//Modify the Inventory Program to use a GUI. The GUI should display the
//informationone product at a time, including the item number, the name 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 GUI should display the value of
//the entire inventory, the additional attribute,and the restocking fee.
Expand|Select|Wrap|Line Numbers
- import java.util.Scanner; // program uses class Scanner
- public class Invprogram4
- {
- public static void main(String args [])// main method begins application
- {
- Inventory theinventory = new Inventory();
- theinventory.printitem(1);
- theinventory.printitem(2);
- theinventory.printitem(3);
- theinventory.printitem(4);
- theinventory.printitem(5);
- theinventory.printitem(6);
- } //End main Method
- } //End class Invprogram4
- class Inventory
- {
- Stock[] stockarray = new Stock[10];//declares and sets up array
- public Inventory()
- {
- stockarray[1] = new Stock(1, "Hand Forged Forks", 5, 2.00);
- stockarray[2] = new Stock(2, "Hand Forged Spoons", 5, 2.00);
- stockarray[3] = new Stock(3, "Hand Forged Knives", 5, 3.00);
- stockarray[4] = new Stock(4, "Hand Forged Hinged Sporks", 10, 5.00);
- stockarray[5] = new Stock(5, "Throwing Knife Blanks", 5, 15.00);
- stockarray[6] = new Forkprongs(6, "Forkprongs", 5, 10.00, 2);
- }//close constructor
- public void printitem(int i)
- {
- System.out.println("The Item number is " + stockarray[i].getproductUPC());
- System.out.println("The Product Name is " + stockarray[i].getproductName());
- System.out.println("The number of units in stock is " + stockarray[i].getproductQuantity());
- System.out.println("The price per piece is " + stockarray[i].getproductPrice());
- System.out.println("The value of the inventory is " + stockarray[i].getStockValue());
- }//close printitem method
- public void getTotalValue() // total value getStockValue
- {
- int total = 0;
- for ( int i=1; i<6; i++ ) total += stockarray[i].getStockValue();
- System.out.printf("Total of stockarray elements %d\n", total);
- }
- }//close class Inventory
- class Stock
- {
- private double productUPC; // Item number or Universial Product Code
- private String productName;//name of product
- private double productQuantity;//number of pieces in stock
- private double productPrice; //price per piece
- private double productValue; //price of all pieces in a UPC
- public Stock(double upc, String name, double quantity, double price)
- {
- //assign variables
- productUPC = upc;
- productName = name;
- productQuantity = quantity;
- productPrice = price;
- } //end constructor
- //collection of set and get methods
- public void setproductUPC(double upc)
- { productUPC = upc; }
- public double getproductUPC()
- { return productUPC; }
- public void setproductName(String name)
- { productName = name; }
- public String getproductName()
- { return productName; }
- public void setproductQuantity(double quantity)
- { productQuantity = quantity; }
- public double getproductQuantity()
- { return productQuantity; }
- public void setproductPrice(double price)
- { productPrice = price; }
- public double getproductPrice()
- { return productPrice; }
- public double getStockValue()
- { return this.getproductPrice() * productQuantity; }
- } //end class Stock
- // This class defines types of forks named forkprongs it is a subclass of forks.
- //It is a stock, but has the extra feature of having prongs as a type and adds a
- //5% restocking fee.
- class Forkprongs extends Stock
- { // starts subclass
- private int productNumProngs;
- public Forkprongs(double UPC, String Name, double Quantity, double Price,
- int NumProngs)
- {
- super(UPC, Name, Quantity, Price);
- productNumProngs = NumProngs;
- }
- public double getproductPrice()
- {
- double productPrice = super.getproductPrice();
- return (productPrice * 1.05);
- }
- // set and get method for subclass
- public void setproductNumProngs(int NumProngs)
- { productNumProngs = NumProngs; }
- public int getproductNumProngs()
- { return productNumProngs; }
- }// end class Forkprongs