Write a program that asks the user to enter an items wholesa
Write a program that asks the user to enter an item\'s wholesale cost and its markup percentage. It should then display the items retail price. For example:
If an item\'s wholesale cost is $5.00 and its markup percentage is 100%, then the item\'s retail price is $ 10.00.
If an item\'s wholesale cost is $5.00 and its markup percentage is 50%, then the item\'s retail price is $ 7.50.
The program should have a function named caclulateRetail that takes as parameters the wholesale cost and the markup percentage and returns the retail price of the item. You should not accept negative values for either the wholesale cost of the item or the markup percentage.
Solution
RetailTest.java
import java.util.Scanner;
public class RetailTest {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
double wholeSale = 0;
int percetange = 0;
do{
System.out.print(\"Enter an item\'s wholesale cost: \");
wholeSale = scan.nextInt();
}while(wholeSale <= 0);
do{
System.out.print(\"Enter markup percentage: \");
percetange = scan.nextInt();
}while(percetange <= 0);
double retailPrice = caclulateRetail(wholeSale, percetange);
System.out.println(\"Retail price is \"+retailPrice);
}
public static double caclulateRetail(double wholesale, int percentage ){
double retailPrice = 0;
retailPrice = wholesale + wholesale* percentage/100;
return retailPrice;
}
}
Output:
Enter an item\'s wholesale cost: 5
Enter markup percentage: 100
Retail price is 10.0
Enter an item\'s wholesale cost: 5
Enter markup percentage: 50
Retail price is 7.5
