Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Set/get method issues  RSS feed

 
Randal Mortell
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm having issues getting my set/get methods to function. I believe I may have set things up in a way that I've "skipped" them. Basically the program has one main class an inventory class and a sales class. The main class reads two *.txt files through Scanner. One for each class. The Constructors of the classes take the String that has been read and converts the String to int, double, int for Inventory and int, int for Sales. I can get the code to function(ish) without the set/get however they are supposed to be included for the assignment. Any advice would be greatly appreciated. What I understand about set/get is very limited but set "mutates" the value while get returns said value(please correct me if I'm wrong). *** not looking for complete answers to a finished product. I'm going to include my main class and inventory class. sales is basically just a repeat of inventory with different variables. as far as the txt files. The String would read
1165,4.25,15
MAIN CLASS



INVENTORY CLASS



Thanks for any help/advice. If there are any questions I'd be happy to try to answer them.
As far as compiling there hasn't been to much of an issue in its current state.
The only major issue at the moment is my get set methods are not being used.
As far as other things I've tried with the code before I knew set was the mutator I was trying to put my token in the get methods since it isn't void.
First Usage would be in the Inventory Class line 15.
 
Carey Brown
Bartender
Posts: 2992
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Getter methods should not take any arguments.

You should not have a "stock" field. When you pass in "String stock", you should parse it, set the appropriate fields, and then throw the stock String away.

Not sure what the intent of your convert methods are but they are riddled with problems. What is your use case for the convert methods? Are they necessary at all?
 
Randal Mortell
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
they are useless. I deleted them after posting the thread. the original idea behind the convert methods was to take the content out of the constructor and use the methods to do the work but I noticed that the string going into the constructor was basically its "identity" so it doesn't really make sense to take the identity away from an object.
 
Randal Mortell
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. I thought I had to have a String variable in my constructor for it to work.
 
Randal Mortell
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The interesting thing is when I run my code in eclipse it says my get/set methods are fine. but when I run it in IntelliJ IDEA it tells me my set/get methods aren't being used.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66188
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Different IDEs will have different inspection settings defaults. I know the inspections are adjustable in IntelliJ; I don't use Eclipse, but I'd surprised if it was not also so.
 
Randal Mortell
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you.
 
Campbell Ritchie
Marshal
Posts: 55694
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is an option in Eclipse to give you a warning for unused code, but I think that doesn't apply to public methods which are intended to be called from outside the object.
You have shown us the inventory class, but no item classes. Please consider what should be in which class. You do not usually have a price in an inventory, but in an item. An inventory should read something like this:-
123 Motherboard: 3
234 Celeron chipset: 2
345 AMD chipset: 2
456 350W power unit: 2
567 650W power unit: 0
678 2GB RAM unit: 3
789 4GB RAM unit 1
987 1TB disc: 1
876 2.5TB disc: 1
765 4 TB disc: 0
Your inventory class would have restock(), sell() methods, etc, as well as find methods by description or item code. A sell() method would take the number of items sold and alter the counts accordingly.
Description price etc would be fields of the Item objects.
 
Randal Mortell
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The text file I'm reading in is just numbers. the first four are the product code. the second set is the price and the final set is the quantity on hand. Its the file that we are supposed to use. it doesn't include names for any of the products. The sales file is similar to the inventory file. basically an order request. Sales doesn't have a price included. Basically we load the Inventory receive the sales file and compare the product code of the two. If the product code matches we subtract the qty of sales from inventory. If it doesn't match we compare the product code to the next item. If the item is on sales but not in the inventory we provide an error for that instance also.
Invntory.txt
1165,4.25,15
1305,1.80,42
1345,12.56,16
1388,7.42,30
1480,6.54,80
1495,8.36,48
1560,15.27,65

Sales.txt
1165,24
1305,27
1345,12
1360,10
1388,15
1388,20
1495,32
1680,36

 
Winston Gutkowski
Bartender
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Randal Mortell wrote:The text file I'm reading in is just numbers. the first four are the product code. the second set is the price and the final set is the quantity on hand. Its the file that we are supposed to use. it doesn't include names for any of the products.

OK, but nevertheless I'd say you're missing a Product class; but I don't know whether you've been told to only write the two classes you've come up with or not.

"Price", for example, is generally associated with a product, NOT with inventory, since (as we all know) businesses are perfectly capable of raising the price of a can of beans or a piston rod while it's on the shelf - and they're unlikely to do it for just one of them.

HIH

Winston
 
Randal Mortell
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
True. I was told to only have the Main class, the Inventory Class, and the Sales Class.
 
Campbell Ritchie
Marshal
Posts: 55694
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure you were told only to write those three classes, as against only being told to write those three classes? The latter would permit you to write more classes.

I think teachers ought to beware of being too prescriptive in programming assignments. Students should know how to decide how many classes are required.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!