Question
Please finish the last 4 bullet points of this inside the gemstoneApp in java. I cant figure them out. My code is below. public class
Please finish the last 4 bullet points of this inside the gemstoneApp in java. I cant figure them out.
My code is below.
public class Gemstone {
private String color; private int weight; private String shape; private final int id; private static int count; /** * @param color * @param weight * @param shape */ public Gemstone(String color, int weight, String shape) { super(); this.color = color; this.weight = weight; this.shape = shape; id = 12345678 + count; count++; } /** * @return the color */ public String getColor() { return color; } /** * @return the weight */ public int getWeight() { return weight; } /** * @return the shape */ public String getShape() { return shape; } /** * @return the id */ public int getId() { return id; } @Override public String toString(){ String result = "The gemstone weighs " + weight + " pounds and has a " + shape + " shape, id number: " + id; return result; } }
import java.util.ArrayList; import java.util.Scanner;
public class GemstoneApp { static Scanner input = new Scanner(System.in); static int choice = 0; public static void displayMenu() { System.out.println("1. Display all Gemstones"); System.out.println("2. Add an Gemstone"); System.out.println("3. Find an Gemstone"); System.out.println("4. Delete an Gemstone"); System.out.println("5. Number of items in list"); System.out.println("6. Exit"); System.out.print("Enter your selection: "); choice = input.nextInt(); //System.out.println(choice); } //I tried to start ths method but doesnt work /*private static int displayAllGemstones() { for (Gemstone gem: gemstones) { System.out.print(gem); } }*/ public static void main(String[] args) { ArrayList
}
constructor setters-in-eclips It needs to override the method toString. The method toString has no parameters and returns a string that represents an instance of the class. This string needs to include the values of all fields except for count (e.g. 2015 Honda Accord id: 12345679 Labels should be added when the value itself is not self-explanatory. (e.g. id) Sample Output: 1. Display all items 2. Add an item 3. Pind an item 4. Delete an item S. Number of items in list 6. Exit Enter your salection: 1 Instructions continued: At this point you have one class that represents one item (e.g. Book, Bike Gemstone, etc.). This class does not contain the list of items nor should it include any print statements. You still need at least one more class (optionally two) that include(s) the list of items, the menu with options, and the user communication (input / 2011 Toyota Corolla id:12345678 2015 Honda Ascord id:12345679 2a08 Audi 4 id : 12345680 2Q17 Teslaodel 3 ia : 12345681 Create one or two additional classes to do the following Declare an ArrayList of items (each element in the list should be an instance of the new Java type you just wrote) Initialize the list with four different elements (hard coded) 1. Display all items 2. Add an item 3. Find an item 4. Delete an item 5. Nuber of items in 1ist 6. Exit Ente your selection: Display a menu with the following choices until the user chooses to exit 1. Display all items 2. Add an item 3. Find an iten 4. Delete an item 5. Number of items in list 6. Exit Ent r your selection: Important: replace the word item and items with the actual type you store in the list. (e.g. Display all cars) Provide the functionality chosen by the user Use private methods to print the menu and to display, find, add, or delete items. Using private methods in such a way structures the code and to makes the code more clear and easier to read When the user wants to find or delete an item s/he should be prompte for the id number If the user provides and id number that doesn't exist, an appropriate message should be displayed (e.g. The id . could not be found.) If the id number could be found the item information should be displayed as part of the response (e.g. 2015 Honda Accord id:12345679 if the item was found or 2015 Honda Accord has been deleted if it was deleted) Number of ars: 4 .Display all items 2. Add an item 3. Find an item 4. Delete an item 5 Number of items in list 6. Exit Enter your aelection: 3 d 12345680 2008 Audi id:12345680 Display all items 2. Add an item 3 ird an item 4. Delete an item 5. Number of items in list 6. Exit Enter your selection: 4 Id 12345680 2008 Audi A4 has beer deleted If the user enters an invalid choice from the menu (e.g. 9) an 1. Display all items 2. Acld an item 3. Find an item 4, Deleten item S. Nmber of items in liat 6. Exit Enter your selection: 2 appropriate message should be printed (e.g. Enter a selection 1 - 6) If the user enters 6 a message should be printed before terminating th program (e.g. Good bye) Below you can find a sample output. This sample is about cars. Your output needs show elements of the item type you chose above Year 2013 M ke: Ford Model: KustangStep 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