Question: Computer.java : public class Computer { // The instance variables to describe the Computer private int barcode = 0; // integer ranges between 10001 and

Computer.java:

public class Computer { // The instance variables to describe the Computer private int barcode = 0; // integer ranges between 10001 and 99999 private int os; // integer ranging from 1 to 3 (inclusive). 1 is for Windows, 2 for MacOS, 3 for Linux private double price = 0; // double ranging from $50.00 to $19,999.00 private String model; // must be at least 2 non-blank characters long private String osName; // must be at least 2 non-blank characters long, and validation of os name /** * Constructs a Computer object * * @param model The Computer model * @param price The price of the computer * @param barcode The number id of the computer * @param os The type of os of the computer * @exception ComputerException If the computer's model is not longer than 2 non-blank characters * @exception ComputerException If the price is not between $50.00 - $19,999.00 * @exception ComputerException If the barcode is not between 10001 - 99999 * @exception ComputerException If computer's os is between 1 - 3 */ public Computer(int barcode, int os, double price, String model) throws ComputerException { setBarcode(barcode); setOs(os); setPrice(price); setModel(model); }

// 4 set methods, one per instance variable. These methods should validate the parameters and must call the ComputerException if the parameters sent are invalid. public void setBarcode(int barcode) throws ComputerException { if(barcode>=10001 && barcode<=99999){ this.barcode = barcode; }else{ ComputerException computerException = new ComputerException(); computerException.setMessage("BarCode is invalid"); throw computerException; } } public void setOs(int os) throws ComputerException { if(os>=1 && os<=3){ this.os = os; setOsName(os); }else{ ComputerException computerException = new ComputerException(); computerException.setMessage("Os is invalid"); throw computerException; } } private void setOsName(int os) { if(os == 1) this.osName = "Windows"; else if(this.os==2) this.osName = "MacOS"; else this.osName = "Linux"; } public void setPrice(double price) throws ComputerException { if(price>=50 && price<=19999){ this.price = price; }else{ ComputerException computerException = new ComputerException(); computerException.setMessage("Price is invalid"); throw computerException; } } public void setModel(String model) throws ComputerException { if(model.length()>2){ this.model = model; }else{ ComputerException computerException = new ComputerException(); computerException.setMessage("Model is invalid"); throw computerException; } } // 4 get methods, Each one of these methods as you should know returns the value of an instance variable. You should know what the respective return data type for each one is. public int getBarcode() { return barcode; } public int getOs() { return os; } public double getPrice() { return price; } public String getModel() { return model; } // 1 toString method, This method returns a String to be printed and takes no parameters, as you should know. @Override public String toString() { return "Computer [barcode=" + barcode + ", os=" + osName + ", price=" + price + ", model=" + model + "]"; } }

ComputerSrote.java:

public class ComputerException extends Exception{ /* instance variable: String message

This class must have the following methods:

1 constructor, no parameters. 1 set method void setMessage (String message) 1 get method String getMessage( ) Overall program structure, naming conventions and style, following the Java coding standards */ String message; public ComputerException(){ } public String getMessage() { return this.message; } public void setMessage(String message) { this.message = message; } }

When your code begins execution the following menu should be displayed/printed

1. add a computer 2. remove a computer 3. print computers of a specific operating system 4. print all the computers 0. end this program

Your driver class should:

  • be named should be ComputerStore.java
  • work with your Computer.java and ComputerException.java
  • You must fix your code if necessary. Please make sure to read the A01 feedback given to you.
  • You must validate user input so that your code does not crash (try/catch).

Implementing the looping menu in the driver class:

  • Your code should continue to loop until the user selects 0. If the program terminates at any other point for any other reason you will lose up to 20 points. (20 points).
  • If the user enters an out of range number, you should print a carefully crafted error message explaining the problem and print the menu again. (20 points).
  • If the user enters anything other than a number, you should catch the exception, print a carefully crafted error message explaining the problem and loop back into the menu again. (20 points).

Implementing the menu options

If the user selects 1, (add a computer) (60 points).

  • Your code should read the computer information from the user using the Scanner class.
  • You should validate everything and in case of invalid input print the appropriate message and go back to print the menu again.
  • If the user information is valid then you should make sure that there is no other computer with the same barcode. In other words, you should make sure there are no duplicate computer barcodes. If the barcode already exists you should print a message saying so and go back to the main menu
    • For the purpose of this assignments a duplicate computer is a computer with the same barcode as another regardless of the other instance variables.

If the user selects 2, (remove a computer) (60 points).

  • You should read the barcode number
  • if the input is not valid, print an error message and loop back into the menu
  • You should search the array looking for a computer matching the barcode entered
  • If a match is found you should remove the computer, print an appropriate message and loop back into the menu
    • when removing a computer from the array you should make sure not to leave a "hole" in the middle. It may result in an exception if it is not carefully handled.
  • it there is no match you should print an appropriate message for the user and loop back into the menu.

If the user selects 3 (print computers of a certain operating system) (40 points).

  • read the os value from the user
  • You should validate it and in case of invalid input print the appropriate message and go back to print the menu again.
  • If the OS is valid then you should should search the array and print all the computers of that operating system and print them to the screen
  • if no computers are found to have that OS, a message should be printed saying so.

If the user selects 4 (print all the computers in the array) (20 points).

  • you may use the enhanced for loop

If the user selects 0 (5 points).

  • you will print a "thank you" message and end program execution

Other considerations

  • The array should not contain duplicate barcode computers at any time.
  • Feel free to use any of the Arrays class methods we learned this week in class.
  • You should use the proper exceptions, like InputMismatchException or ComputerException, etc as appropriate. You should not use the general "Exception"
  • If you use several static methods within your driver, for example one method per menu option
  • Great documentation / comments
  • Overall program usability (user friendliness)
  • Follow Java Coding Standards

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!