So I have the following code contained within a class labeled book.

    public void setPublication(int bookVersion, String bookISBN, double bookPrice) {
        bookVersion = pub.setVersion(bookVersion);
        bookISBN = pub.setISBN(bookISBN);
        bookPrice = pub.setPrice(bookPrice);

It refers to the following class, called publication.

    //Getter method to get the book ISBN
    public String getISBN(String bookISBN){
        return ISBN;

    //Getter method to get the book Version
    public int getVersion(int bookVersion){
        return version;

    //Getter method to get the book Price
    public double getPrice(double bookPrice){
        return price;

    //Setter method to set the book ISBN
    public void setISBN(String bookISBN){
        ISBN = bookISBN;

    //Setter method to set the book Version
    public void setVersion(int bookVersion){
        version = bookVersion;

    //Setter method to set the book Price
    public void setPrice(double bookPrice){
        price = bookPrice;

In my driver class I have switches for user input

 switch (input)
             case 'A':   //Add Book
               System.out.print("Enter book title:\n");
               bookTitle = scan.nextLine();

               System.out.print("Enter book author:\n");
               bookAuthor = scan.nextLine();

               System.out.print("Enter book version:\n");
               bookVersion = Integer.parseInt(scan.nextLine());
               System.out.print("Enter book ISBN:\n");
               bookISBN = scan.nextLine();
               System.out.print("Enter book price:\n");
               bookPrice = Double.parseDouble(scan.nextLine());
               book1.setPublication(bookVersion, bookISBN, bookPrice);
             case 'D':   //Display course
             case 'Q':   //Quit
             case '?':   //Display Menu
               System.out.print("Unknown action\n");

I'm having trouble aggrating the publication class to the book class. This is a homework project, so It would be super helpful if someone could explain it to me rather than just giving me an answer.

I think what needs to happen is the book class has to set the information in the publication class. which is what I was trying to do with
bookVersion = pub.setVersion(bookVersion);
However, it keeps asking me to change the setter method in the publication class so it returns a value.

Edited by Meghan_1

3 Weeks
Discussion Span
Last Post by JamesCherrill

It appears to me that you need 2 sets of calls 1 to the Publication setters and one to the Book setters. The error is because you can't assign the result of a void return to a variable.


bookVersion = pub.setVersion(bookVersion);

your set methods are void, so they don't return anything, so there's nothing that can be assigned to bookVersion.

It's traditional for set methods to be void, but latest practice is for them to return this so you can chain them together (so-called "fluent interface").

Just a thought.... is Book a subclass of Publication? If not, why not?

Edited by JamesCherrill

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.