Answer:
//import the scanner class to allow for user's input
import java.util.Scanner;
//Create a class to house the application
public class OrderProcessor {
//Create the main method where execution starts from
public static void main(String[] args) {
//Create an object of the Scanner class to read user's inputs
Scanner input = new Scanner(System.in);
//Prompt the user to enter number of orders
System.out.println("Enter the number of orders to process");
//Read user input and store in a variable
int noOfOrders = input.nextInt();
//Declare and initialize the variables to hold the
//quantity, price, total and grand total of the order
int quantity = 0;
double price = 0.0;
double total = 0.0;
double grandtotal = 0.0;
//Write a for loop that cycles as many times as the number of orders
for (int i=1; i<=noOfOrders; i++){
//At each of the loop, prompt the user to enter the quantity of each
// order
System.out.println("Enter the quantity of order " + i);
//Read the user input and store in the quantity variable
quantity = input.nextInt();
//Also, prompt the user to enter the price of a quantity of each order
System.out.println("Enter the price of a quantity of order " + i);
//Read the user input and store in the price variable
price = input.nextDouble();
//Calculate the total of each order by multiplying the quantity and
// price
total = quantity * price;
//Print out the total
System.out.println("Total price for order " + i + " is " + total);
//Add the total to the grandtotal
grandtotal += total;
} // End of for loop
//At the end of the loop, print out the grandtotal
System.out.println("The grand total for the order is " + grandtotal);
} //End of main method
} //End of class definition
===========================================================
Sample Output:
>> Enter the number of orders to process
3
>> Enter the quantity of order 1
7
>> Enter the price of a quantity of order 1
30
>> Total price for order 1 is 210.0
>> Enter the quantity of order 2
5
>> Enter the price of a quantity of order 2
30
>> Total price for order 2 is 150.0
>> Enter the quantity of order 3
6
>> Enter the price of a quantity of order 3
30
>> Total price for order 3 is 180.0
>> The grand total for the order is 540.0
===========================================================
Step-by-step explanation:
The program contains comments explaining every line of the code. Please go through the comments.
The actual lines of code have been written in bold face to enhance readability and distinguish them from comments.
A sample output of a run of the program has been given too.