-
Program goes into infinite compilation. University project - Library Program.
Code java:
/**
* Write a description of class Book here.
*
* @author (Michael Clark)
* @version (30th October 2012, version 0.1)
*/
public class Book
{
// instance variables - replace the example below with your own
private int id;
private String author;
private String title;
private boolean isFiction;
/**
* Constructor for objects of class Book
*/
public Book(String title, String author, int id, boolean isFiction)
{
// initialise instance variables
this.id = 0;
this.author = author;
this.title = title;
this.isFiction = false;
}
/**
* Get the name of the book Author.
*
*/
public String getAutor()
{
// put your code here
return this.author;
}
/**
* Get the book ID.
*/
public int getId()
{
return this.id;
}
/**
* Get the book title.
*
*/
public String getTitle()
{
return this.title;
}
public void setAuthor(String authorName)
{
author = authorName;
}
public void setId(int bookId)
{
id = bookId;
}
public void setTitle(String bookTitle)
{
title = bookTitle;
}
}
This is the book Class, every time i click on compile, it goes into an infinite compilation.
Code java:
import java.util.ArrayList;
/**
* This Class would hold Membership details for the Library.
*
* @author (Michael Clark)
* @version (30th October 2012, version 0.1)
*/
public class Member
{
// instance variables - These are member object attributes/fields
private String firstName;
private String lastName;
private String phoneNumber;
private int refNumber;
/**
* Constructor for objects of class Member
*/
public Member(String firstName, String lastName, String phoneNumber, int refNumber)
{
this.firstName = firstName;
this.lastName = lastName;
this.phoneNumber = phoneNumber;
this.refNumber = refNumber;
}
/**
* This is return method for the object firstname.
*
*/
public String getfirstName()
{
return this.firstName;
}
/**
* Return method for the last name.
*/
public String getlastName()
{
return this.lastName;
}
/**
* Return method for the phone number.
*/
public String getPhoneNumber()
{
return this.phoneNumber;
}
/**
* Return method for membership reference.
*/
public int getrefNumber()
{
return this.refNumber;
}
}
-
Re: Program goes into infinite compilation. University project - Library Program.
It compiles fine in my machine
Can you please give the details ....like which tool/IDE are using to compile the class ?
-
Re: Program goes into infinite compilation. University project - Library Program.
Are you sure it is the compile step that is the problem?
Usually infinite loops happen when the code is executed, AFTER the compilation.
I don't see a main() method in the posted code. How do you execute the program?
-
Re: Program goes into infinite compilation. University project - Library Program.
Quote:
Originally Posted by
Norm
Are you sure it is the compile step that is the problem?
Usually infinite loops happen when the code is executed, AFTER the compilation.
I don't see a main() method in the posted code. How do you execute the program?
Its all done in the blue J environment..cheers for ur input
--- Update ---
Quote:
Originally Posted by
clarky2006
Its all done in the blue J environment..cheers for ur input
its not infinite loop but infinite compilation..it just says compiling and never stops unless i close the window,which makes it impossible to test the programe. cheers
-
Re: Program goes into infinite compilation. University project - Library Program.
Sorry, I'm not familiar with blue j.
Do you know the difference between compiling a program and executing a program?
Does blue j allow you to compile a java class without trying to execute it?
Is there a main() method in any of your classes?
-
Re: Program goes into infinite compilation. University project - Library Program.
Complies good on JGrasp... Try using a different complier or make sure you have the latest version of your complier and java.
-
Re: Program goes into infinite compilation. University project - Library Program.
Quote:
Originally Posted by
ashboi
Complies good on JGrasp... Try using a different complier or make sure you have the latest version of your complier and java.
Blue J is the java environment our teacher is using to teach us and he wants the project done in blueJ.. cheers
-
Re: Program goes into infinite compilation. University project - Library Program.
Do you know the difference between compiling a program and executing a program?
Does blue j allow you to compile a java class without trying to execute it?
Is there a main() method in any of your classes?
-
Re: Program goes into infinite compilation. University project - Library Program.
Code java:
import java.util.ArrayList;
/**
* This is the Library Class which would be used to maintain collections of members
* and books.
* @author (Michael Clark)
* @version (30th October 2012, version 0.1)
*/
public class Library
{
// instance variables
private ArrayList<Membership> member;
private ArrayList<Book> books;
/**
* Constructor for objects of class Library
*/
public Library()
{
// initialised instance variables
members = new ArrayList<Membership>();
books = new ArrayList<book>();
}
Ye I do know the difference in compilling and running the program..compile is to turn the code into=01010101,binary numbers so computer can read it..there is a compile button on BlueJ. I ve rewritten the library classstill cant compile...it says "cannot find symbol-class Membership".i added the new code..cheers.
--- Update ---
So what is the main method and what does it do? i ve not used it before...thanx
-
Re: Program goes into infinite compilation. University project - Library Program.
Quote:
cannot find symbol-class Membership
Where is the definition for the Membership class? That message says that the compiler can not find it.
The main() method is the one called by the java program to start the execution of a class. When you execute this command:
java TheClassName
the java program calls the main() method of the TheClassName class.
-
Re: Program goes into infinite compilation. University project - Library Program.
Please attach a recording so that we can get to the root cause.
-
Re: Program goes into infinite compilation. University project - Library Program.
Quote:
Originally Posted by
Norm
I don't see a main() method in the posted code. How do you execute the program?
In BlueJ you have no main() method.
In the environment you have different classes and at when you export it to jar, you can choose which class you want to be the main class.
The chosen main class will be started when you execute the jar and so the constructor method of the main class becomes the main() method.
-
Re: Program goes into infinite compilation. University project - Library Program.
Quote:
Originally Posted by
minju
In BlueJ you have no main() method.
In the environment you have different classes and at when you export it to jar, you can choose which class you want to be the main class.
The chosen main class will be started when you execute the jar and so the constructor method of the main class becomes the main() method.
@minju
Are you saying that the jar files created by bluej are different from other jar files?
That there is some magic that bluej does so that you do not need to code a main() method in the class where you want the program to start executing?
-
Re: Program goes into infinite compilation. University project - Library Program.
Quote:
Originally Posted by
Norm
@minju
Are you saying that the jar files created by bluej are different from other jar files?
That there is some magic that bluej does so that you do not need to code a main() method in the class where you want the program to start executing?
@Norm
yes the jar differs from normal ones because it has package.bluej included
like if you have the classes test1, test2, test3 the jar will have
META-INF
test1.class
test2.class
test3.class
README.TXT
package.bluej
-
Re: Program goes into infinite compilation. University project - Library Program.
Quote:
Originally Posted by
Norm
@minju
Are you saying that the jar files created by bluej are different from other jar files?
That there is some magic that bluej does so that you do not need to code a main() method in the class where you want the program to start executing?
Sorry, my mistake.
You do need a main() method I remember.
But maybe clarky2006 is not aware of that because in BlueJ you have the availability to create an object out of a class without a main() method.
-
Re: Program goes into infinite compilation. University project - Library Program.
Quote:
In BlueJ you have no main() method.
In the environment you have different classes and at when you export it to jar, you can choose which class you want to be the main class.
The chosen main class will be started when you execute the jar and so the constructor method of the main class becomes the main() method.
Thats right there is no main in blue j..
-
Re: Program goes into infinite compilation. University project - Library Program.
Quote:
there is no main in blue j
Does that mean you do not use the java command to execute the program? The java command requires a main() method.
Or does the bluej IDE create a class with a main() method that calls the constructor of the class that you want executed?
-
1 Attachment(s)
Re: Program goes into infinite compilation. University project - Library Program.
Attachment 1525
here is a pic of blue j
-
Re: Program goes into infinite compilation. University project - Library Program.
Code java:
import java.util.ArrayList;
/**
* A simple model of an auction.
* The auction maintains a list of lots of arbitrary length.
*
* @author David J. Barnes and Michael Kölling.
* @version 2011.07.31
*/
public class Auction
{
// The list of Lots in this auction.
private ArrayList<Lot> lots;
// The number that will be given to the next lot entered
// into this auction.
private int nextLotNumber;
/**
* Create a new auction.
*/
public Auction()
{
lots = new ArrayList<Lot>();
nextLotNumber = 1;
}
/**
* Enter a new lot into the auction.
* @param description A description of the lot.
*/
public void enterLot(String description)
{
lots.add(new Lot(nextLotNumber, description));
nextLotNumber++;
}
/**
* Show the full list of lots in this auction.
*/
public void showLots()
{
for(Lot lot : lots) {
System.out.println(lot.toString());
}
}
/**
* Make a bid for a lot.
* A message is printed indicating whether the bid is
* successful or not.
*
* @param lotNumber The lot being bid for.
* @param bidder The person bidding for the lot.
* @param value The value of the bid.
*/
public void makeABid(int lotNumber, Person bidder, long value)
{
Lot selectedLot = getLot(lotNumber);
if(selectedLot != null) {
Bid bid = new Bid(bidder, value);
boolean successful = selectedLot.bidFor(bid);
if(successful) {
System.out.println("The bid for lot number " +
lotNumber + " was successful.");
}
else {
// Report which bid is higher.
Bid highestBid = selectedLot.getHighestBid();
System.out.println("Lot number: " + lotNumber +
" already has a bid of: " +
highestBid.getValue());
}
}
}
/**
* Return the lot with the given number. Return null
* if a lot with this number does not exist.
* @param lotNumber The number of the lot to return.
*/
public Lot getLot(int lotNumber)
{
if((lotNumber >= 1) && (lotNumber < nextLotNumber)) {
// The number seems to be reasonable.
Lot selectedLot = lots.get(lotNumber - 1);
// Include a confidence check to be sure we have the
// right lot.
if(selectedLot.getNumber() != lotNumber) {
System.out.println("Internal error: Lot number " +
selectedLot.getNumber() +
" was returned instead of " +
lotNumber);
// Don't return an invalid lot.
selectedLot = null;
}
return selectedLot;
}
else {
System.out.println("Lot number: " + lotNumber +
" does not exist.");
return null;
}
}
}
Here is a working Auction class in Blue J with no main method..
--- Update ---
I mean in Blue j
-
Re: Program goes into infinite compilation. University project - Library Program.
Are you still having problems?
Is your problem with the bluej program
or is it with your java program? For example you are getting compiler errors. If you are getting errors you need help with, copy and paste here the full text of the compiler's error messages.
I can't help you with bluej.
-
Re: Program goes into infinite compilation. University project - Library Program.
Quote:
Sorry, my mistake.
You do need a main() method I remember.
But maybe clarky2006 is not aware of that because in BlueJ you have the availability to create an object out of a class without a main() method.
I have been doing introduction to java since september and the tutor has never said any thing about main method. in Blue J you can create an objects on the work bench.
-
Re: Program goes into infinite compilation. University project - Library Program.
Sounds like the IDE (bluej) is doing some of the work for you and hiding what it is doing. In the real world, you need a main() method.
-
Re: Program goes into infinite compilation. University project - Library Program.
Quote:
Originally Posted by
clarky2006
I have been doing introduction to java since september and the tutor has never said any thing about main method. in Blue J you can create an objects on the work bench.
Yeah as I mentioned you can create objects out of classes in the environment, but if you export the whole thing you need a main() method.
-
Re: Program goes into infinite compilation. University project - Library Program.
Quote:
Originally Posted by
Norm
Sounds like the IDE (bluej) is doing some of the work for you and hiding what it is doing. In the real world, you need a main() method.
Sorry mate, I have been at Uni all day, just got home now..I had a chat with our lecturer today about the Main () method and he said you are right, we need the main method in the real world. He says we would be learning the Main () method and other stuff next semester or year 2..so I was really disappointed because with the money Im paying to be educated, Im not getting my money,s worth. Next semester I would be doing Networking (Cisco), so wont be doing programming..looks like i have to teach my self the rest of it."gutted". But im glad I stumbled on this site, cause I ve learnt more here in 2 days than i ve done at Uni in 7 wks..Cheers guys..
-
Re: Program goes into infinite compilation. University project - Library Program.
My impression of several IDEs is that they are for giving students the flavor of programming without requiring them to know all the dirty details.
If you want to be a programmer, you need to know the dirty details. Then the question is, When do you teach them? I'll leave that to the academics to figure out the best way to teach a subject.