473,543 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Inventory Program Help

9 New Member
I need help with a class project I'm working on, Below is my assignment and the code I have currently created.

Assignment:
Modify the Inventory Program by creating a subclass of the product class that uses one additional unique feature of the product you chose (for the DVDs subclass, you could use movie title, for example). In the subclass, create a method to calculate the value of the inventory of a product with the same name as the method previously created for the product class. The subclass method should also add a 5% restocking fee to the value of the inventory of that product.
• Modify the output to display this additional feature you have chosen and the restocking fee.

Problem:
My code complies but my restocking fee doesn't show up, and I'm not sure how to make it. Do I need to hardcode the fee at the beginning like a statement: reStockFee = .05 or reStockFee = 5%

Any help or suggestions will be greatly appreciated!

Expand|Select|Wrap|Line Numbers
  1. class Product implements Comparable
  2. {
  3.         private long itemNumber;    // class variable that stores the item number
  4.         private String itemName;    // class variable that stores the item name
  5.         private long invQuantity;   // class variable that stores the quantity in stock
  6.         private double itemPrice;   // class variable that stores the item price
  7.  
  8.             public Product(long number, String name, long quantity, double price) // Constructor for the Supplies class
  9.                 {
  10.                     itemNumber = number;
  11.                     itemName = name;
  12.                     invQuantity = quantity;
  13.                     itemPrice = price;
  14.                 }
  15.  
  16.             public void setItemNumber(long number)  // Method to set the item number
  17.                 {
  18.                     this.itemNumber = number;
  19.                 }
  20.  
  21.             public long getItemNumber()  // Method to get the item number
  22.                 {
  23.                     return itemNumber;
  24.                 }
  25.  
  26.             public void setItemName(String name)  // Method to set the item name
  27.                 {
  28.                     this.itemName = name;
  29.                 }
  30.  
  31.             public String getItemName()  // Method to get the item name
  32.                 {
  33.                     return itemName;
  34.                 }
  35.  
  36.             public void setinvQuantity(long quantity)  // Method to set the quantity in stock
  37.                 {
  38.                     invQuantity = quantity;
  39.                 }
  40.  
  41.             public long getInvQuantity()  // Method to get the quantity in stock
  42.                 {
  43.                     return invQuantity;
  44.                 }
  45.  
  46.             public void setItemPrice(double price)  // Method to set the item price
  47.                 {
  48.                     this.itemPrice = price;
  49.                 }
  50.  
  51.             public double getItemPrice()  // Method to get the item price
  52.                 {
  53.                     return itemPrice;
  54.                 }
  55.  
  56.             public double calculateInventoryValue()  // Method to calculate the value of the inventory
  57.                 {
  58.                     return itemPrice * invQuantity;
  59.                 }
  60.  
  61.             public int compareTo(Object o)
  62.                 {
  63.                     Product p = null;
  64.                         try
  65.                             {
  66.                                 p = (Product) o;
  67.                             }
  68.  
  69.                         catch (ClassCastException cE)
  70.                             {
  71.                                 cE.printStackTrace();
  72.                             }
  73.  
  74.                         return itemName.compareTo(p.getItemName());
  75.                 }
  76.  
  77.             public String toString()
  78.                 {
  79.                     return "Item #: " + itemNumber + "\nName: " + itemName + "\nQuantity: " + invQuantity + "\nPrice: $" + itemPrice + "\nValue: $" + calculateInventoryValue();
  80.                 }
  81. }  //end class Product
  82.  
  83. class DVD extends Product
  84. {
  85.     private double reStockingFee;
  86.  
  87.         public DVD(int itemNumber, String itemName, long invQuantity, double itemPrice, double reStockingFee) 
  88.             {
  89.                    super(itemNumber, itemName, invQuantity, itemPrice);
  90.                    this.reStockingFee = reStockingFee;
  91.               }    
  92.         public double getItemPrice() //returns the value of the inventory, plus the restocking fee
  93.             {
  94.                 return super.getItemPrice() + reStockingFee; // TODO Auto-generated method stub
  95.             }
  96.          public String toString() 
  97.             {
  98.                 return new StringBuffer().append("Price: " + super.getItemPrice()).append(" With RestockingFee: " + getItemPrice()).toString();
  99.             }
  100.  
  101. } // end class DVD
  102.  
  103.  
  104. public class Inventory3
  105.  
  106.     {
  107.         Product[] supplies;
  108.  
  109.         public static void main(String[] args)
  110.             {
  111.                 Inventory3 inventory = new Inventory3();
  112.                 inventory.addProduct(new Product(1001, "Megaforce", 10, 18.95));
  113.                 inventory.addProduct(new Product(502, "Abyss", 25, 12.95));
  114.                 inventory.addProduct(new Product(1003, "Deep Impact", 65, 21.95));
  115.                 inventory.addProduct(new Product(750, "Forest Gump", 28, 7.95));
  116.  
  117.                 System.out.println(); // blank line
  118.                 System.out.println("Welcome to DVD Inventory 1.0"); //display header
  119.                 inventory.sortByName(); //sort list by name
  120.                 System.out.println(); // blank line
  121.                 inventory.showInventory(); //display inventory
  122.  
  123.                 double total = inventory.calculateTotalInventory();
  124.                 System.out.println("Total Value is: $" + total);
  125.  
  126.             }
  127.  
  128.         public void sortByName()
  129.             {
  130.                 for (int i = 1; i < supplies.length; i++)
  131.                     {
  132.                         int j;
  133.                         Product val = supplies[i];
  134.                         for (j = i - 1; j > -1; j--)
  135.                             {
  136.                                 Product temp = supplies[j];
  137.                                 if (temp.compareTo(val) <= 0)
  138.                                     {
  139.                                     break;
  140.                                     }
  141.                                 supplies[j + 1] = temp;
  142.                             }
  143.                         supplies[j + 1] = val;
  144.                     }
  145.             }
  146.  
  147.         public String toString() //creates a String representation of the array of products
  148.             {
  149.                 String s = "";
  150.                 for (Product p : supplies)
  151.                     {
  152.                         s = s + p.toString();
  153.                         s = s + "\n\n";
  154.                     }
  155.                 return s;
  156.             }
  157.  
  158.         public void addProduct(Product p1) //Increases the size of the array
  159.             {
  160.                 if (supplies == null)
  161.                     {
  162.                         supplies = new Product[0];
  163.                     }
  164.                 Product[] p = supplies; //Copy all products into p first
  165.                 Product[] temp = new Product[p.length + 1]; //create bigger array
  166.                 for (int i = 0; i < p.length; i++)
  167.                     {
  168.                         temp[i] = p[i];
  169.                     }
  170.                 temp[(temp.length - 1)] = p1; //add the new product at the last position
  171.                 supplies = temp;
  172.             }
  173.  
  174.         public double calculateTotalInventory() //sorting the array using Bubble Sort
  175.             {
  176.                 double total = 0.0;
  177.                 for (int i = 0; i < supplies.length; i++)
  178.                     {
  179.                         total = total + supplies[i].calculateInventoryValue();
  180.                     }
  181.                 return total;
  182.             }
  183.  
  184.         public void showInventory()
  185.         {
  186.             System.out.println(toString()); //call our toString method
  187.         }
  188.  
  189.     } //end Class Inventory3
  190.  
