Hi Guys,
I was just wondering if you could help me with any suggestions in implementing input from a user and outputting it to the console, I have getters and setters that the user needs to be able to use as a template for the type of data they need to enter, here's some of the code I have written up:
This is some of the file that stores the variables,getters and setters..
// Instance Variables // ================== private int upc; private String title; private int issueNumber; private String publisher; private String gradeCode; private double currentValue; public String determineCondition; public double calcSellingPrice; // Main Method public static void main(String[] args) { // Create instance of Student ComicBook comicbook = new ComicBook (687788599, "Aquaman", 12, "Marvel", "MT", 20.00); comicbook.setUpc(539684363); } // Create the Constructors public ComicBook() { setUpc(596060547); setTitle("Wolverine"); setIssueNumber(20); setPublisher("Marvel Comics"); setGradeCode("FR"); setCurrentValue(50.00); } public ComicBook(int upc, String title, int issueNumber, String publisher, String gradeCode, double currentValue){ setUpc(upc); setTitle(title); setIssueNumber(issueNumber); setPublisher("Marvel Comics"); setGradeCode("FR"); setCurrentValue(50.00); } // Getters and Setters // Upc getters and setters public int getUpc() { return upc; } public void setUpc(int upc) { this.upc = upc; } // Title getters and setters public String getTitle() { return title; } public void setTitle(String title) { this.title = title; }
This file needs to grab user input then display, the users need to be able to input into the getters and setters like they are creating a new item themself:
public static void main(String[] args) { Scanner scanner = new Scanner(System.in); //Initialize the scanner BufferedReader keyboard = null; // input stream int numBooks = 0; //How many books are to be entered? int whatNumBook = 0; //If this exceeds the value of numBooks, exit(); ComicBook c = new ComicBook(); //create new comic book //Welcome message System.out.println("Welcome to the Comic Book Manager!"); //Start running with request for no. of books //Store value in numBooks for later use System.out.print("How many books will you be entering today? "); try { numBooks = scanner.nextInt(); //Now wait for user to enter the number of books they are entering System.out.print("Please enter what number book you would like to start with? "); whatNumBook = scanner.nextInt(); //Once they are finished this will end the program if (whatNumBook > numBooks){ exit(); } System.out.println("Upc: " + c.getUpc()); System.out.println("Title: " + c.getTitle()); System.out.println("Issue Number: " + c.getIssueNumber()); System.out.println("Publisher: " + c.getPublisher()); System.out.println("Grade Code: " + c.getGradeCode()); System.out.println("Current Value: " + c.getCurrentValue()); } finally { if (whatNumBook != 0) { System.out.println("Closing Comic Book Manager"); ComicBookManager.exit(); }else { System.out.println("Comic Book Manager not open"); }
Hope that makes sense, any help would be appreciated