Java Inventory part 4 problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • blitz1989
    New Member
    • Jul 2008
    • 2

    #1

    Java Inventory part 4 problem

    Hello all, I'm new to this forum and Java and having a alot of problems understanding this language. I am working on an invetory program part 4. The assignment requirements are listed but the reading has very little in it that helps can someone take a look at this code and point me in the right direction please. Thanks for any help that is offered.

    //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.

    [code=java]
    import java.util.Scann er; // program uses class Scanner

    public class Invprogram4
    {
    public static void main(String args [])// main method begins application
    {
    Inventory theinventory = new Inventory();
    theinventory.pr intitem(1);
    theinventory.pr intitem(2);
    theinventory.pr intitem(3);
    theinventory.pr intitem(4);
    theinventory.pr intitem(5);
    theinventory.pr intitem(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.prin tln("The Item number is " + stockarray[i].getproductUPC( ));
    System.out.prin tln("The Product Name is " + stockarray[i].getproductName ());
    System.out.prin tln("The number of units in stock is " + stockarray[i].getproductQuan tity());
    System.out.prin tln("The price per piece is " + stockarray[i].getproductPric e());
    System.out.prin tln("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.prin tf("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(d ouble upc)
    { productUPC = upc; }

    public double getproductUPC()
    { return productUPC; }

    public void setproductName( String name)
    { productName = name; }

    public String getproductName( )
    { return productName; }

    public void setproductQuant ity(double quantity)
    { productQuantity = quantity; }

    public double getproductQuant ity()
    { return productQuantity ; }

    public void setproductPrice (double price)
    { productPrice = price; }

    public double getproductPrice ()
    { return productPrice; }

    public double getStockValue()
    { return this.getproduct Price() * 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 productNumProng s;

    public Forkprongs(doub le UPC, String Name, double Quantity, double Price,
    int NumProngs)
    {
    super(UPC, Name, Quantity, Price);
    productNumProng s = NumProngs;
    }

    public double getproductPrice ()
    {
    double productPrice = super.getproduc tPrice();
    return (productPrice * 1.05);
    }


    // set and get method for subclass
    public void setproductNumPr ongs(int NumProngs)
    { productNumProng s = NumProngs; }

    public int getproductNumPr ongs()
    { return productNumProng s; }

    }// end class Forkprongs
    [/code]
    Last edited by JosAH; Jul 5 '08, 08:32 PM. Reason: added [code] ... [/code] tags
  • blitz1989
    New Member
    • Jul 2008
    • 2

    #2
    OK, I just came back to this and discovered my spelling was horrific. I apologize.

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      Your current classes have set up a 'model' of your stock and a bit of a 'view'
      that displays the entire inventory (btw, arrays start their index values at 0, not
      at the value 1). Your last assignment wants you to replace your 'view' by a GUI
      based view, not just the console.

      For starters have a look at the JFrame class, you'll definitely need it and have
      a look at the JTable class; it can display the 'records' of your inventory. There
      isn't much of a 'controller' in your program because you don't want to, or have to
      do much with your inventory, you just have to display it.

      kind regards,

      Jos

      Comment

      Working...