I am pretty proud of myself really. I looked online for the assignment and found the answers and code pretty much done for me, but I decided I was going to give it a whack.
Here's the assignment:
Modify the Inventory Program so the application can handle multiple items. Use an array to store the items. The output should display the information about one product at a time, including the item number, the name of the product, the department of the product, the number of units in stock, the price of each unit, and the value of the inventory of that product. In addition, the output should display the value of the entire inventory.
Create a method to calculate the value of the entire inventory.
Create another method to sort the array items by the name of the product.
Here's my code:
//Thomas Harrald //IT215 Checkpoint Inventory Program //Camera Inventory program import java.util.Scanner; import java.util.Arrays; // Stores and then gets info on a Camera public class CameraProgram2 { public static void main(String args[]) { //Declare Arrays and Scanner Scanner in = new Scanner(System.in); int[] arrayItem = new int[3]; String[] arrayName = new String[3]; String[] arrayDept = new String[3]; int[] arrayUnits = new int[3]; double[] arrayPrice = new double[3]; double[] arrayTotal = new double[3]; double totalValue = 0; //Build the arrays for( int counter =0; counter<=2; ++counter) //For loop to add each part of the array { // input product info System.out.println("Enter the item number:"); arrayItem[counter] = Integer.parseInt(in.nextLine()); System.out.println("Enter the name of the Camera:"); arrayName[counter] = in.nextLine(); System.out.println("Enter the name of the department:"); arrayDept[counter] = in.nextLine(); System.out.println("Enter the units in stock:"); arrayUnits[counter] = Integer.parseInt(in.nextLine()); System.out.println("Enter the price:"); arrayPrice[counter] = Double.parseDouble(in.nextLine()); arrayTotal[counter] = arrayUnits[counter] * arrayPrice[counter]; //Assignment statement for Total Value of the product Units * Price totalValue += arrayTotal[counter]; //Adds the arrayTotal value to totalValue } //For loop to display arrays for( int count =0; count <= 2; ++count) { System.out.printf("\nItem Number:%d\nItem Name:%s\nItem Department:%s\nUnits in Stock:%d\nTotal Value of product:%f\n", arrayItem[count], arrayName[count], arrayDept[count], arrayUnits[count], arrayPrice[count], arrayTotal[count]); } //Sorts array products names and displays them in order Arrays.sort(arrayName); System.out.println(Arrays.toString(arrayName)); System.out.printf("\n%f\n", totalValue); } }
However I don't think the way the displaying of names is exactly what the professor is looking for, however it does not clearly state that the display needs to include all of the products information... so...
Anyways, any tips to improve this program?