Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that asks the user to enter an item’s wholesale cost and its mar

ID: 3885372 • Letter: W

Question

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.

Class name: RetailPriceCalculator

out put should be like this

first test

second test

third test

forth test

last test

Explanation / Answer

import java.util.Scanner;

public class RetailPriceCalculator {

/**

* @param args

*/

public static void main(String[] args) {

Scanner scanner = null;

try {

scanner = new Scanner(System.in);

do {

double wholeSaleCost;

do {

// prompt to read wholesale cost

System.out

.print(" Please enter the wholesale cost or -1 exit:");

wholeSaleCost = scanner.nextDouble();

if (wholeSaleCost > 0.0 || wholeSaleCost == -1)

break;

else {

System.out

.println("Wholesale cost cannot be a negative value.");

}

} while (true);

if (wholeSaleCost == -1)

break;

double markUpPercentage;

do {

// prompt to read markup percentage

System.out

.print("Please enter the markup percentage or -1 exit:");

markUpPercentage = scanner.nextDouble();

if ((markUpPercentage > 0.0 && markUpPercentage <= 100)

|| markUpPercentage == -1)

break;

else {

System.out

.println("markup percentage cost cannot be lessthan -100.");

}

} while (true);

if (markUpPercentage == -1)

break;

// print the retail price

System.out.printf("The retail price is: %.2f",

calculateRetail(wholeSaleCost, markUpPercentage));

} while (true);

} catch (Exception e) {

// TODO: handle exception

if (scanner != null)

scanner.close();

}

}

/**

* calculateRetail that receives the wholesale cost and the markup

* percentage as arguments, and returns the retail price of the item.

*

* @param wholeSaleCost

* @param markUpPer

* @return

*/

public static double calculateRetail(double wholeSaleCost, double markUpPer) {

double markUp = markUpPer / 100;

double markUpAmount = wholeSaleCost * markUp;

double retail = wholeSaleCost + markUpAmount;

return retail;

}

}

OUTPUT:

Test 1:

Please enter the wholesale cost or -1 exit:5
Please enter the markup percentage or -1 exit:50
The retail price is: 7.50
Please enter the wholesale cost or -1 exit:-1

Test 2:

Please enter the wholesale cost or -1 exit:-32
Wholesale cost cannot be a negative value.

Please enter the wholesale cost or -1 exit:10
Please enter the markup percentage or -1 exit:-2
markup percentage cost cannot be lessthan -100.
Please enter the markup percentage or -1 exit:50
The retail price is: 15.00
Please enter the wholesale cost or -1 exit:-1

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote