2020-11-11 08:47:37 -05:00
|
|
|
/*
|
|
|
|
In main, ask the user for two items and create two objects of the
|
|
|
|
ItemToPurchase class.
|
|
|
|
|
|
|
|
Before asking for the second item, call scnr.nextLine()
|
|
|
|
to allow the user to put in a new string.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
Item 1
|
|
|
|
Enter the item name:
|
|
|
|
Chocolate Chips
|
|
|
|
Enter the item price:
|
|
|
|
3
|
|
|
|
Enter the item quantity:
|
|
|
|
1
|
|
|
|
|
|
|
|
Item 2
|
|
|
|
Enter the item name:
|
|
|
|
Bottled Water
|
|
|
|
Enter the item price:
|
|
|
|
1
|
|
|
|
Enter the item quantity:
|
|
|
|
10
|
|
|
|
Then add the costs of teh two items together and output
|
|
|
|
the total cost
|
|
|
|
|
|
|
|
Example:
|
|
|
|
TOTAL COST
|
|
|
|
Chocolate Chips 1 @ $3 = $3
|
|
|
|
Bottled Water 10 @ $1 = $10
|
|
|
|
|
|
|
|
Total: $13
|
|
|
|
*/
|
|
|
|
|
|
|
|
import java.util.Scanner;
|
|
|
|
|
|
|
|
public class ShoppingCartPrinter {
|
|
|
|
public static void main(String[] args) {
|
|
|
|
Scanner scnr = new Scanner(System.in);
|
2020-11-11 09:20:45 -05:00
|
|
|
ItemToPurchase item1 = new ItemToPurchase();
|
|
|
|
ItemToPurchase item2 = new ItemToPurchase();
|
|
|
|
|
|
|
|
|
|
|
|
System.out.println("Item 1");
|
|
|
|
System.out.println("Enter the item name:");
|
|
|
|
item1.setName(scnr.nextLine());
|
2020-11-11 09:43:59 -05:00
|
|
|
System.out.println("Enter the item price:");
|
|
|
|
item1.setPrice(scnr.nextInt());
|
|
|
|
System.out.println("Enter the item quantity:");
|
|
|
|
item1.setQuantity(scnr.nextInt());
|
|
|
|
scnr.nextLine();
|
2020-11-11 09:20:45 -05:00
|
|
|
|
2020-11-11 09:43:59 -05:00
|
|
|
System.out.println("\nItem 2");
|
2020-11-11 09:20:45 -05:00
|
|
|
System.out.println("Enter the item name:");
|
|
|
|
item2.setName(scnr.nextLine());
|
2020-11-11 09:43:59 -05:00
|
|
|
System.out.println("Enter the item price:");
|
|
|
|
item2.setPrice(scnr.nextInt());
|
|
|
|
System.out.println("Enter the item quantity:");
|
|
|
|
item2.setQuantity(scnr.nextInt());
|
2020-11-11 09:20:45 -05:00
|
|
|
|
2020-11-11 09:43:59 -05:00
|
|
|
System.out.println("\nTOTAL COST");
|
2020-11-11 09:20:45 -05:00
|
|
|
System.out.println(item1.getName() + " " + item1.getQuantity() +
|
|
|
|
" @ $" + item1.getPrice() + " = $" +
|
|
|
|
(item1.getPrice() * item1.getQuantity()));
|
|
|
|
|
|
|
|
System.out.println(item2.getName() + " " + item2.getQuantity() +
|
|
|
|
" @ $" + item2.getPrice() + " = $" +
|
|
|
|
(item2.getPrice() * item2.getQuantity()));
|
2020-11-11 09:43:59 -05:00
|
|
|
System.out.println("\nTotal: $" +
|
2020-11-11 09:20:45 -05:00
|
|
|
((item2.getPrice() * item2.getQuantity()) +
|
2020-11-11 09:43:59 -05:00
|
|
|
(item1.getPrice() * item1.getQuantity())));
|
2020-11-11 08:47:37 -05:00
|
|
|
}
|
|
|
|
}
|
2020-11-11 09:43:59 -05:00
|
|
|
|