473,614 Members | 2,328 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Java Inventory part 4 problem

2 New Member
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 4430
blitz1989
2 New Member
OK, I just came back to this and discovered my spelling was horrific. I apologize.
Jul 5 '08 #2
JosAH
11,448 Recognized Expert MVP
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
3421
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 materials and their specifications. I have many lookup formulas on sheet1 that lookup the specs on the inventory. The problem is sheet 1 works really well but sheet 2 is not really performing as an inventory database like I want it to. The...
0
7108
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 the due date 10% of the grade is taken off. I think I'm coming down with the flu and my brain is just not processing this assignment. Here is the assignment: Modify the Inventory program by adding a button to the GUI that allows the user to move...
3
2132
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 Product.java, when you compile it a .class is created for every class in the file Product.java if there are no errors. In this case you are getting this error because there is no class file called Product.class so you must compile the Product class...
2
2893
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 help? my script is below. thank you import java.awt.*; //import all java.awt import java.awt.event.*; //import all java.awt.event import java.util.*; //import all java.util import javax.swing.*; //import all javax.swing class Product...
3
3579
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 use the previos two. I've gotten all of this code oto compile but I'm still doing something wrong. I'm about to pull my hair out! When I run my CDInventoryDisplay program it comes back with this error: C:\Documents and Settings\Sam>java...
1
2815
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 item, and the last item in the inventory. If the first item is displayed and the user clicks on the Previous button, the last item should display. If the last item is displayed and the user clicks on the Next button, the first item should display. the...
9
7603
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 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 output should display the value of the entire inventory. • Create a method to calculate...
11
7687
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 workplace, office supplies, music CDs, DVD movies, or software). • Create a product class that holds the item number, the name of the product, the number of units in stock, and the price of each unit. • Create a Java application that displays the...
2
2514
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 the corresponding actions on the item name, the number of units in stock, and the price of each unit. An item added to the inventory should have an item number one more than the previous last item. Add a Save button to the GUI that saves the...
0
8591
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8444
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7115
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6093
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5549
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4058
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4138
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2575
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1758
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.