This program will demonstrate nested loops. Create a Java program that asks for a number of orders to process and use a loop to handle the number the user gives. For each order the program needs to ask the user for how many items are going to be entered for that order. In a loop for each order have it go the number of times the user entered (of how many items for that order) and ask the user for an item price and add it to a total for the order. After the inner loop getting the item prices (for the current order) is over show the total to the user as well as adding it to a grand total. At the end of the program show the grand total of all orders to the user.

Respuesta :

Answer:

import java.util.*;

public class Orders {

   public static void compute() {

     Scanner sc = new Scanner(System.in);

     System.out.print("Enter number of orders: ");    

     int numOrders = sc.nextInt();

     double total = 0.0;

     double grandTotal = 0.0;

     for (int i = 0; i < numOrders; i++){

        System.out.print("Enter number of items for order #" + (i+1) +": ");

        int numItems = sc.nextInt();

        for (int j = 0; j < numItems; j++){

           System.out.print("Enter price for item #" + (j+1) + ": ");

           double price = sc.nextDouble();

           total += price;

        }

        grandTotal += total;

        System.out.println("Total price for this order: " + total);

     }

     System.out.println("Grand Total price for all orders: " + grandTotal);

   }

   public static void main(String[] args){

       compute();

  }

}

Explanation: