import javax.swing.JFrame; import java.awt.*; import javax.swing.*; import java.awt.event.*; public class Inventory extends JFrame { private Container cp = getContentPane(); private static int itemNum[] = new int[3]; private static String name[] = new String[3]; private static int units[] = new int[3]; private static double price[] = new double[3]; private static boolean isRestock[] = new boolean[3]; Object rows[][] = new Object[3][6]; private static int i = 0; String titles[] = new String[] { "Item #","Name","Units","Unit Price","Restock Fee","Value Of Inventory"}; public Inventory(){ setLayout(new FlowLayout()); }// public Inventory(int _itemNum, String _name, int _units, double _price)// { itemNum[i] = _itemNum; name[i] = _name; units[i] = _units; price[i] = _price; i = i + 1; } public Inventory(int _itemNum, String _name, int _units, double _price, boolean isR) { isRestock[i] = isR; Inventory I = new Inventory(_itemNum, _name, _units, _price); } public static double valueOfInventory(double p,int u) { return p*u; } public void showInventory() { for (int j = 0; j < i; j++) { rows[j][0] = itemNum[j]; rows[j][1] = name[j]; rows[j][2] = units[j]; rows[j][3] = "$" + price[j]; rows[j][4] = "$" + Products.valueOfRestockFee(price[j], units[j], isRestock[j]); rows[j][5] = "$" + valueOfInventory(price[j], units[j]); } JTable table = new JTable(rows, titles); table.setPreferredScrollableViewportSize(table.getPreferredSize()); JScrollPane scrollPane = new JScrollPane(table); JLabel lblVofI = new JLabel("Total Value of Inventory"); lblVofI.setPreferredSize(new Dimension(400, 15)); cp.add(scrollPane, BorderLayout.CENTER); cp.add(lblVofI); lblVofI.setText("Total Value of Inventory is =" + showValueofInventory()); } public double showValueofInventory() { double totalVal = 0; for (int j = 0; j < i; j++) { totalVal = totalVal + valueOfInventory(price[j], units[j]); } return totalVal; //System.out.println("\n-----------Total Value of Inventory is = " + totalVal); } //public static void sortByProduct() //{ // for (int j = 0; j < i; j++){ // int min = j; // for (int k = j; k < i; k++){ // if (name[k].compareTo(name[min]) < 0){ // min = k; // } // } // sortItems(j, min); // String tmp; // tmp = name[j]; // name[j] = name[min]; // name[min] = tmp; // } // System.out.println("\n************Inventory sorted by products***********\n"); // showInventory(); //} //public static void sortItems(int j, int min) //{ // int temp = itemNum[j]; // itemNum[j] = itemNum[min]; // itemNum[min] = temp; // temp = units[j]; // units[j] = units[min]; // units[min] = temp; // double temp1 = price[j]; // price[j] = price[min]; // price[min] = temp1; //} }