Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

// Ansignent #. 4 /I Namet Your name /I StudentID: /I Description: Assignment 4

ID: 3884547 • Letter: #

Question



// Ansignent #. 4 /I Namet Your name /I StudentID: /I Description: Assignment 4 class displays a menu of choices to a user and performs the chosen task. It will keep asking a user to enter the next choice until the choice of ·Q' (Quit) is entered. import java.io.* I/to use InputStreamReader and BufferedReader import java.util. public class Assignment4 /I local variables, can be accessed anywhere from the main method char input '2' String bookTitle, bookAuthor, bookISBN int bookVersion double bookPrice String line new String) a Book object Book bookinev Book(O: //Create a Scanner object to read user input Scanner scan- new Scanner (System.in) do // will ask for user input system.out.printin( "What action would you 1ike to perform2") line scan.nextLinet) if (line.length1) input 1ine.charat (0)1 input Character.toUpperCase(input): // matches one of the case statement case "Add Book bookTitle scan.nextLinet) book1.setAuthor(bookAuthor)

Explanation / Answer

class Publication {
    private String ISBN;
    private int version;
    private double price;
    public Publication(){
        ISBN = "?";
        version = 1;
        price = 0.0;
    }
    public String getISBN(){
       return ISBN;
    }
    public int getVersion(){
       return version;
    }
    public double getPrice(){
       return price;
    }
    public void setISBN(String newISBN){
       ISBN = newISBN;
    }
    public void setVersion(int newVersion){
       version = newVersion;
    }
    public void setPrice(double newPrice){
       price = newPrice;
    }


}

class Book {

    private String title;
    private String author;
    private Publication pub;

    public Book(){
       title = "?";
       author = "?";
       pub = new Publication();
    }
    public String getTitle(){
        return title;
    }
    public String getAuthor(){
        return author;
    }
    public String getPublication(){
        return pub;
    }
    public void setTitle(String newTitle){
        title = newTitle;
    }
    public void setAuthor(String newAuthor){
        author = newAuthor;
    }
    public void setPublication(int newVersion, String newISBN, double newPrice){
        pub = new Publication();
        pub.setVersion(newVersion);
        pub.setISBN(newISBN);
        pub.setPrice(newPrice);
    }

}