In: Computer Science
Write a program that asks the user to enter an item’s wholesale cost and its markup percentage. It should then display the item’s retail price. For example:
• If an item’s wholesale cost is 5.00 and its markup percentage is 100 percent, then the item’s retail price is 10.00.
• If an item’s wholesale cost is 5.00 and its markup percentage is 50 percent, then the item’s retail price is 7.50.
The program should have a method named calculateRetail that receives the wholesale cost and the markup percentage as arguments, and returns the retail price of the item.
In Java please and thank you.
Java code:
import java.util.Scanner;
public class Main{
//function which calculate retail price
static double calculateRetail(double price,double
percentage){
//returning retail price
return price+price*percentage/100;
}
public static void main(String[] args){
Scanner input=new
Scanner(System.in);
//initializing
price,percentage
double price,percentage;
//asking for cost
System.out.print("Enter wholesale cost: ");
//accepting it
price=input.nextDouble();
//asking for percentage
System.out.print("Enter markup percentage: ");
//accepting it
percentage=input.nextDouble();
//printing Retail price
System.out.printf("Retail price is
%.2f",calculateRetail(price,percentage));
}
}
Screenshot:
Input and Output: