473,386 Members | 1,830 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,386 software developers and data experts.

Can't get my inventory program to compile

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 [Individual] forum
• 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 product number, the name of the product, the
number of units in stock, the price of each unit, and the value of the inventory (the
number of units in stock multiplied by the price of each unit). Pay attention to the good
programming practices in the text to ensure your source code is readable and well
documented.


1. CheckPoint: Inventory Program Part 2
• Resource: Java: How to Program
• Due Date: Day 4 [Individual] forum
• 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 the value of the entire inventory.
• Create another method to sort the array items by the name of the product.


2. CheckPoint: Inventory Program Part 3
• Resource: Java: How to Program
• Due Date: Day 7 [Individual] forum
• 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.


4. CheckPoint: Inventory Program Part 4
• Resource: Java: How to Program
• Due Date: Day 5 [Individual] forum
• 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 attribute,
and the restocking fee.


2. CheckPoint: Inventory Program Part 5
• Resource: Java: How to Program
• Due Date: Day 7 [Individual] forum
• 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.
• Add a company logo to the GUI using Java graphics classes.

Here is the last program that I was able to get to compile... I am supposed to remove the user input section, but no matter what I try, it doesn't work....

[Program removed as per site rules - see FAQ]

Pleeeease java geniuses... HELP!!! :)
I can be reached at <email removed>
Nov 29 '06 #1
109 25676
r035198x
13,262 8TB
Let's go one stage at a time then

[Program removed as per site rules - see FAQ]
Nov 29 '06 #2
horace1
1,510 Expert 1GB
your print statements in main() are a mixture of C++ and Java, i.e. to print to the screen in Java you use System.out.println() not System.out.printf()
main() should look like
Expand|Select|Wrap|Line Numbers
  1. public class Inventory
  2. {
  3.    // main methods begins execution of java application
  4.    public static void main( String args[])
  5.    {
  6.          Supplies mySupplies = new Supplies();
  7.  
  8.          System.out.println("\n\nItem Name: "+mySupplies.getItemName()); //display item name
  9.                  System.out.println("Item Number: "+mySupplies.getItemNumber()); //display item number
  10.                  System.out.println("Quantity in Stock: "+mySupplies.getStockQuantity()); //display quantity in stock
  11.                  System.out.println("Item Price:$ "+mySupplies.getItemPrice()); //display item price
  12.                  System.out.println("Value of Inventory:$ "+mySupplies.calculateInventoryValue()); //display total value of inventory for this item
  13.  
  14.          System.out.println("\n\nEnter item name or enter the word stop to quit:");//prompt
  15.               //   mySupplies.setItemName(input.next()); // read item name or stop
  16.  
  17.  
  18.    } // end main method
  19. }//end class Inventory
  20.  
when run it gives
Item Name:
Item Number: 0.0
Quantity in Stock: 0.0
Item Price:$ 0.0
Value of Inventory:$ 0.0


Enter item name or enter the word stop to quit:

you now need to call setItemName(), setItemNumber(), etc to set up data in mySupplies
Nov 29 '06 #3
yes please and thank you... you are a life saver!!
Nov 29 '06 #4
Let's go one stage at a time then

[Program removed as per site rules - see FAQ]
This one worked beautifully... I guess I was sort of close... Thank you so much... what is the next step...?
Nov 29 '06 #5
r035198x
13,262 8TB
your print statements in main() are a mixture of C++ and Java, i.e. to print to the screen in Java you use System.out.println() not System.out.printf()

[code removed as per site rules - see FAQ]

you now need to call setItemName(), setItemNumber(), etc to set up data in mySupplies
printf is now available in java 1.5
Nov 29 '06 #6
r035198x
13,262 8TB
This one worked beautifully... I guess I was sort of close... Thank you so much... what is the next step...?
Being close is the reason why it was easy to help you. Now have a look at this and make additions so that we can sort by name and test that functionality

