using jGRASP i need the code to run this program Retail Price Calculator Write a
ID: 3848559 • Letter: U
Question
using jGRASP i need the code to run this program
Retail Price Calculator
Write a program 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
Here is the below code for the above scenario:
import java.util.Scanner;
public class RetailPriceCalculator
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
double wholeSaleCost;
double markUpPercentage;
double retailPrice;
System.out.println("Enter the wholesale cost");
wholeSaleCost = input.nextDouble();
System.out.println("Enter the markup percentage");
markUpPercentage = input.nextDouble();
retailPrice = calculateRetail(wholeSaleCost, markUpPercentage);
System.out.println("The retail price is: " + retailPrice);
}
public static double calculateRetail(double wholesale, double markUp)
{
double markUpConverted = markUp/100;
double markUpAmount = wholesale * markUpConverted;
double retail = wholesale + markUpAmount;
return retail;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.