PDA

View Full Version : Java Programming (encapsulation)



lightshow
09-24-2006, 10:39 PM
I keep getting an error that says Constructor Book() not found in class project1.book

and

illegal start of type (at the very end of my code)


package project1;
public class Book
{
private int ISBN;
private String bookTitle;
private String author;
private int publishYear;
private double price;
private double discount;

public void main(String[] args)
{
Book book1 = new Book();
EditorialReview editorialreview1 = new EditorialReview();

book1.author="Jimmy Cook";
book1.ISBN=24235;
book1.bookTitle="How to Save the World";
book1.publishYear=1981;
book1.price=17.99;

editorialreview1.bookISBN=24235;
editorialreview1.bookRating=5;
editorialreview1.reviewContent="Great Book!";
editorialreview1.reviewerName="Kim Hammel";

discount = book1.CalculateDiscountPercentage(editorialreview1.getbookRating());

book1.PrintBookInformation(editorialreview1.GetReviewContent(), editorialreview1.GetReviewerName(), editorialreview1.GetRating(), book1.bookTitle, book1.author, book1.publishYear, book1.price, book1.discount);



}
//methods of the Book Class
public double CalculateDiscountPercentage(int rating)
{
if (rating >= 5)
return 0.00;
else if(rating >=4)
return 5.00;
else if(rating >=3)
return 10.00;
else if(rating >=2)
return 15.00;
else if(rating >=1)
return 20.00;
else
return 0.00;
}
public void PrintBookInformation(String content, String reviewerName, int rating, String bookTitle, String author, int year, double price, double discount)
{
System.out.println("Book Title: " + bookTitle);
System.out.println("Author: " + author);
System.out.println("Year: " + year);
System.out.println("Original Price: $" + price);
System.out.println("Discounted Price: $"); //need to calculate
System.out.println("Editorial Review - from " + reviewerName);
System.out.println("Rating! = " + rating);
System.out.println("Editorial Comments: " + content);
}

public void setAuthor(String author)
{
this.author = author;
}
public void setbookTitle(String bookTitle){
bookTitle = this.bookTitle;
}
public void setISBN(int ISBN){
ISBN = this.ISBN;
}
public void setPrice(double price){
price = this.price;
}
public void setpublishYear(int publishYear){
publishYear = this.publishYear;
}
class EditorialReview
{
private int bookISBN;
private String reviewerName;
private String reviewContent;
private int bookRating;

public String GetReviewContent(){
return reviewContent;
}
public String GetReviewerName(){
return reviewerName;
}
public int GetRating(){
return bookRating;
}

public int getbookRating()
{
return bookRating;
}
}

lightshow
09-29-2006, 04:36 PM
Fixed it, stupid complier didn't work right on my computer.

suedenim
10-06-2006, 09:46 AM
Hi Lightshow - just out of interest, what version of javac are you running and on what platform?