Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

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 // ArrayList all= new ArrayList(); 31 //all.add(new InventoryItem(stockNum, itemDes, itemPrice)); 32 33 1/.addItem(new InventoryItem(stockNum, itemDes, itemPrice)); 34 35 36 System.out.println("Are there any other items to add to this transaction? (Y/N)"); 37 answer=userInput.next(); 38 i++; 39 40 41 }while(answer.equals IgnoreCase("Y")); //if answer is Y starts the loop again to enter more records 42 43 }//end main 44 }//end homework import demo4. Student; public class InventoryItem implements Comparable { private final String stockNum; private final String itemDes; private final Double itemPrice; private ArrayList roster= new ArrayList(); public InventoryItem(String stockNum, String itemes, Double itemPrice) { this.stockNum = stockNum; this. itemDes = itemDes; this.itemPrice = itemPrice; } // end ctor. @Override public String toString() { return "InventoryItem [sku=" + stockNum + ", desc=" + itemDes + ", price=" + itemPrice + "]"; }// end toString public int hashCode() { return Objects.hash(this.stockNum); } // end hashCode public boolean equals(Object inc) { if (inc instanceof InventoryItem) { return this.stockNum.equals(((InventoryItem) inc).stockNum); } else { return false; } // end else } // end equals public int compareTo(InventoryItem inc) { return this.stockNum.compareTo(inc. stockNum); } // end compare To public void addItem (InventoryItem inc) { this.roster.add( inc); }//end addItem

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

Database Systems Introduction To Databases And Data Warehouses

Authors: Nenad Jukic, Susan Vrbsky, Svetlozar Nestorov

1st Edition

1943153191, 978-1943153190

More Books

Students also viewed these Databases questions