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

THE OUTPUT SHOULD HAVE 2 DECIMAL PLACES. Write a program IN JAVA that prompts th

ID: 3841715 • Letter: T

Question

THE OUTPUT SHOULD HAVE 2 DECIMAL PLACES.

Write a program IN JAVA

that prompts the user for the wholesale price and markup percentage of an item. The program should invoke a method to calculate the retail price of the item.

You will need:

A scanner object to read the wholesale price and the markup percentage
(Note: make sure you let the user know how the percentage should be entered. If it is in a percent format like 25% it would need to be converted to decimal for calculations. If the user entered it as a decimal format then no conversion is necessary.)

Variables to store:

a. The wholesale price (as a double)

b. The markup (as a double – convert if entered as a %

c. (Optional: The retail price, which stores the returned retail value from the method. Keep in mind that you can use the method call directly in an output statement.)

3. A NumberFormat object to display the retail price in currency format (Optional: you can also create a format for the percentage, but it is not as important.)

A method that:

Accepts 2 parameters – the wholesale price and markup percentage

Calculates the retail price

Returns the retail price value

Comments where necessary

A sample of the output is shown below:

Enter the item's wholesale cost: 60
Enter the item's markup percentage (as a %): 75
The item's retail price (at a 75% markup) is $105.00

Explanation / Answer

PROGRAM:

package rpcalculation;

import java.text.NumberFormat;

import java.util.Scanner;

public class rpcalculation {

  

   //method for calculating marked price @params wholesaleprice,markupprice

   private double calculateprice(double wholesaleprice, double markupprice) {

      

       // percentage calculation

       double percentage=markupprice/100;

       //marked price calculation

       double t=wholesaleprice+wholesaleprice*percentage;

       //returnning marked price

       return t;

   }

   public static void main(String[] args)

   {

       //Objec creation

       rpcalculation ob=new rpcalculation();

       //number format object

       NumberFormat numberFormatter = NumberFormat.getCurrencyInstance();

       //scanner object

       Scanner in=new Scanner(System.in);

      

       System.out.println("Enter the item's wholesale cost:");

       //reading the wholesale cost

       double wholesaleprice=in.nextDouble();

       System.out.println("Enter the item's markup percentage (as a %):");

       //reding the percentage

       double markupprice=in.nextDouble();

       // calling the method and getting the marked price as double

       double price=ob.calculateprice(wholesaleprice,markupprice);

       //printing the output

       System.out.println("The item's retail price (at a " +markupprice +"% Markup) is "+numberFormatter.format(price)) ;

   }

}

OUTPUT:

Enter the item's wholesale cost:

100

Enter the item's markup percentage (as a %):

40

The item's retail price (at a 40.0% Markup) is Rs.140.00