[Code removed as per site rules - see FAQ]
Nov 29 '06 #7
Where can I add the %.2f to get the currency to diplay two decimals?
Nov 29 '06 #8
r035198x
13,262 8TB
Where can I add the %.2f to get the currency to diplay two decimals?
Change this line
Expand|Select|Wrap|Line Numbers
  1. System.out.println("Total Value is"+s.getTotalValue());
  2.  
to make it use printf instead of println.
Nov 29 '06 #9
r035198x
13,262 8TB
Change this line
Expand|Select|Wrap|Line Numbers
  1. System.out.println("Total Value is"+s.getTotalValue());
  2.  
to make it use printf instead of println.
Remember Product is just a name I chose, you should change it to something that can be a superclass of some other object as per requirement in Part3
Nov 29 '06 #10
I did this

Expand|Select|Wrap|Line Numbers
  1. System.out.printf("Total Value is: $%.2f\n"+s.getTotalValue());
and got this

$Exception in thread "main" java.util.MissingFormatArgumentException: Format specifier '.2f'
at java.util.Formatter.format(Unknown Source)
at java.io.PrintStream.format(Unknown Source)
at java.io.PrintStream.printf(Unknown Source)
at Inventory2.main(Inventory2.java:153)
Nov 29 '06 #11
Product works doesn't it? it is a list of products that are in stock...

Could I use something like a date recieved, or maybe who the product was ordered by for the subclass?
Nov 29 '06 #12
r035198x
13,262 8TB
Product works doesn't it? it is a list of products that are in stock...

