Your Ad Here Your Ad Here
Results 1 to 3 of 3

Thread: Java Programming (encapsulation)

  1. #1
    lightshow's Avatar Asleep at the wheel
    Join Date
    Mar 2003
    Age
    32
    Posts
    924
    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)

    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;    
    }
    }

  2. Internet, Programming and Graphics   -   #2
    lightshow's Avatar Asleep at the wheel
    Join Date
    Mar 2003
    Age
    32
    Posts
    924
    Fixed it, stupid complier didn't work right on my computer.
    I miss the days of random nut '03
    Click for more activation options, then activate by telephone. Run the keygen.
    if I call them, aren't they going to get me? (you know, down there)

  3. Internet, Programming and Graphics   -   #3
    suedenim's Avatar Life in a vacuum sux
    Join Date
    May 2006
    Location
    Hong Kong
    Posts
    9
    Hi Lightshow - just out of interest, what version of javac are you running and on what platform?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •