473,320 Members | 2,094 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,320 software developers and data experts.

Inventory Program Help

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 2633
chaarmann
785 Expert 512MB
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
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...
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...
4
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...
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...
3
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...
5
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...
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...
3
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...
2
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.