Question
I have an error showing at line 200 and i have exhausted my knowledge on how to find/fix. Can you please help?? Please see bold
I have an error showing at line 200 and i have exhausted my knowledge on how to find/fix. Can you please help?? Please see bold below for " Inventory inventory = new Inventory();"
package CMIS242ASG1AfetseM;
//import utility packages import java.security.InvalidParameterException; import java.util.ArrayList; import java.util.Iterator; import java.util.Scanner;
public class CMIS242ASG1AfetseM { //create book class public class Book { private String id; private String title; private double price; private boolean isDigit(String str) { try { Long.parseLong(str); } catch(NumberFormatException e) { return false; } return true; } //set methods public void setId(String id) { if(id.length() != 5) { throw new InvalidParameterException("Please note the length of Book ID should be 5 digits."); } else if(!isDigit(id)) { throw new InvalidParameterException("Please note the Book ID should consist of only digits."); } this.id = id; } public void setTitle(String title) { this.title = title; } public void setPrice(double price) { this.price = price; } //access methods public String getId() { return id; } public String getTitle() { return title; } public double getPrice() { return price; } //set override for string @Override public String toString() { return "Book [ID=" + id + ", Title=" + title + ", Price=" + price + "]"; }
//create inventory class public class Inventory { //create arraylist ArrayList
System.out.print("Please Enter Book Price: "); double price = scan.nextDouble(); book.setPrice(price); bookList.add(book); scan.close(); } //remove a book from inventory public void remove() {
Scanner scan = new Scanner(System.in); boolean done = false; while(!done) { System.out.print("Please Enter Book ID(5-digits): "); String id = scan.next(); Iterator
Scanner scan = new Scanner(System.in); boolean done = false; Book book = null; while(!done) { System.out.print("Please Enter Book ID(5-digits): "); String id = scan.next(); Iterator
public static void main(String[] args) { Scanner scan = new Scanner(System.in); //create instance for inventory Inventory inventory = new Inventory(); boolean quit = false; while(!quit) { inventory.displayMenu(); //prompt user to select desired option System.out.print("Please select option: "); int option = scan.nextInt(); switch(option) { case 1: inventory.add(); break;
case 2: inventory.remove(); break;
case 3: inventory.find(); break;
case 4: inventory.display(); break;
case 9: quit = true; break; default: System.out.println("Apologies for that is an invalid entry. Please select a valid option from menu."); } System.out.println(); scan.close(); } } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started