I have two classes here:
public class Invoice {
ArrayList<Double> ItemPrices= new ArrayList<Double>();
ArrayList<Boolean> ItemIsPet = new ArrayList<Boolean>();
ArrayList<Integer> ItemQuantitys = new ArrayList<Integer>();
public void add(Item anItem){
}
public static void main(String args[]){
int counter = 0;
boolean pet;
Scanner s = new Scanner(System.in);
do {
System.out.println();
System.out.print("Item " + counter+1 + ":");
System.out.println();
System.out.print("Please enter the item's price: ");
double inputprice = s.nextDouble();
System.out.println();
System.out.print("Is this item a pet? (Y/N): ");
String inputIsPet = s.next();
if (inputIsPet.equals('Y')){
pet = true;
}
else {
pet = false;
}
System.out.println();
System.out.print("What is the quantity of this item?: ");
int inputquantity = s.nextInt();
Item newItem = new Item(inputprice, pet, inputquantity);
counter += 1;
} while (true);
}
}
And here is the second class:
public class Item {
Invoice Inv = new Invoice();
public Item(double price, boolean isPet, int quantity){
}
}
My question is for this line right here:
Item newItem = new Item(inputprice, pet, inputquantity);
So I have those 3 necessary arguments from the user input so that I can make a new object newItem of type item, but my question is once I have object newItem, how can I access those inputted arguments? My assignment is forcing me to implement this particular "add" method:
public void add(Item anItem)
Basically, the way I want to use this method is to take the inputted arguments from here:
Item newItem = new Item(inputprice, pet, inputquantity);
and have the "add" method access them, and from there put them into these arrays:
ArrayList<Double> ItemPrices= new ArrayList<Double>();
ArrayList<Boolean> ItemIsPet = new ArrayList<Boolean>();
ArrayList<Integer> ItemQuantitys = new ArrayList<Integer>();
But how do I access the parts of the object newItem? Do I have to modify my constructor in some way?