• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Beginner: My Inventory Program  RSS feed

 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I am starting on my Inventory part 3 Java and I am running into some problems here. Here is the 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.


I am having some difficulty. I modified one of the Inventory 2 programs I had this week into this, and I have a few questions.

1.) does this code represent what I am trying to do in my assignment, as stated above?
2.) Line 138 is an error "bad operand for (+)"
3.) Line 142 and 148 are warnings to "Add @override"


My code will not compile.
Also, I do not have very good Java lingo skills. I am not that good at Java and I'm trying to learn, but I just can't get it. I'm two weeks from graduating and I just want to get past this class. This is the only class I have had difficulty with.

 
Marshal
Posts: 4051
239
Clojure IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a duplicate of your other thread you started a few days ago right?
 
Os Stewart
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes it is. I'm sorry, I never got anything on it. I've tried to modify some things and I tried to look up some of this stuff and try to figure out the errors, but I ended up doing more damage, so I just started from here again because I was at a loss. I don't quite get this stuff, and the (+) operand error really bugs me because it sounds so simple, but only if you understand this stuff.
 
Rancher
Posts: 1815
15
Android Eclipse IDE Java Java ME
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are you trying to achieve with the following line?

 
Os Stewart
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to get the price of the DVD and add the restocking fee of 5% to the value of the product.
 
Os Stewart
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Swastik Dey wrote:What are you trying to achieve with the following line?



Another thing that gets me is the ending part


If I try to override the annotations, all it does is compile nothing. I tired to get rid of it all to see what would happen, but it just makes things work. Nothing will compile at all with or without it?
 
Os Stewart
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another thing... Line 13 has no warnign but a grey circle to the side that says. "Has sub-classes" would this make a difference at all. I've never heard anything about this before?



Should that matter in this program?
 
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never write 150+ lines of code before testing. I personally write 2-3 at MOST. I may even re-write the same line several times, adding just a piece more, and then compile and test each time.

If this line doesn't work:



simplify it. for now, have it always return something like -1. Then, see if you can get/print the reStockingFee:


then see if you can get the getPrice method to work:


Then see if you can add them together (but still return -1)

Then see if you can return the sum...

I think you are trying to do too much on each compile/test/debug cycle. The less code you write, and the more often you do compile, the easier it is. And it WILL end up SAVING you time in the long run.
 
Os Stewart
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am very new at this. I just added modified an assignment that I had previously and it was very short and simple, then I was asked to modify it and I got really confused. When I tried to use what you just gave me, it still ran into errors. This may sound silly, but we have not used or talked about this, but what does double temp mean in the code you just gave. When I used your code, it said expected ; and also "incompatible types; object can not be converted to double."

 
Swastik Dey
Rancher
Posts: 1815
15
Android Eclipse IDE Java Java ME
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you please be bit more specific about your exact requirement?
 
Os Stewart
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what debugger console looks like:

Listening on javadebug
User program running
User program finished

And I'm starting to wonder if it has something to do with line 13. It's not showing errors, but when I click on the line, and error suddenly shows up and the only thing it says is "Has sub-classes." This is probably not the cause of the error and the two warnings on lines 148 and lines 142, but it should compile something, right? even if it's the beginning part alone?
 
Os Stewart
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Swastik Dey wrote:Could you please be bit more specific about your exact requirement?


Hello,
Yes all I have as the requirements for this assignment is what was written in blue up top.

"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."


Is this helpful?
 
Os Stewart
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fred rosenberger wrote:Never write 150+ lines of code before testing. I personally write 2-3 at MOST. I may even re-write the same line several times, adding just a piece more, and then compile and test each time.

If this line doesn't work:



simplify it. for now, have it always return something like -1. Then, see if you can get/print the reStockingFee:


then see if you can get the getPrice method to work:


Then see if you can add them together (but still return -1)

Then see if you can return the sum...

I think you are trying to do too much on each compile/test/debug cycle. The less code you write, and the more often you do compile, the easier it is. And it WILL end up SAVING you time in the long run.



Hello again,
I don't know what I did, but I messed around with this code and it is now going through with no errors. However, I still can't get anything to compile.
 
