Write a program that asks the user to enter an item’s wholesale cost and its mar
ID: 3885947 • Letter: W
Question
Write a program that asks the user to enter an item’s wholesale cost and its markup percentage.(I NEED JAVA CODE) 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.
Class name: RetailPriceCalculator
out put should be like this
first test
second test
third test
forth test
last test
Explanation / Answer
RetailCostCheck.java
import java.text.DecimalFormat;
import java.util.Scanner;
public class RetailCostCheck {
public static void main(String[] args) {
DecimalFormat df = new DecimalFormat("0.00");
Scanner scan = new Scanner(System.in);
System.out.print("Please enter the wholesale cost or -1 exit: ");
double wholesaleCost = scan.nextDouble();
double percentage = 0;
if (wholesaleCost != -1) {
System.out.print("Please enter the markup percentage or -1 exit: ");
percentage = scan.nextDouble();
}
while (wholesaleCost != -1 && percentage != -1) {
double retailCost = calculateRetail(wholesaleCost, percentage);
System.out.println("The retail price is: " + df.format(retailCost));
System.out.print("Please enter the wholesale cost or -1 exit: ");
wholesaleCost = scan.nextDouble();
if (wholesaleCost != -1) {
System.out
.print("Please enter the markup percentage or -1 exit: ");
percentage = scan.nextDouble();
}
}
}
public static double calculateRetail(double wholesaleCost, double percentage) {
double retailCost = wholesaleCost + (wholesaleCost * percentage) / 100;
return retailCost;
}
}
Output:
Please enter the wholesale cost or -1 exit: 500
Please enter the markup percentage or -1 exit: 5.5
The retail price is: 527.5
Please enter the wholesale cost or -1 exit: 300
Please enter the markup percentage or -1 exit: 3.3
The retail price is: 309.9
Please enter the wholesale cost or -1 exit: 200
Please enter the markup percentage or -1 exit: -1
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.