Could I use something like a date recieved, or maybe who the product was ordered by for the subclass?
And what would you be calling that Subclass?
Usually beginners are encouraged to write their own sort functions and all that. Here is how you properly use the Arrays.sort method. Read and understand the need for the comparable interface (if you have not yet done interfaces then that's the price you pay for not writting your own sort function. I have to go in the next fifteen minutes so here is where we've got so far

[code removed as per site rules - see FAQ]
Nov 29 '06 #13
No... I am sorry... I do want to write my own sort function... I thought that was how you did it... Should I take out the import of Array then?

Will you be back on when you could help me more? You have already taught me more than my teacher has during the whole class...
Nov 29 '06 #14
r035198x
13,262 8TB
No... I am sorry... I do want to write my own sort function... I thought that was how you did it... Should I take out the import of Array then?

Will you be back on when you could help me more? You have already taught me more than my teacher has during the whole class...
It's a bit arguable you know. Deepends on what your teacher wants too. You would learn more java by using Arrays.sort, IMO. It is how you would want to do it in practice. On the other hand, writing your own bubblesort (or even quicksort function) might be less efficient but will improve your knowledge of loops and arrays. I suggest you ask your teacher and try to understand the Array.sort route for now. At the end, when you get time, do it both ways and compare. It's the best way to learn. Yeah I'll be in about tomorrow (about 15 hrs from now) but I'm sure there are some people around who will be able to help you.
Nov 29 '06 #15
r035198x
13,262 8TB
Expand|Select|Wrap|Line Numbers
  1.  
  2. public static void main( String args[])
  3.    {
  4.  
  5.      Product[] supplies = new Product[3];
  6.  
  7. >
  8. >
  9. >
  10.   }
  11.  
  12.  
[Code removed as per site rules - see FAQ]

Now because you've been asking the same question in many threads, it has been difficult to track the progress of your exercises. I should probably delete your other threads for this same qustion.

Now you said (somewhere else) that your teacher wants the array to be created in the main method. Will the above one be what you want?
Dec 1 '06 #16
[removed program code as per site rules - see FAQ]

I do think it might be closer, but when I try to run it I get a no class def found error... What did I do wrong?
Dec 1 '06 #17
r035198x
13,262 8TB
Did you save it as Inventory2.java and compile it before running it?
Dec 1 '06 #18
[removed program code as per site rules - see FAQ]

Ok, I thought I did, but I redid it and now it works...
This is good for that assognment I think. Next, I need 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
Dec 1 '06 #19
r035198x
13,262 8TB
You said you will stick with product so what subclass do you want to create now for something with an additional feature to product?
Dec 1 '06 #20
Hmmm...

I dunno, how about Department?
Dec 1 '06 #21
r035198x
13,262 8TB
Hmmm...

I dunno, how about Department?
Department is surely not part of inventory. They want something like
Book(title), DVD(title), MobilePhone(brand), etc. The item in () is the additional feature of the product
Dec 1 '06 #22
Ok, how bout brand then... That sounds good to me...
Dec 1 '06 #23
r035198x
13,262 8TB
Ok, how bout brand then... That sounds good to me...
You mean MobilePhone?
Dec 1 '06 #24
no..

productBrand
Dec 1 '06 #25
r035198x
13,262 8TB
no..

productBrand
What's required is a Product first something that we can model as is a Product then we add something else to it. Alright forget it. Here is an example using mobile phone



[code removed as per site rules - see FAQ]
Dec 1 '06 #26
So would I do that for each item... (Stapler, Pen, etc...)
How does that fit it with the array stuff from the other one? Or am I taking that out?
Dec 1 '06 #27
I guess now I don't understand how that part fits into the other one... Did you take out the Product class and instead use mobilephone? Shouldn't the item be one of the ones from the array?
Dec 1 '06 #28
r035198x
13,262 8TB
I guess now I don't understand how that part fits into the other one... Did you take out the Product class and instead use mobilephone? Shouldn't the item be one of the ones from the array?
Sorry I'd got disconnected for some time.

I think you need to revisit your inheritance to fully understand what is going on. Here is what you should have

[code removed as per site rules - see FAQ]
Dec 1 '06 #29
I get how the subclass inherits from the class,

Now since you used MobilePhone which is another item,

I am confused because I thought the subclass was supposed to be an additional charachteristic of each item, so like underneath the book, pen, etc there would be a brand name for each one... Is that incorrect?

To me it seems like mobile phone would be another addition to the array as a product...
Dec 1 '06 #30
When I run this one, it does appear to add the mobilephone as an additional item, not an additional charachteristic for each item...
Dec 1 '06 #31
r035198x
13,262 8TB
When I run this one, it does appear to add the mobilephone as an additional item, not an additional charachteristic for each item...

"
Modify the Inventory Program by creating a subclass of the product class that uses one
additional unique feature of the product you chose"
The additional feature should not be added to all the items but is unique for that product only.

The subclass-superclass relationship should say a MobilePhone is a Product.

You are asked to come up with something that is a product and write a class for it reusing the other elements you already added for product. The MobilePhone is added to the Products array because it is a Product.
Dec 1 '06 #32
This is what my teacher said...

"You want to add a subclass that extends from your product class. In it, you will add a new attribute which could be brand as you suggested. You will leave in the array and sort."

To me that sounds like she wants the subclass to add a new sttribute; brand, to each item already in the array...

I will double check..
Dec 1 '06 #33
r035198x
13,262 8TB
This is what my teacher said...

"You want to add a subclass that extends from your product class. In it, you will add a new attribute which could be brand as you suggested. You will leave in the array and sort."

To me that sounds like she wants the subclass to add a new sttribute; brand, to each item already in the array...

I will double check..
If you looked at the code I posted, I added brand to MobilePhone. The attribute is to be added to the subclass only as your teacher pointed out. The array and the sort is still there.
Dec 1 '06 #34
I checked again-I thinkg she is crazy...

Anyway, she wants the out put to be the items that were already in the array, and she wants the new subclass to add a new attribute to each item...

Like


Name Pen
Number Price
Quantity
Value
Brand

Name Book
Number Price
Quantity
Value
Brand

Name Chair
Number Price
Quantity
Value
Brand

I played with it andf this is what I have, I know it is not right...

[code removed as per site rules - see FAQ]
Dec 1 '06 #35
r035198x
13,262 8TB
[code removed as per site rules - see FAQ]

I think she meant it to be this way rather. Each Mobile is a product that has a brand. Remember brand is unique only for objects of the type of the subclass ie MobilePhone. As far as I can see, your code for Brand does not make anysense.
Dec 1 '06 #36
I asked her-she wants the subclass to add a new attribute to the items already in the array. Is there a way to do that?
Dec 1 '06 #37
I am looking through my reading, and your version does make more sense-you can see why I am having trouble with this teacher...

Sorry about the confusion-I really do appreaciate your help with this...
Dec 1 '06 #38
This seems to be working as a subclass... Now where should I add the restocking fee?
Dec 1 '06 #39
This is getting there, but you do not want to get rid of the name of the object. That still stays there and is the field to sort on. The MobilePhone class should not have all the old attributes, they belong to the Product class and should be used from there.

This was her response to the most recent version. What she is saying does not make sense... So I need to keep the old array, AND add the new subclass that contains only the brand attribute? I think I am going to fail this class... :(
Dec 2 '06 #40
The brand would be added to all the items. You would now have a new class and it would extend from the Product class. All the items have the old attributes and the new ones as well.

She also said this...
Dec 4 '06 #41
The brand would be added to all the items. You would now have a new class and it would extend from the Product class. All the items have the old attributes and the new ones as well.

She also said this...

I think we are in the same class, or taking the same course. I am having trouble with the part 5. I know that the ones I have turned in so far were not exactly what was requested.
Dec 5 '06 #42
r035198x
13,262 8TB
This is getting there, but you do not want to get rid of the name of the object. That still stays there and is the field to sort on. The MobilePhone class should not have all the old attributes, they belong to the Product class and should be used from there.

This was her response to the most recent version. What she is saying does not make sense... So I need to keep the old array, AND add the new subclass that contains only the brand attribute? I think I am going to fail this class... :(
Unfortunately. you teacher missed that the attributes in Product (name etc) are all defined there as private and so are not available outside the product class. This means for the subclass MobilePhone you have to redefine them. Note that you do not redefine the get and set methods becuse all of them are defined as public in the Product class an so are available in the subclass MobilePhone.

If we make these attributes protected instead of private the become visible in the subclass and we no longer need to redefine them as in

[code removed as per site rules - see FAQ]
Dec 5 '06 #43
I see what you are doing here, but she still seems to want the old items in there (book, pen, etc) and for the new subclass to add the brand attribute to the old items...
Dec 5 '06 #44
How can we take this code and turn it into what is requested in Part 5? I have a similar Inventory program I am working on and have gotten this far but have gotten stuck on parts 4 and 5. Using the GUI is not working out.

2. CheckPoint: Inventory Program Part 5
• Resource: Java: How to Program
• Due Date: Day 7 [Individual] forum
• 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.
• Add a company logo to the GUI using Java graphics classes.
Dec 5 '06 #45
I am still trying to get 4 right before we move on to 5. Why don't you post your #4 if you are done with that one so we can see what you have done...?
Dec 5 '06 #46
I can't get it to compile... Did you?
Dec 5 '06 #47
It is actually 2 seperate files. The second one is at the bottom
Dec 5 '06 #48
r035198x
13,262 8TB
It is actually 2 seperate files. The second one is at the bottom
[code removed as per site rules - see FAQ]

This will make the code compile. May I say that you are using the wrong tools here. To display non-editable text eg labels, you should use a JLabel. Where did you say was the problem with this one?
Dec 6 '06 #49
Now I got it to work... Thanks...

What do we need to do now, I guess this one...


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.

• Add a company logo to the GUI using Java graphics classes.
Dec 6 '06 #50

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

Similar topics

12
by: jason | last post by:
Access 2000: I have a customer-inventory table I need to loop through and compile a list of all the inventory items the customer is tracking. The problem I am finding is that a simple loop...
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...
67
by: hollywoood | last post by:
I am trying to add the Delete button, save and search buttons. I have tried to call my teacher and he is absolutly no help and i have read and reread the text but still have no idea what is going...
4
by: momov4 | last post by:
I can't seem to resolve these errors. I have had people compile these codes on their computers with no problem, but I keep getting errors...can anyone help???? Here are the errors: cannot find...
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...
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...
13
by: jcato77 | last post by:
I am having trouble figuring out my code and was hoping someone could point me in the right direction. Below is my code what I need to due is create a method to add and display the value of the...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
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,...
0
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...

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.