tl Price Calculator) Write a program that asks the user to enter an item\'s whol
ID: 3750134 • Letter: T
Question
tl Price Calculator) 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 itemExplanation / Answer
Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts. Thanks
// RetailPriceCalculator.java
import java.util.Scanner;
public class RetailPriceCalculator {
/**
* method to calculate retail cost
*
* @param wholesaleCost
* - wholesale price
* @param markup
* - markup percentage
* @return the retail cost
*/
static double calculateRetail(double wholesaleCost, double markup) {
// finding the retail cost
double retailCost = wholesaleCost + wholesaleCost * markup / 100.0;
return retailCost;
}
public static void main(String[] args) {
// scanner to read user input
Scanner scanner = new Scanner(System.in);
// prompting and receiving inputs
System.out.print("Enter wholesale cost: ");
double wholesale = scanner.nextDouble();
System.out.print("Enter markup percentage: ");
double markup = scanner.nextDouble();
// finding and displaying the retail cost, formatting to 2 decimal
// places
System.out.printf("Retail price is : %.2f ",
calculateRetail(wholesale, markup));
}
}
/*OUTPUT (multiple runs)*/
Enter wholesale cost: 5
Enter markup percentage: 50
Retail price is : 7.50
Enter wholesale cost: 25.55
Enter markup percentage: 89.3
Retail price is : 48.37
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.