Swastik Dey
Rancher
Posts: 1815
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Modify the Inventory Program by creating a subclass of the product


So how does you Product class look like?
 
Os Stewart
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Holy smokes! I got rid of the


and it compiled... It looks like this,

debug:
Grumpy old men 17.0 1.0 1.0
Grumpier Old Men 17.0 2.0 1.0
Pretty Woman 19.95 3.0 1.0
Goast 19.95 4.0 1.0
Gone with the Wind 11.0 5.0 1.0
BUILD SUCCESSFUL (total time: 0 seconds)

but I still need to figure out why it's not showing exactly what I need? But at least it's compiling something! :-) (Sorry, tired of looking at this thing already, glad it did something!)
 
Swastik Dey
Rancher
Posts: 1815
15
Android Eclipse IDE Java Java ME
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It compiled just because of this

 
Swastik Dey
Rancher
Posts: 1815
15
Android Eclipse IDE Java Java ME
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess you are thinking too much. First see what your Product class is. Now extend another class e.g. from Product class and add the other additional features(methods).
 
Os Stewart
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I got rid of the DVD1 class, it compiled. Now I'm trying to see how I can label these columns and make sure that it looks clean. I'm also trying to add the restocking fee to it.
 
Os Stewart
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Swastik Dey wrote:I guess you are thinking too much. First see what your Product class is. Now extend another class e.g. from Product class and add the other additional features(methods).


My product class? Yeah, your right I'm thinking too much. lol Let me see what I can do here. Should I make a class for something like restocking fee for an example? You and everyone here are really helpful. I'm glad that I have others to help, I don't think I could have done it all on my own. :-)
 
Os Stewart
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what I have all together now. Here's an update:

 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ofelia Stewart wrote:
Swastik Dey wrote:I guess you are thinking too much.

I'm thinking too much.

NO!!! You can never think too much when coding. When you are writing a program, it should be 50-80% thinking.

Perhaps you need to start over. Take the original code, compile it, and run it.

Then, make a subclass of the product class, as the specs say. It doesn't have to do ANYTHING different. It can be an empty class. Then use it in your code instead of the product. It should run identically.

THEN add in one feature. something like "String movieTitle = "dummy title". Don't write any getters/setters/anything at all. Compile and test.

THEN write a getter method. compile, test, and prove you can now print out the title.

THEN write a setter method. compile test, and prove you can now set the movie title (and change it, if that is your requirement).

THEN write a value method, but at first have it ONLY return a hardcoded value. the method should contain one statement, akin to "return -1;". Compile and test.

THEN start working on actually doing the computation, building it up a piece at a time. compile and test as you add each piece.


The less you change before you compile and test, the easier it is to see what impact your change had.
 
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ofelia Stewart wrote:This is what I have all together now. Here's an update:

First: Folks (not just Ofelia), please DontWriteLongLines. It makes threads very hard to read. If you're the poster, break them up, and if you're replying to a post, either do the same or don't include them. Thanks.

Now, back to your code.

I've noticed a couple of things that are probably worth mentioning (I'm afraid I haven't read the entire thread, so there may be some duplication).

1. Prices should almost never be held in floating-point types. Use BigDecimal instead. For more info, read this.

2. Stock items and inventory are not the same thing. One is an identifier to something that you sell (or redistribute - eg, a DVD title); the other is the count of actual items that you are storing. Therefore, it's normally bad practise to include stock counts and prices directly with your items. However, this may be a little advanced for your needs right now.

3. Your program (and the spec as you posted it) appears to be a generalized inventory, but your DVD class doesn't subclass anything. Specifically, I suspect it should be subclassing a Product class or interface. Inventory structures can get very involved, but an old mantra that I remember from my BOS days is "cat→item→copy".
  • "Cat" is short for "category", and would probably be something like "DVDs".
  • "Item" - "Terminator 8 - Arnold saves the world after hip replacement"
  • "Copy" - a single copy of the above item (often dealt with in groups).
  • It's by no means the only way to do it, but hopefully it gives you some idea of how inventory is structured. Again, it may be overkill for your purposes, but I give it as something to think about.

    HIH

    Winston
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!