473,387 Members | 1,463 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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.

Expand|Select|Wrap|Line Numbers
  1. import java.util.Scanner; // program uses class Scanner
  2.  
  3. public class Invprogram4
  4. {   
  5.    public static void main(String args [])// main method begins application
  6.      {
  7.      Inventory theinventory = new Inventory();
  8.      theinventory.printitem(1);
  9.      theinventory.printitem(2);
  10.      theinventory.printitem(3);
  11.      theinventory.printitem(4);
  12.      theinventory.printitem(5);
  13.      theinventory.printitem(6);
  14.  
  15.      } //End main Method
  16.  
  17.  
  18. }  //End class Invprogram4
  19.  
  20. class Inventory
  21. {
  22.    Stock[] stockarray = new Stock[10];//declares and sets up array
  23.  
  24.    public Inventory()
  25.      {
  26.      stockarray[1] = new Stock(1, "Hand Forged Forks", 5, 2.00);
  27.      stockarray[2] = new Stock(2, "Hand Forged Spoons", 5, 2.00);
  28.      stockarray[3] = new Stock(3, "Hand Forged Knives", 5, 3.00);
  29.      stockarray[4] = new Stock(4, "Hand Forged Hinged Sporks", 10, 5.00);
  30.      stockarray[5] = new Stock(5, "Throwing Knife Blanks", 5, 15.00);
  31.      stockarray[6] = new Forkprongs(6, "Forkprongs", 5, 10.00, 2);
  32.      }//close constructor
  33.  
  34.    public void printitem(int i)
  35.      {    
  36.      System.out.println("The Item number is " + stockarray[i].getproductUPC());
  37.      System.out.println("The Product Name is " + stockarray[i].getproductName());
  38.      System.out.println("The number of units in stock is " +     stockarray[i].getproductQuantity());
  39.      System.out.println("The price per piece is " + stockarray[i].getproductPrice());
  40.      System.out.println("The value of the inventory is " + stockarray[i].getStockValue());    
  41.      }//close printitem method
  42.  
  43.  
  44.    public void getTotalValue()  // total value getStockValue
  45.      {
  46.      int total = 0;
  47.  
  48.      for ( int i=1; i<6; i++ ) total += stockarray[i].getStockValue();
  49.      System.out.printf("Total of stockarray elements %d\n", total);
  50.      }
  51.  
  52.  
  53. }//close class Inventory
  54.  
  55. class Stock
  56.  
  57. {
  58.  
  59.      private double productUPC; // Item number or Universial Product Code
  60.      private String productName;//name of product
  61.      private double productQuantity;//number of pieces in stock
  62.      private double productPrice; //price per piece
  63.      private double productValue; //price of all pieces in a UPC
  64.  
  65.    public Stock(double upc, String name, double quantity, double price)
  66.      {
  67.      //assign variables 
  68.      productUPC = upc;
  69.      productName = name;
  70.      productQuantity = quantity;
  71.      productPrice = price;
  72.      }  //end constructor
  73.  
  74. //collection of set and get methods
  75.  
  76.    public void setproductUPC(double upc) 
  77.      { productUPC = upc; }
  78.  
  79.    public double getproductUPC() 
  80.      { return productUPC; }
  81.  
  82.    public void setproductName(String name) 
  83.      { productName = name; }
  84.  
  85.    public String getproductName() 
  86.      { return productName; }
  87.  
  88.    public void setproductQuantity(double quantity) 
  89.      { productQuantity = quantity; }
  90.  
  91.    public double getproductQuantity() 
  92.      { return productQuantity; }
  93.  
  94.    public void setproductPrice(double price) 
  95.      { productPrice = price; }
  96.  
  97.    public double getproductPrice() 
  98.      { return productPrice; }
  99.  
  100.    public double getStockValue()
  101.      { return this.getproductPrice() * productQuantity; }
  102.  
  103.  
  104. } //end class Stock
  105.  
  106. // This class defines types of forks named forkprongs it is a subclass of forks.  
  107. //It is a stock, but has the extra feature of having prongs as a type and adds a 
  108. //5% restocking fee.
  109.  
  110.    class Forkprongs extends Stock 
  111.      { // starts subclass 
  112.    private int productNumProngs;
  113.  
  114.    public Forkprongs(double UPC, String Name, double Quantity, double Price, 
  115.      int NumProngs)
  116.      {
  117.      super(UPC, Name, Quantity, Price);
  118.      productNumProngs = NumProngs;
  119.      }
  120.  
  121.    public double getproductPrice() 
  122.      {
  123.      double productPrice = super.getproductPrice();
  124.      return (productPrice * 1.05);
  125.      }
  126.  
  127.  
  128. // set and get method for subclass
  129.    public void setproductNumProngs(int NumProngs) 
  130.      { productNumProngs = NumProngs; }
  131.  
  132.    public int getproductNumProngs() 
  133.      { return productNumProngs; }
  134.  
  135. }// end class Forkprongs
  136.  
Jul 5 '08 #1
2 4414
OK, I just came back to this and discovered my spelling was horrific. I apologize.
Jul 5 '08 #2
JosAH
11,448 Expert 8TB
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
Jul 6 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: gregork | last post by:
I have painstakingly created an excel 2000 workbook for the very complex recipes I have to formulate. I have 2 sheets- 1 for configuring the recipe and 1 that is like an inventory of all the raw...
0
by: south622 | last post by:
I'm taking a beginning Java course and I'm stuck in week eight of a nine week course. If anyone could help me I would greatly appreciate it. This assignment was due yesterday and each day I go past...
3
by: ITQUEST | last post by:
The moderator posted this in another thread: (I am starting a new one not to confuse the other subject at hand) ".java classes are compiled to into .class files. If you have a .java file called...
2
by: rookiejavadude | last post by:
I'm have most of my java script done but can not figure out how to add a few buttons. I need to add a delete and add buttong to my existing java program. Not sure were to add it on how. Can anyone...
3
sammyboy78
by: sammyboy78 | last post by:
Hello again, This time I'm creating a program that creates an array of CD objects and then displays the information. I've created a CD class, a CDInventory class and then a CDInventoryDisplay to...
1
by: twin2003 | last post by:
need help with inventory part 5 here is what I have to do Modify the Inventory Program by adding a button to the GUI that allows the user to move to the first item, the previous item, the next...
9
by: xxplod | last post by:
I am suppose to modify the Inventory Program so the application can handle multiple items. Use an array to store the items. The output should display the information one product at a time, including...
11
by: hamiltongreg | last post by:
I am new to Java and am having problems getting my program to compile correctly. My assignment is as follows; Choose a product that lends itself to an inventory (for example, products at your...
2
by: pinkf24 | last post by:
I cannot figure out how to add the following: Modify the Inventory Program to include an Add button, a Delete button, and a Modify button on the GUI. These buttons should allow the user to perform...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.