Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(2) Add a computer If the user enters 4 and presses enter then the following sub-menu should be displayed: If the user enters 1 then

(2) Add a computer If the user enters 4 and presses enter then the following sub-menu should be displayed:

image text in transcribed

If the user enters 1 then s/he is prompted to enter the specification data for a laptop computer, e.g.:

image text in transcribed

The prompts show the only valid options for each item, e.g. CPUs can only be i5 or i7, etc. Any other values should be rejected and an error message displayed. Entering 2 at this sub-menu would allow the user to enter the data for a desktop computer, e.g.:

image text in transcribed

5 of 19 Once the computers have been added to the system the user can press 3 and return to the main application window (or enter more computers using 1 and 2 in the sub-menu, if they so wish), e.g.:

image text in transcribed

Entering 3 will list the data on the computers as entered, e.g.:

image text in transcribed

(3) Edit a computer To edit the data for an existing computer, enter 6 at the main menu, and then the number of the computer to edit as shown in the computer listing (by entering 1), e.g. to edit the data for computer number 1 (the laptop in the sample data above):

image text in transcribed

In the example above the user is upgrading the RAM in the laptop to 16GB (but s/he still needs to enter the other data values as well, even if their values are the same as before). Redisplaying the computer data after the laptop has been edited would show the following:

image text in transcribed

Delete a computer To delete a computer, enter 5 at the main menu, and then the number of the computer to delete, e.g. to delete the desktop computer from our sample data, and show the revised list of computers:

image text in transcribed

(4) Load computer data from drive To load previously-saved computer data from the drive select 1 from the menu. This will load the data for those computers into memory, replacing any computer data that was already in memory with the data loaded from the drive.

image text in transcribed

The screenshot above shows the user running the application. Then the user selected 1 from the menu, which loaded the data on any computers stored on the drive back into memory. Entering 3 after reloading the computer data displayed the newly-loaded computer data, in this example for a single laptop computer.

(5) Save computer data to a drive To save the data for any computers that is currently held in memory the user selects 2 from the menu. The application saves copies of the data for each computer (held in memory) in separate serialized data files on the drive, and then redisplays the main menu:

image text in transcribed

(6) Exit the application Selecting 0 terminates the application and drops the user back to the command prompt, e.g.:

image text in transcribed

Exiting from the application should not auto-save any unsaved computer data in memory. Error Messages The application must output the following error messages1 as required:

If the application is run without the supervision of a SecurityManager:

image text in transcribed

1 Note that error messages displayed on-screen must all be sanitized of sensitive information, e.g. file names and paths, etc.

If the application does not have permissions to read, write and delete files in the /root/assign1Data directory, where computer object data must be stored:

image text in transcribed

If the user enters invalid data for a new computer, e.g. an i9 processor:

image text in transcribed

Or, an invalid laptop screen size (17):

image text in transcribed

Note: Display equivalent error messages for other invalid input values also.

If an invalid computer number is entered during an operation, e.g. delete:

image text in transcribed

Application Requirements General Requirements This application must be written using the following Java Secure Coding Guidelines