Mar 21 '08 #1
1 2651
chaarmann
785 Recognized Expert Contributor
The stocking fee is not showing up because you are not creating an object of class DVD (the derived class). You are only creating objects of the parent class Product.
Just ask yourself: How can something magically come out that you have not put in? You must define your stocking fee somewhere, and you have to do it in your code in the constructor.

Here you are only adding "Product", but no "DVD"
Expand|Select|Wrap|Line Numbers
  1.                 Inventory3 inventory = new Inventory3();
  2.                 inventory.addProduct(new Product(1001, "Megaforce", 10, 18.95));
  3.                 inventory.addProduct(new Product(502, "Abyss", 25, 12.95));
  4.                 inventory.addProduct(new Product(1003, "Deep Impact", 65, 21.95));
  5.                 inventory.addProduct(new Product(750, "Forest Gump", 28, 7.95));
  6.  
so simply add

Expand|Select|Wrap|Line Numbers
  1.                 inventory.addProduct(new DVD(1005, "Megaforce on DVD", 10, 18.95, 0.5));
Mar 22 '08 #2

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

Similar topics

109
25708
by: zaidalin79 | last post by:
I have a java class that goes for another week or so, and I am going to fail if I can't figure out this simple program. I can't get anything to compile to at least get a few points... Here are the assignments... 4. CheckPoint: Inventory Program Part 1 • Resource: Java: How to Program • Due Date: Day 5 forum • Choose a product that lends...
0
7097
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...
4
2297
nexcompac
by: nexcompac | last post by:
Ok, I posted a similar post but now need to jump back into it. Here is what I have been able to clean up. I am using textpad and jbuilder. Still getting used to the whole java world and I am trying to compile a program using TextPad. Here is what I have so far. /* * Main.java * * Created on July 19, 2007, 5:54 PM *
11
7680
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...
3
6972
by: cblank | last post by:
I need some help if someone could help me. I know everyone is asking for help in java. But for some reason I'm the same as everyone else when it comes to programming in java. I have an inventory program that I have built so far with no problem. But I cannot figure out how to turn it into a GUI application. This is what I'm trying to get it to do....
5
3365
by: cblank | last post by:
I'm having some trouble with my inventory program. Its due tom and my teacher is not wanting to help. He keeps giving me a soluction that is not related to my code. I have everything working except the Delete and Modify Button. The Search button works but it only searchs the new .dat file or what is set in the array. Not sure what is going on...
2
2505
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...
3
4464
by: 100grand | last post by:
Modify the Inventory Program to use a GUI. The GUI 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 GUI should display the value of the entire inventory, the additional...
2
4427
by: blitz1989 | last post by:
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...
0
7412
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7355
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7594
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7697
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...
1
5285
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...
0
3395
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1830
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
979
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
648
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.