• Post Reply Bookmark Topic Watch Topic
  • New Topic

Having Trouble Inputting data  RSS feed

 
Kyle Ruey
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am still working on my inventory program and I finally got it to where it will run with no errors. Only thing is when it displays the lines I can not figure out how to make it print one line at a time to allow for user input to be put in place of a value. For instance Enter Item Name :

Here is the code I have so far trust me its not the best looking code ever.

 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have added code tags again. Please use them. Also please indent your code. I sorted out some of the indentation but look at lines 93-95.
Why do you have a products class extending from Array101? If the names of the classes are accurate then I doiubt whether you should extend the Array class.
Why do you have that nested class?
In line 114 you are returning 0 regardless. I am sure that is wrong. Also reassigning the field from a getXXX method is wrong. You are doing that sort of thing in several places. Actually you aren't reassigning fields. Look closely at those set methods. Also look closely to find where you declared those fields.

Start by getting a decent text editor (for Windows® .I suggest NotePad++) and enabling the options shown in this post. Then learn my indenting technique which involves writing backwards. That way you will get the indentation right and you will be able easily to see where the code is.
Then set up the product class first. Get methods simply return a value. Do not change the fields. The constructor should set up all the fields so create a constructor requiring every field as a parameter. And set the values in the constructor. Now don't do anything outside the product class to change its innards. If anything changes, it must be via methods. Only after you have the product class working can you consider creating those arrays.

A class should not know how many instances of itself are in stock. That does not belong to the product but to an inventory (somewhere else).
 
Kyle Ruey
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I really appreciate all your help but I will be honest with you I dont know why I did all those things. This is only my 2nd week in the class and I am completey lost. So much so that I have thought about dropping out of the class.
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can tell you where you declared those fields: nowhere. You forgot to write them down. Then you wrote local variables because otherwise the class wouldn't compile.


Now, you want a product class with private fields like ID, price, description. You will remember what they should be a lot better than me. Don't say it extends anything.
Your class wants a constructor which takes values for all those fields as its parameters and sets up sensible initial values for every field. Give it one constructor and only one.
Give the class some methods, e.g. getPrice. Also a toString method which should return something like
"Product ID 87465834 sprunging flange price $123.45"
Don't use the keyword static anywhere that you don't absolutely have to. I think there will be only one place you need static: after public and before void main(String[] args).

Now write some code like:-Once you get that working, try all the Product methods you can find and repeat the print call. If you get that to run, you will know whether your product class works
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!