Sagot :
Answer:
Explanation:
The following is written in Java. It creates the ShoppingCart class as requested and implements the requested methods. A test class has been added to the main method and the output is highlighted in red down below.
import java.util.ArrayList;
import java.util.Scanner;
class Brainly {
public static void main(String[] args) {
ShoppingCart newCart = new ShoppingCart();
newCart.add_item();
newCart.add_item();
newCart.add_item();
newCart.print_summary();
}
}
class ShoppingCart {
Scanner in = new Scanner(System.in);
ArrayList<String> items = new ArrayList<>();
ArrayList<Integer> amount = new ArrayList<>();
ArrayList<Double> cost = new ArrayList<>();
public ShoppingCart() {
}
public void add_item() {
System.out.println("Enter Item:");
this.items.add(this.in.next());
System.out.println("Enter Item Amount:");
this.amount.add(this.in.nextInt());
System.out.println("Enter Cost Per Item:");
this.cost.add(this.in.nextDouble());
}
public void get_total_price() {
double total = 0;
for (double price: cost) {
total += price;
}
System.out.println("Total Cost: $" + total);
}
public void print_summary() {
for (int i = 0; i < items.size(); i++) {
System.out.println(amount.get(i) + " " + items.get(i) + " at " + cost.get(i) + " each.");
}
get_total_price();
}
}