Interstellar travel is possible and almost every citizen owns a ship. I am the captain, and you
Question:
Interstellar travel is possible and almost every citizen owns a ship. I am the captain, and you are my pilot of the space pirate ship, the Depos. Awakening from stasis sleep at a space station in a low-security sector, we get dressed and exit our ship. Before we leave to plunder unknowing travelers passing through dangerous space, our ship needs a few enhancements. We make our way to the engineer post to purchase some ship modifications with the last of our credits. The head engineer sells us on a new weapons system, an improved ballistic shield, and, most importantly, an improved cargo hold that contains our looted items. Each looted item is stored in a fixed-size box, and we can only fit so many boxes onboard.
We need a program that simulates this space world. We will start off by creating a class that meets the following requirements.
- Our ship can only carry 10 items as adding any more items will not fit in our cargo hold. (Use an array of size 10).
- 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 hold based on its name.
- We need to be able to sort items by their names alphabetically in ascending order
- We need to know how many of each item we have in our cargo hold.
As your captain, I have gone ahead and given us a start, but I have more pressing issues to attend to -The needed files are located in the module under the assignments header.
Note: You CANNOT modify the AssignmentDriver file, you should only modify the file called StudentMethods.java.
AssignmentDriver file:
import java.util.Scanner; public class AssignmentDriver { StudentMethods studentMethods = new StudentMethods(); Scanner input = new Scanner(System.in); public static void main(String[] args) { new AssignmentDriver(); } public AssignmentDriver() { String[] cargohold = new String[10]; System.out.println("Welcome to the Revenge 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."); System.out.println("5: 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.searchItems(cargohold); break; case 5: 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); } } } }
StudentMethods file:
public class StudentMethods { public void addItem(String cargohold[]) { // TODO: Add an item that is specified by the user } public void removeItem(String cargohold[]) { // TODO: Remove an item that is specified by the user } public void sortItems(String 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 searchItems(String cargohold[]) { // TODO: Search for a user specified item } public void displayItems(String 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 } }
Business Communication Essentials a skill based approach
ISBN: 978-0132971324
6th edition
Authors: Courtland L. Bovee, John V. Thill