Create two files to submit: ItemToPurchase.java - Class definition ShoppingCartPrinter.java - Contains main() method
~Build the ItemToPurchase class with the following specifications:
Private fields
-String itemName - Initialized in default constructor to "none"
-int itemPrice - Initialized in default constructor to 0
-int itemQuantity - Initialized in default constructor to 0
Default constructor
Public member methods (mutators & accessors)
-setName() & getName()
-setPrice() & getPrice()
-setQuantity() & getQuantity()
-In main(), prompt the user for two items and create two objects of the ItemToPurchase class. Before prompting for the second item, call scnr.nextLine(); to allow the user to input a new string.
-Add the costs of the two items together and output the total cost.
Below is my code for ShoppingCartPrinter:
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
ItemToPurchase item1 = new ItemToPurchase();
ItemToPurchase item2 = new ItemToPurchase();
//String inputName = "";
//int inputPrice = 0;
//int inputQuantity = 0;
item1.setName("testName");
item1.setQuantity(1);
item1.setPrice(1);
String itemName = item1.getName();
int itemQuantity = item1.getQuantity();
int itemPrice = item1.getPrice();
System.out.println(itemName);
System.out.println(itemPrice);
System.out.println(itemQuantity);
}
//Add the costs of the two items together and output the total cost.
}
Below is my code for ItemToPurchase:
public class ItemToPurchase {
// The class' private internal fields
private String itemName;
private int itemPrice;
private int itemQuantity;
// The class' public methods
public void setName(String inputName) {
itemName = inputName;
}
public String getName() {
return itemName;
}
public void setPrice(int inputPrice) {
itemPrice = inputPrice;
}
public int getPrice() {
return itemPrice;
}
public void setQuantity(int inputQuantity) {
itemQuantity = inputQuantity;
}
public int getQuantity() {
return itemQuantity;
}
}
I getting more and more confused as I look for resources to help me and haven't heard back from my Professor. The code builds without errors but doesn't copy. This is he error I am getting: