473,387 Members | 1,470 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.

Inventory Program Part3

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?
Jul 17 '08 #1
7 4220
JosAH
11,448 Expert 8TB
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
Jul 17 '08 #2
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. }
Jul 18 '08 #3
BigDaddyLH
1,216 Expert 1GB
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?
Jul 18 '08 #4
JosAH
11,448 Expert 8TB
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
Jul 19 '08 #5
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
Jul 20 '08 #6
JosAH
11,448 Expert 8TB
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
Jul 20 '08 #7
chaarmann
785 Expert 512MB
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.
Jul 21 '08 #8

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

Similar topics

13
by: royaltiger | last post by:
I am trying to copy the inventory database in Building Access Applications by John L Viescas but when i try to run the database i get an error in the orders form when i click on the allocate...
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...
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...
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...
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...
1
by: jcato77 | last post by:
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...
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: 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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.