Westonci.ca is the best place to get answers to your questions, provided by a community of experienced and knowledgeable experts. Connect with a community of experts ready to provide precise solutions to your questions quickly and accurately. Our platform offers a seamless experience for finding reliable answers from a network of knowledgeable professionals.
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();
}
}
We hope you found this helpful. Feel free to come back anytime for more accurate answers and updated information. We hope this was helpful. Please come back whenever you need more information or answers to your queries. Discover more at Westonci.ca. Return for the latest expert answers and updates on various topics.