Joanne Neal wrote:Your Event class is immutable (you can't change its state once you've created it. Therefore your grossPrice, discount and netPrice calculations in the toString method will always return the same value. I would therefore be inclined to do these calculations in the constructor which will only be called once rather than in the toString method where they will be calculated every time the method is called.
Joanne Neal wrote:Always try to avoid infinite loops (while(true)) with break statements in them.
makes the purpose of the code a lot clearer.
Joanne Neal wrote:Comments should always be accurate.
Is the comment on line 10 of your Meal class accurate ?
What about the one on line 47 of your CateringCompany class ? If you replace that break by System.exit(0) does the code behave exactly the same ?
Aj Prieto wrote:Your do-while loop could be shortened to:
For discouts, it looks like you have to associate a price for each meal code and multiply that by the amount of people that order it. With that number, you subtract the discounted amount.
James Boswell wrote:I would like to suggest writing a static method on the Event class to validate the meal code:
I will leave you with the implementation of this method which you can then use in your while loop:
Jackson Lawton wrote:
Aj Prieto wrote:On what part are you lost?
First you have to create an instance/object with the constructor of the Event class. Then you add that object to your ArrayList.
Didn't I do that??? It compiles and runs correctly. Oh and I need the mealCode under that loop not month, my original question mentioned that, though I typed in month instead of mealCode in my coding.
Aj Prieto wrote:On what part are you lost?
First you have to create an instance/object with the constructor of the Event class. Then you add that object to your ArrayList.
Aj Prieto wrote:Right now your adding Strings to the arraylist rather than Event. The ArrayList you created takes in Event objects.
So it'd be something like:
Also we can't comment on your event class without seeing what you have.
Campbell Ritchie wrote:No, that looks nothing like 100% right. You have a List<Event> but you are not filling it with Events. You are filling it with Strings. The compiler won’t be happy about that. It won’t be happy about some other things.
Before you can create a List<Event>, you need an Event class. All the inputs like number of guests are used as attributes of the Event class, Create an Event class, with its fields, constructor and a few methods. You might do well to create a Menu class or similar for the entrées. Forget all about the List for the time being. Get one object of the Event class working first, then you can consider the List later.