In Java please:
The manager of a Super Supermarket would like to be able to compute the unit price for products sold there. To do this, the program should input the name and price of an item per pound and its weight in pounds and ounces. Then it should determine and display the unit price (the price per ounce) of that item and the total cost of the amount purchased.You will need the following variables:ItemName, Pounds, Ounces, PoundPrice, TotalPrice, UnitPriceYou will need the following formulas:UnitPrice = PoundPrice/16TotalPrice = PoundPrice * (Pounds + Ounces/16)

Respuesta :

Answer:

import java.util.Scanner;

public class Supermarket

{

public static void main (String[] args)

{  

String item;

double pounds, ounces, price,

total, unit;

Scanner scn = new Scanner(System.in);

System.out.print("Please enter the name of item ");

item = scn.nextLine();

System.out.print("Please enter the price of "  + "the item per pound : ");

price = scn.nextDouble();

System.out.print("Enter the weight of "  + "the item in pounds and "  + "ounces respectively : ");

pounds = scn.nextDouble();

ounces = scn.nextDouble();

unit = price/16;

total = price * (pounds + ounces/16);

System.out.print("The unit price of "  + "the products sold is : "  + unit);

System.out.print("\nThe total cost of the "  + "amount purchased is : "  + total);

}

}

Explanation:

  • Ask the user to enter the price of  the item and the weight.
  • Calculate the unit and the total price.
  • Display the unit and the total price.

Answer:

//Import the Scanner class to allow for user's input

import java.util.Scanner;

//Create the class declaration

public class SuperMarket {

   //Write the main method

   public static void main(String[] args) {

       //Create an object of the Scanner class

       //to read in user's input

       Scanner input = new Scanner(System.in);

       

       //Declare all variables with their correct types

       String ItemName;

       double Pounds, Ounces, PoundPrice, TotalPrice, UnitPrice;

       

       //Prompt the user to enter all details one after the other

       //Receive the inputs and store in the right variables

       System.out.println("Please enter the item name");

       ItemName = input.nextLine();

       

       System.out.println("Please enter the price of the item per pound");

       PoundPrice = input.nextDouble();

       

       System.out.println("Please enter the weight of the item in pounds");

       Pounds = input.nextDouble();

       

       System.out.println("Please enter the weight of the item in ounces");

       Ounces = input.nextDouble();

       

       

       //Calculate the unit price using the given formula

       UnitPrice = PoundPrice / 16;

       

       //Calculate the total price using the given formula

       TotalPrice = PoundPrice * (Pounds + Ounces / 16);

       

       //Print out the results as follows;

       System.out.println("Item Name : " + ItemName);

       System.out.println("Unit Price : " + UnitPrice);

       System.out.println("Total Price : " + TotalPrice);

       

       

   }           //End of main method

   

}               //End of class declaration

===========================================================

Sample Output:

>> Please enter the item name

Biscuit

>> Please enter the price of the item per pound

780

>> Please enter the weight of the item in pounds

67

>> Please enter the weight of the item in ounces

90

>> Item Name : Biscuit

>> Unit Price : 48.75

>> Total Price : 56647.5

=============================================================

Explanation:

The above code has been written in Java and it contains comments explaining every line of the code. Please go through the comments carefully.

The actual lines of code in the program have been written in bold face to differentiate it from comments.

A sample output has also been given.