// Assignment #: 4 I Name: Your name // StudentID: // Description: Assignment 4
ID: 3885313 • Letter: #
Question
// Assignment #: 4 I Name: Your name // StudentID: // 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 'o' (Quit) is entered. import java.io.* //to use InputStreamReader and BufferedReader import java.util. public class Assignment4 public static void main (Stringt1 args) /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) it (1ine.length)1) input 1ine.charAt(0) input Character.toUpperCase(input)i // matches one of the case statement avitch (input) case "a'/dd Book bookTitle scan. nextLinet)i bookl System.out.print( "Enter book authorin") book1.setAuthor(bookauthor) a thor-scan.nextLine )iExplanation / 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);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.