Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Here are my code files. Any help would be appreciated. We are supposed to use hashcode, the contains ()method, and also collections sort() to sort
Here are my code files. Any help would be appreciated. We are supposed to use hashcode, the contains ()method, and also collections sort() to sort the list by stock number. I need to be able to store it in a 2d array which is giving me the most trouble right now.
O Assignment: Create a Java class named InventoryItem that contains the following members: Properly named variables of appropriate data types for the following information: Stock number (alpha-numeric), item description, item price Create a Java class named Homework7 that performs the following: This file will include your mainline logic (e.g. main method) Given the activity diagram provided in Figure 1 below, create the necessary Java code to satisfy the algorithmic requirements The conditional testing of y input must be case invariant O O O Note: Your program should create the correct output and repeat correctly using data values entered by the user. Table 1 below shows the example input/output used by MISGrader's test case, there are other hidden test cases that you do not have knowledge of the values provided. What is item #1's stock number? 123456 What is item #1's description? Pencil What is item #1's price? 0.59 Are there any other items to add to this transaction? (Y/N) Y What is item #2's stock number? a789z234 What is item #2's description? Eraser What is item #2's price? 2.99 Are there any other items to add to this transaction? (Y/N) Y What is item #3's stock number? d99e-ef What is item #3's description? Paper, college-rule What is item #3's price? 0.89 Are there any other items to add to this transaction? (Y/N) N Did this transaction contain item #123456: true Item 123456 hashcode is: 1450575490 Item a789z234 hashcode is: 481530223 Item d99e-ef hashcode is: 243612588 InventoryItem [sku=123456, desc=Pencil, price=0.59] InventoryItem [sku=a789z234, desc=Eraser, price=2.99] InventoryItem [sku=d99e-ef, desc=Paper, college-rule, price=0.89] Table 1 - Example program input & output act Activity diagram Repeat n times M Input "What is item #" value "'s stock number?' Store stock number in a local variable LIN Output "Did this transaction contain item #123456" value Input "What is item #" value's description?" Store description in a local variable Input "What is item #" value "'s price?" Store price in a local variable Output "Item" value" hashcode is:" value More items in the collection? MY IN Instantiate object of proper type to hold the 3 collected values Add instantiated object to data structure Sort the data structure according to stock number Input" Are there any other items to add to this transaction? (Y/N)" More items in the collection? Output toStringo invocation on each object [Y] [N] Figure 1 Activity diagram D Homework7.java X D Inventoryltem.java 1 package homework7; 2 3e import java.util.Scanner; 25 import demo4. Student; 7 import java.util.Collections; 28 import java.util.ArrayList; 9 10 11 public class Homework7 { 12 public static void main(String[] args) { 13 14 int i=0; //variable to act as iterator 15 String answer = ""; 2.16 Scanner user Input=new Scanner(System.in); 17 18 19 20 do { 21 System.out.println("What is item #"+(i+1)+"'s stock number?"); 9:22 String stockNum=userInput.next(); //input stock number 23 System.out.println("What is item #"+(i+1)+"'s description?"); 24 userInput.nextLine(); 24 25 String itemDes=userInput.nextLine(); //input description 26 System.out.println("What is item #"+(i+1)+"'s price?"); 2427 Double itemPrice=userInput.nextDouble(); //input price 28 29 30 // ArrayListStep 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