======This is what I have so far for codes(However, my current code doesn't work)=====

**DesktopComputer.java**

package domain;

//Class Desktop Computer extends Computer and hence //has all the attributes of Computer class and some // of its own - here, GPU. class DesktopComputer extends ManageComputer { private String GPU; public DesktopComputer(String CPU,int ram, int disk, String GPU) { //call base class's constructor, // i.e, constructor of Computer class super("LaptopComputer",CPU,ram,disk); this.GPU = GPU; }

public String getGPU() { return GPU; }

public void setGPU(String CPU) { this.GPU = CPU; } @Override public void printDetails(){ System.out.println("Type: DesktopComputer"); //Calling base class's printDetails method. super.printDetails(); System.out.println("GPU: " + getGPU()); } }

**ManageComputer.java**

package domain;

import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList;

public class ManageComputer { //using a arraylist that will be able //to store our items - laptops and desktops static ArrayList allItems = new ArrayList(); public static void main(String[] args) throws IOException { int choice = -1; BufferedReader br = new BufferedReader( new InputStreamReader(System.in)); //Using a do-while loop to keep //displaying menu until user exits. do{ System.out.println("===MENU==="); System.out.println("1. Load"+" "+ "2. Save"+" "+ "3. List"+" "+ "4. Add"+" "+ "5. Delete"+" "+ "6. Edit"+" "+ "0. Exit"); System.out.println("Enter selection:"); choice = Integer.parseInt(br.readLine()); //check for invalid choice(our choice //lies between 0 and 6. Other inputs are invalid if(choice6){ System.out.println("Invalid Input! Try again."); continue; }

//Using switch to choose appropriate //functions according to choices. switch(choice){ case 1: optionLoad(); break; case 2: optionSave(); break; case 3: optionList(); break; case 4: optionAdd(); break; case 5: //optionDelete(); break; case 6: //optionEdit(); break; case 0: optionLoad(); break; } }while(choice!=0); //Continue showing menu till user exits. } public static void optionLoad(){ } public static void optionSave(){ } //Listing all items in arraylist public static void optionList(){ int sr_no = 1; //If list is empty, display so and exit. if(allItems.size()==0){ System.out.println("Currently, we don't have any items."); return; } //Printing details of each item in list. for(Computer c: allItems){ System.out.println("--------------"); System.out.println("Computer #"+sr_no); sr_no++; c.printDetails(); } } //Adding items to arraylist. public static void optionAdd() throws IOException{ String CPU; int ram,disk; int opt=0; BufferedReader br = new BufferedReader( new InputStreamReader(System.in)); System.out.println("What do you want to add?"); System.out.println("\t1.Laptop \t2.Desktop"); opt = Integer.parseInt(br.readLine()); System.out.println("Enter CPU description:"); CPU = br.readLine(); System.out.println("Enter RAM Size:"); ram = Integer.parseInt(br.readLine()); System.out.println("Enter Disk Space:"); disk = Integer.parseInt(br.readLine()); //Check first what the user wants to add //and create and add items accordingly. if(opt==1){ //user wants to add laptop System.out.println("Enter Screen sixe:"); float scr_size = Float.parseFloat(br.readLine()); allItems.add(new LaptopComputer(CPU,ram,disk,scr_size)); } else{ //user wants to add desktop System.out.println("Enter GPU description:"); String GPU = br.readLine(); allItems.add(new DesktopComputer(CPU,ram,disk,GPU)); } } }

**LaptopComputer.java**

package domain;

//Class Laptop Computer extends Computer and hence //has all the attributes of Computer class and some // of its own - here, screen_size. class LaptopComputer extends ManageComputer { private float screen_size;

public LaptopComputer(String CPU,int ram, int disk, float screen_size) { //call base class's constructor, // i.e, constructor of Computer class super("DesktopComputer",CPU,ram,disk); this.screen_size = screen_size; }

public float getScreen_size() { return screen_size; }

public void setScreen_size(int screen_size) { this.screen_size = screen_size; } //Calling base class's printDetails method. @Override public void printDetails(){ System.out.println("Type: LaptopComputer"); super.printDetails(); System.out.println("Screen Size: " + getScreen_size() + " inches"); } }

**BaseComputer.java**

package domain;

class BaseComputer{ private String type; private String CPU; private int ram; private int disk;

//Defining constructor, getter and setter functions. public BaseComputer(String type, String CPU, int ram, int disk) { this.type = type; this.CPU = CPU; this.ram = ram; this.disk = disk; } public String getCPU() { return CPU; }

public void setCPU(String CPU) { this.CPU = CPU; }

public int getRam() { return ram; }

public void setRam(int ram) { this.ram = ram; }

public int getDisk() { return disk; }

public void setDisk(int disk) { this.disk = disk; } //Printing details of attributes. public void printDetails(){ System.out.println("CPU: " + getCPU()); System.out.println("RAM: " + getRam() + " GB"); System.out.println("DISK: " + getDisk() + " GB"); }

}

====MENU==== 1. Load 2. Save 3. List 4. Add 5. Delete 6. Edit 0. Exit Enter selection: ADD NEW COMPUTER 1. Add new Laptop Computer 2. Add new Desktop Computer 3. Back to main menu ADD NEW COMPUTER 1. Add new Laptop Computer 2. Add new Desktop Computer 3. Back to main menu Enter CPU type (i5/17) : 15 Enter RAM size (8/16): Enter disk size (250/500) : 250 Enter screen size (13/15) : 13 ADD NEW COMPUTER 1. Add new Laptop Computer 2. Add new Desktop Computer 3. Back to main menu ADD NEW COMPUTER 1. Add new Laptop Computer 2. Add new Desktop Computer 3. Back to main menu Enter CPU type (i5/i7) : i7 Enter RAM size (8/16) : Enter disk size (250/500) : 500 Enter GPU (intel/amdvidia) : nvidia ADD NEW COMPUTER 1. Add new Laptop Computer 2. Add new Desktop Computer 3. Back to main menu ADD NEW COMPUTER 1. Add new Laptop Computer 2. Add new Desktop Computer 3. Back to main menu ====MENU==== 1. Load 2. Save 3. List 4. Add 5. Delete 6. Edit 0. Exit Enter selection: ====MENU==== 1. Load 2. Save 3. List 4. Add 5. Delete 6. Edit . Exit Enter selection: COMPUTER #1 Type: Laptop Computer CPU: 15 RAM: 8 GB DISK: 250 GB Screen Size: 13 inches COMPUTER #2 Type: Desktop Computer CPU: 17 RAM: 16 GB DISK: 500 GB GPU: nvidia ====MENU==== 1. Load 2. Save 3. List 4. Add 5. Delete 6. Edit c. Exit Enter selection: 2. Exit Enter selection: COMPUTER #1 Type: LaptopComputer CPU: 15 RAM: 8 GB DISK: 250 GB Screen Size: 13 inches COMPUTER #2 Type: Desktop Computer CPU: 17 RAM: 16 GB DISK: 500 GB GPU: nvidia EESMENU==== 1. Load 2. Save 3. List 4. Add 5. Delete 6. Edit D. Exit Enter selection: EDIT COMPUTER Enter number of computer to edit: 13 Enter CPU type (15/17) : Enter RAM size (8/16): 16 Enter disk size (250/500) : 256 Enter screen size (13/15) : MENUS 1. Load 2. Save 3. List 4. Add 5. Delete 6. Edit 9. Exit Enter selection: ====MENU==== 1. Load 2. Save 3. List 4. Add 5. Delete 6. Edit . Exit Enter selection: COMPUTER #1 Type: Laptop Computer CPU: i5 RAM: 16 GB DISK: 250 GB Screen Size: 13 inches COMPUTER #2 Type: Desktop Computer CPU: 17 RAM: 16 GB DISK: 500 GB GPU: nvidia ====MENU==== 1. Load 2. Save 3. List 4. Add 5. Delete 6. Edit 0. Exit Enter selection: ====MENU==== 1. Load 2. Save 3. List 4. Add 5. Delete 6. Edit C. Exit Enter selection: DELETE COMPUTER Enter number of computer to delete: ====MENU==== 1. Load 2. Save 3. List 4. Add 5. Delete 6. Edit c. Exit Enter selection: COMPUTER #1 Type: Laptop Computer CPU: 15 RAM: 16 GB DISK: 250 GB Screen Size: 13 inches ====MENU==== 1. Load 2. Save 3. List 4. Add 5. Delete 6. Edit 0. Exit Enter selection: root@kali:-/ManageComputers/working/temp# java -cp.:Domain.jar -Dja ====MENU==== 1. Load 2. Save 3. List 4. Add 5. Delete 6. Edit 0. Exit Enter selection: ====MENU==== 1. Load 2. Save 3. List 4. Add 5. Delete 6. Edit 0. Exit Enter selection: COMPUTER #1 Type: Laptop Computer CPU: 15 RAM: 16 GB DISK: 250 GB Screen Size: 13 inches ====MENU==== 1. Load 2. Save 3. List 4. Add 5. Delete 6. Edit 0. Exit Enter selection: ====MENU==== 1. Load 2. Save 3. List 4. Add 5. Delete 6. Edit 0. Exit Enter selection: 2 ====MENU==== 1. Load 2. Save 3. List 4. Add 5. Delete 6. Edit 6. Exit Enter selection: ====MENU==== 1. Load 2. Save 3. List 4. Add 5. Delete 6. Edit 0. Exit Enter selection: rootakali:-/ManageComputers/working/temp# root@kali:-/assignments/assignmentl# java ManageComputers *** ERROR: program must run under a Security Manager! ** root@kali:-/assignments/assignment1# ====MENU==== 1. Load 2. Save 3. List 4. Add 5. Delete 6. Edit . Exit Enter selection: 1 *** ERROR: access Denied *** ====MENU==== 1. Load 2. Save 3. List 4. Add 5. Delete 6. Edit 0. Exit Enter selection: ====MENU==== 1. Load 2. Save 3. List 4. Add 5. Delete 6. Edit 0. Exit Enter selection: ADD NEW COMPUTER 1. Add new LaptopComputer 2. Add new Desktop Computer 3. Back to main menu Enter CPU type (15/17) : i9 Enter RAM size (8/16) : Enter disk size (250/500) : 250 Enter screen size (13/15) : 13 ***ERROR : Invalid CPU type*** ADD NEW COMPUTER 1. Add new Laptop Computer 2. Add new Desktop Computer 3. Back to main menu ADD NEW COMPUTER 1. Add new Laptop Computer 2. Add new Desktop Computer 3. Back to main menu Enter CPU type (15/17) : Enter RAM size (8/16) : Enter disk size (250/500) : 250 Enter screen size (13/15) : ***ERROR: Invalid Laptop Computer screen size*** ADD NEW COMPUTER 1. Add new Laptop Computer 2. Add new Desktop Computer 3. Back to main menu ====MENU==== 1. Load 2. Save 3. List 4. Add 5. Delete 6. Edit . Exit Enter selection: DELETE COMPUTER Enter number of computer to delete: 99 *** ERROR: Invalid computer number entered *** ====MENU==== 1. Load 2. Save 3. List 4. Add 5. Delete 6. Edit 0. Exit Enter selection: ====MENU==== 1. Load 2. Save 3. List 4. Add 5. Delete 6. Edit 0. Exit Enter selection: ADD NEW COMPUTER 1. Add new Laptop Computer 2. Add new Desktop Computer 3. Back to main menu ADD NEW COMPUTER 1. Add new Laptop Computer 2. Add new Desktop Computer 3. Back to main menu Enter CPU type (i5/17) : 15 Enter RAM size (8/16): Enter disk size (250/500) : 250 Enter screen size (13/15) : 13 ADD NEW COMPUTER 1. Add new Laptop Computer 2. Add new Desktop Computer 3. Back to main menu ADD NEW COMPUTER 1. Add new Laptop Computer 2. Add new Desktop Computer 3. Back to main menu Enter CPU type (i5/i7) : i7 Enter RAM size (8/16) : Enter disk size (250/500) : 500 Enter GPU (intel/amdvidia) : nvidia ADD NEW COMPUTER 1. Add new Laptop Computer 2. Add new Desktop Computer 3. Back to main menu ADD NEW COMPUTER 1. Add new Laptop Computer 2. Add new Desktop Computer 3. Back to main menu ====MENU==== 1. Load 2. Save 3. List 4. Add 5. Delete 6. Edit 0. Exit Enter selection: ====MENU==== 1. Load 2. Save 3. List 4. Add 5. Delete 6. Edit . Exit Enter selection: COMPUTER #1 Type: Laptop Computer CPU: 15 RAM: 8 GB DISK: 250 GB Screen Size: 13 inches COMPUTER #2 Type: Desktop Computer CPU: 17 RAM: 16 GB DISK: 500 GB GPU: nvidia ====MENU==== 1. Load 2. Save 3. List 4. Add 5. Delete 6. Edit c. Exit Enter selection: 2. Exit Enter selection: COMPUTER #1 Type: LaptopComputer CPU: 15 RAM: 8 GB DISK: 250 GB Screen Size: 13 inches COMPUTER #2 Type: Desktop Computer CPU: 17 RAM: 16 GB DISK: 500 GB GPU: nvidia EESMENU==== 1. Load 2. Save 3. List 4. Add 5. Delete 6. Edit D. Exit Enter selection: EDIT COMPUTER Enter number of computer to edit: 13 Enter CPU type (15/17) : Enter RAM size (8/16): 16 Enter disk size (250/500) : 256 Enter screen size (13/15) : MENUS 1. Load 2. Save 3. List 4. Add 5. Delete 6. Edit 9. Exit Enter selection: ====MENU==== 1. Load 2. Save 3. List 4. Add 5. Delete 6. Edit . Exit Enter selection: COMPUTER #1 Type: Laptop Computer CPU: i5 RAM: 16 GB DISK: 250 GB Screen Size: 13 inches COMPUTER #2 Type: Desktop Computer CPU: 17 RAM: 16 GB DISK: 500 GB GPU: nvidia ====MENU==== 1. Load 2. Save 3. List 4. Add 5. Delete 6. Edit 0. Exit Enter selection: ====MENU==== 1. Load 2. Save 3. List 4. Add 5. Delete 6. Edit C. Exit Enter selection: DELETE COMPUTER Enter number of computer to delete: ====MENU==== 1. Load 2. Save 3. List 4. Add 5. Delete 6. Edit c. Exit Enter selection: COMPUTER #1 Type: Laptop Computer CPU: 15 RAM: 16 GB DISK: 250 GB Screen Size: 13 inches ====MENU==== 1. Load 2. Save 3. List 4. Add 5. Delete 6. Edit 0. Exit Enter selection: root@kali:-/ManageComputers/working/temp# java -cp.:Domain.jar -Dja ====MENU==== 1. Load 2. Save 3. List 4. Add 5. Delete 6. Edit 0. Exit Enter selection: ====MENU==== 1. Load 2. Save 3. List 4. Add 5. Delete 6. Edit 0. Exit Enter selection: COMPUTER #1 Type: Laptop Computer CPU: 15 RAM: 16 GB DISK: 250 GB Screen Size: 13 inches ====MENU==== 1. Load 2. Save 3. List 4. Add 5. Delete 6. Edit 0. Exit Enter selection: ====MENU==== 1. Load 2. Save 3. List 4. Add 5. Delete 6. Edit 0. Exit Enter selection: 2 ====MENU==== 1. Load 2. Save 3. List 4. Add 5. Delete 6. Edit 6. Exit Enter selection: ====MENU==== 1. Load 2. Save 3. List 4. Add 5. Delete 6. Edit 0. Exit Enter selection: rootakali:-/ManageComputers/working/temp# root@kali:-/assignments/assignmentl# java ManageComputers *** ERROR: program must run under a Security Manager! ** root@kali:-/assignments/assignment1# ====MENU==== 1. Load 2. Save 3. List 4. Add 5. Delete 6. Edit . Exit Enter selection: 1 *** ERROR: access Denied *** ====MENU==== 1. Load 2. Save 3. List 4. Add 5. Delete 6. Edit 0. Exit Enter selection: ====MENU==== 1. Load 2. Save 3. List 4. Add 5. Delete 6. Edit 0. Exit Enter selection: ADD NEW COMPUTER 1. Add new LaptopComputer 2. Add new Desktop Computer 3. Back to main menu Enter CPU type (15/17) : i9 Enter RAM size (8/16) : Enter disk size (250/500) : 250 Enter screen size (13/15) : 13 ***ERROR : Invalid CPU type*** ADD NEW COMPUTER 1. Add new Laptop Computer 2. Add new Desktop Computer 3. Back to main menu ADD NEW COMPUTER 1. Add new Laptop Computer 2. Add new Desktop Computer 3. Back to main menu Enter CPU type (15/17) : Enter RAM size (8/16) : Enter disk size (250/500) : 250 Enter screen size (13/15) : ***ERROR: Invalid Laptop Computer screen size*** ADD NEW COMPUTER 1. Add new Laptop Computer 2. Add new Desktop Computer 3. Back to main menu ====MENU==== 1. Load 2. Save 3. List 4. Add 5. Delete 6. Edit . Exit Enter selection: DELETE COMPUTER Enter number of computer to delete: 99 *** ERROR: Invalid computer number entered *** ====MENU==== 1. Load 2. Save 3. List 4. Add 5. Delete 6. Edit 0. Exit Enter selection

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions