Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Complete the following Java program to perform the tasks indicated in the in-lin

ID: 3799685 • Letter: C

Question

Complete the following Java program to perform the tasks indicated in the in-line comments below.

import java.util.Scanner;
public class T1_Q12
{
public static void main (String[] args)
{
     int quantity;
     double unitPrice, totalCost;
     Scanner scan = new Scanner (System.in);
     
    //Write Java codes that prompt the user to enter quantity and read it into the proper variable
  
    


    //Write java codes that prompt the user to enter unit price and read it into the proper variable
  


    //Compute the total cost

    


    // printout all variables with proper labels and lineup the outputs using tabs
  


   }
}

Explanation / Answer

Program

import java.util.Scanner;
public class T1_Q12
{
public static void main (String[] args)
{
int quantity;
double unitPrice, totalCost;
Scanner scan = new Scanner (System.in);

//Write Java codes that prompt the user to enter quantity and read it into the proper variable

  
System.out.print("Enter The Quantity :");
quantity=scan.nextInt();

//Write java codes that prompt the user to enter unit price and read it into the proper variable
System.out.print("Enter The Unit Price :");
unitPrice=scan.nextDouble();

//Compute the total cost
totalCost=quantity * unitPrice;
  

// printout all variables with proper labels and lineup the outputs using tabs
System.out.println("Quantity= "+quantity);
System.out.println("Unit Price= "+unitPrice);
System.out.println("Total Price= "+totalCost);
scan.close();

}
}

Output

Enter The Quantity :10
Enter The Unit Price :155.58
Quantity= 10
Unit Price= 155.58
Total Price= 1555.8000000000002