Sign In | Register Now About Bytes | Help | Site Map
Connecting Tech Pros Worldwide

Inventory Program Part3

Question posted by: lilsugaman (Newbie) on July 17th, 2008 07:45 PM
I now have to 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.


Any suggestion on a simple code to start the subclass?
JosAH's Avatar
JosAH
Chief Editor
7,734 Posts
July 17th, 2008
07:54 PM
#2

Re: Inventory Program Part3
Yep, extend your original class and override that method and make it do what
your assignment text tells you what it should do. It's your homework.

kind regards,

Jos

Reply
lilsugaman's Avatar
lilsugaman
Newbie
12 Posts
July 18th, 2008
10:01 PM
#3

Re: Inventory Program Part3
I have tried to create a subclass called premiumProduce that will add a 5% fee to the totalvalue, this is what I have but is not compiling. Please tell me what I'm doing wrong.

1. import java.util.*;
2. import java.text.NumberFormat;
3.
4. public class Produce {
5.
6. //initialize and load array with values
7.
8. private static int[] produceNumber = new int[] {2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024};
9.
10. private static String[] produceName = new String[] {"carrots","potatoe", "bananas", "tomatoe", "lettuce", "apples", "oranges", "grapes", "cherrie", "celery"};
11.
12. private static int[] produceStock = new int[] {20, 50, 12, 15, 10, 30, 40, 6, 75, 8};
13.
14. private static double[] producePrice = new double[] {.50,2.75,.60,1.00,1.50,2.50,3.00,1.89,2.50,1.48};
15.
16.
17. public static void DisplayOutput()
18.
19. { //Displays inventory and totals
20.
21. System.out.println("Item Number\tProduce Name\tStock\tPrice\tTotal Price\n");
22.
23. NumberFormat numForm = NumberFormat.getCurrencyInstance();//Displays double values as currency
24.
25. double totalValue = 0;
26.
27. for (int i=0; i<10; i++){
28.
29. // String price = numform.format(producePrice[i]);
30.
31. System.out.println(produceNumber[i]+"\t\t"+ produceName[i]+"\t\t"+produceStock[i]+"\t"+numForm.format(producePrice[i])+
32.
33. "\t"+(numForm.format(produceStock[i]*producePrice[i])));
34.
35. totalValue=totalValue+(produceStock[i]*producePrice[i]);
36. }
37. System.out.println("\n\nTotal Stock Value: "+numForm.format(totalValue));
38. }
39.}
40.
41. // Inventory Part 3 July 20, 2008
42.
43.
44.
45. class premiumProduce extends Produce
46. {
47.
48.
49. private double restockFee;
50.
51. public premiumProduce(String name, String number, String Stock, Double price)
52. {
53.
54. super(name, number, stock);
55. setRestockFee( fee);
56.
57. }
58.
59. public void setRestockFee( totalValue+0.05 price)
60.
61. {
62.
63. restockFee = fee < 0.0 ? 0.0 : price);
64.
65. }
66.
67. public double getRestockFee()
68.
69.{
70. return restockFee;
71.
72. }
73.
74. public double totalValue()
75.
76. {
77. return getRestockFee();
78.
79. }
80.
81. public String toString()
82.
83. {
84. return String.format("Premium Produce: %s\n%s: $%,.2f",
85.
86. super.toString(), "Restock Fee", getRestockFee() );
87.
88.}
89.
90. }
91.}
92. }

Reply
BigDaddyLH's Avatar
BigDaddyLH
Moderator
1,211 Posts
July 18th, 2008
10:10 PM
#4

Re: Inventory Program Part3
Do you ever plan on getting rid of those parallel arrays and coding this correctly? You have been told about this several times, I just want to know if it will ever sink in?

Reply
JosAH's Avatar
JosAH
Chief Editor
7,734 Posts
July 19th, 2008
10:14 AM
#5

Re: Inventory Program Part3
Quote:
Do you ever plan on getting rid of those parallel arrays and coding this correctly? You have been told about this several times, I just want to know if it will ever sink in?


I'm afraid not; this is one of the cases of "it seems to work, don't touch it anymore".
Which is quite sad actually because the little deformed class keeps on living and
spreading more of a mess than it deserves.

kind regards,

Jos

Reply
lilsugaman's Avatar
lilsugaman
Newbie
12 Posts
July 20th, 2008
12:18 AM
#6

Re: Inventory Program Part3
Well this is the example my instructor gave this is why their still there. If you have another way give me an example so I can understand, I learn by example and visual. Thanks for your help

Reply
JosAH's Avatar
JosAH
Chief Editor
7,734 Posts
July 20th, 2008
06:07 AM
#7

Re: Inventory Program Part3
Quote:
Well this is the example my instructor gave this is why their still there. If you have another way give me an example so I can understand, I learn by example and visual. Thanks for your help


Read my reply #16 in your previous thread.

kind regards,

Jos

Reply
chaarmann's Avatar
chaarmann
Expert
177 Posts
July 21st, 2008
06:55 AM
#8

Re: Inventory Program Part3
Quote:
Read my reply #16 in your previous thread.

kind regards,

Jos


And please read my reply there, too.
I already gave some sample code there to start with.

Reply
Reply
Not the answer you were looking for? Post your question . . .
189,088 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
Top Java Forum Contributors