Is there a way I can have quantitySold stay as an instance or if not are there any suggestions on how I can use this with static? Thank you for any suggestions.
***Sidenote*** The most of the comments are me just blocking things out that I'm trying til I find a path that works.
As Paul C has already suggested, the correct answer to that error is not to make the target static. It is to move the calling code out of the static context into a
Randal Mortell wrote:. . . I receive errors until I convert anything . . . to static. . . .
I wish those error messages would say instance rather than
2. You got inconsistent code indentation, that is not good, you need to be consistent how you place curly braces, if you leave empty lines or not in between successor methods (read coding convention).
3. Lots of commented out code needs to be removed too, that adds its own bit to a total mess.
4. In Inventory and Sales classes constructors you got lots of duplicated code. Have you ever encountered keyword this used in constructors context?
5. Why have you got no argument constructor with an empty body?
6. When you use Scanner for files reading - use Path, instead FileReader. That would look (what is in quotes needs to be full path where the file is located):
7. As Campbell Ritchie already mentioned, most likely you'll need to rewrite your main method. That should be quick - just delete everything what is in there. The code which is currently laying down in there you'll need to move somewhere else to a non static method. Follow instructions CR gave you as a link.
Hi Randall once again. No need to sorry, all good.
Randal Mortell wrote:Sorry. Its me again. So as far as that link for running a run() method in main. Would I call any variables or is that handled in the run method also?
or basically am I mirroring the program to a window? if that makes sense.
Now about the code. There are many issues with it. The problem I see, that you're trying to do too many things in one go without having confident that what you did so far at least contains 1 part which is correct. It is not a Hello, World problem. You need to think about the project as a whole first, might draw some diagrams, one of those could be a Class diagram, so you could see relations of classes. Have you learned about drawing class diagrams?
By extending Main class I meant couple of the very first lines in your Sales and Inventory classes:
Randal Mortell wrote:
Please explain why you're doing that?
Randal Mortell wrote:
I'd suggest you to forget about the Main class and all interaction of the program and choose one class to work on, either Sales or Inventory. You know that you can add static main method to one of those classes just for a test purpose to test it independently from the rest of your program? Later of course you'd need to remove it, but in that manner you wouldn't need to to think about writing 2 classes at the same time, so in that main method you could pass some dummy data to simulate sales or inventory files content.
Once you are confident, that your class has functionality you want it to have and the outcome of it is as expected, you can remove that temporary main method and move on with another class. ONCE you got Sales and Inventory classes, you can think of the other class where program interaction happens. It could be in the Main class as you have now, but it should be at least in other method, check the tutorial written by one of moderators Winston, kudos to him for that, this tutorial helps thousands of people, you can go through it here (<-- link). [interim comment] Campbell Ritchie gave you this tutorial link already, so now you really have to go through it.
When you override methods as you do with toString method, add @Override notation. Read about it what it does.
- X 2
When I finish with the project I delete and respace everything.
If I'm understanding you, you leave formatting to the end, as if it's a "make things pretty" step. I believe this is an error. Good formatting is vital for good programming. It helps you avoid many kinds of errors and helps to organize your code.