Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Each time we arrive at a station, we must unload our cargo into the station hold for inspection and reload it back into our own

Each time we arrive at a station, we must unload our cargo into the station hold for inspection and reload it back into our own ship's cargo hold when we wish to leave. This is becoming very tedious and taking away time that we could be plundering in space. We head into the station central to research a way to eliminate this problem. We meet a fellow space pirate who has found a solution to the problem we shared. We sit back and listen as he tells us how to find a workaround.

  • We must now store our items in a file and load from the file if prompted by the user. You can make a file with the list of items so you never have to type them in again, and you can control the items that are introduced to our world.
  • All inputs from the user must be verified for accuracy by catching exceptions for invalid inputs.
  • Items have attributes such as Name, Weight, Value, Durability and ID. (make an object called 'Item').
  • We now classify our items by separating them into 3 distinct categories Equipment, Consumable or Material. (You must implement these 3 classes that are subclasses of Item and they must have at least 3 unique attributes in each subclass)
  • We can carry up to 10 items, as long as they don't exceed the maximum weight of the cargo bay, 25 Tons.
  • We need to be able to add and remove items by their name.
  • We need to be able to search for a specific type of item in our cargo bay based on the item's name and one of its attributes (Implement 2 searches - one on name and another on any attribute you choose).
  • We need to be able to sort items by their names alphabetically in order (Use either a selection or insertion sort)
  • We need to know how many of each item we have in our cargo bay and display their attributes.

The driver you are to use has been attached to the module.

Note: You CANNOT modify the MidtermDriver file, you should only modify the file called MidtermMethods.java and you CANNOT change the method headers. You can add other methods as you see fit, but do not modify any of the method headers I have given you. This will break the testing program I have and will result in a lower grade on your assignment.

MidtermDriver:

import java.util.Scanner; public class MidtermDriver { MidtermMethods studentMethods = new MidtermMethods(); Scanner input = new Scanner(System.in); public static void main(String[] args) { new MidtermDriver(); } public MidtermDriver() { Item[] cargohold = new Item[10]; System.out.println("Welcome to the Discipulus Cargo Hold interface."); System.out.println("Please select a number from the options below"); System.out.println(""); while (true) { // Give the user a list of their options System.out.println("1: Add an item to the cargo hold."); System.out.println("2: Remove an item from the cargo hold."); System.out.println("3: Sort the contents of the cargo hold."); System.out.println("4: Search for an item by name."); System.out.println("5: Search for an item by ID."); System.out.println("6: Load from file"); System.out.println("7: Save to a file."); System.out.println("8: Display the items in the cargo hold."); System.out.println("0: Exit the Discipulus Cargo Hold interface."); // Get the user input int userChoice = input.nextInt(); input.nextLine(); switch (userChoice) { case 1: studentMethods.addItem(cargohold); break; case 2: studentMethods.removeItem(cargohold); break; case 3: studentMethods.sortItems(cargohold); break; case 4: studentMethods.searchItemsByName(cargohold); break; case 5: studentMethods.searchItemsByID(cargohold); break; case 6: studentMethods.loadItems(cargohold); break; case 7: studentMethods.saveItems(cargohold); break; case 8: studentMethods.displayItems(cargohold); break; case 0: System.out.println("Thank you for using the

Discipulus Cargo Hold interface. See you again soon!"); System.exit(0); } } } }

MidtermMethods:

public class MidtermMethods { public void addItem(Item cargohold[]) { // TODO: Add an item that is specified by the user } public void removeItem(Item cargohold[]) { // TODO: Remove an item that is specified by the user } public void sortItems(Item cargohold[]) { // TODO: Sort the items in the cargo hold (No need to display them here) - Use // Selection or Insertion sorts // NOTE: Special care is needed when dealing with strings! research the // compareTo() method with strings } public void searchItemsByName(Item cargohold[]) { // TODO: Search for a user specified item } public void searchItemsByID(Item cargohold[]) { // TODO: Search for a user specified item } public void loadItems(Item cargohold[]){ } public void saveItems(Item cargohold[]){ } public void displayItems(Item cargohold[]) { // TODO: Display only the unique items along with a count of any duplicates // For example it should say // Food - 2 // Water - 3 // Ammunition - 5 } }

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

Recommended Textbook for

Operations Management Processes And Supply Chains

Authors: Lee Krajewski, Naresh Malhotra, Larry Ritzman

13th Global Edition

129240986X, 978-1292409863

More Books

Students also viewed these Programming questions