Hey everyone its my first post and im in desperate need of help. I'm currently working on a project in school. My instructor wants us to create an array with hard coded values and then add the objects from the array into the list. I've already created the hard-coded array and have added the objects into the list that I have created. Now what I want to do next is ask the user if they want to add more items, if yes then I have to add the items they have entered into my list, if no, I need to output a total for the cost.
Here is my code, I have an Item class and Sales class
Aditya Jha wrote: . . .] Trying to be more politically correct.
It never works
Careful about spelling: you have written quantity in one place and quality in another.
Have you really been told to create an Item class with a quantity field? The word item precludes any argument about quantity: an item is always one. You might buy several items of the same sort when shopping, but if I buy two bags of flour, for example, my receipt will look like this
I think you need a class intermediate between item and order, which you might call line, which encapsulates the type of goods (item) and quantity, as long as you don’t buy more than 2147483647 at a time.
**The method add(Item) in the type list is not applicable for the arguments(String)
Is it because answer is a String while my List is from my Item class? Is there any way around this? Thanks.
It is because you told the compiler you would only add Items to that list, and you are adding something different. Look at line 60 in your code. You need to pass the String or whatever to the Item constructor, and add the new Item object.