PLEASE FIX AND MODIFY THIS JAVA PROGRAM SO WHEN I UPLOAD IT TO HYPERGRADE IT PASSES ALL TEST CASSES PLEASE. RIGHT NOW IT SAYS 0 OUT 5 PASSED. THE PROGRAM IS NOT WORKING IN HYPERGRADE FIX IT SO IT WILL WORK IN HYPERGRADE. THANK YOU.
JAVA PROGRAM
PLEASE FIX AND MODIFY THIS JAVA PROGRAM SO WHEN I UPLOAD IT TO HYPERGRADE IT PASSES ALL TEST CASSES PLEASE. RIGHT NOW IT SAYS 0 OUT 5 PASSED. THE PROGRAM IS NOT WORKING IN HYPERGRADE FIX IT SO IT WILL WORK IN HYPERGRADE. THANK YOU.
import java.util.Scanner;
public class Main {
public static double calculateRetail(double wholesale, double percentage) {
if (percentage < -100) {
throw new IllegalArgumentException("Markup cannot be less than -100%.");
}
return wholesale + wholesale * (percentage / 100);
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double wholesale;
double percentage;
do {
System.out.println("Please enter the wholesale cost: ");
wholesale = sc.nextDouble();
} while (wholesale < 0);
do {
System.out.println("Please enter the markup percentage: ");
percentage = sc.nextDouble();
} while (percentage < -100);
double retailPrice = calculateRetail(wholesale, percentage);
System.out.printf("The retail price is: %.2f\n", retailPrice);
}
}
Test Case 1
10ENTER
Please enter the markup percentage or -1 exit:\n
-1ENTER
Test Case 2
100ENTER
Please enter the markup percentage or -1 exit:\n
100ENTER
The retail price is: 200.00\n
Please enter the wholesale cost or -1 exit:\n
-1ENTER
Algorithm: Retail Price Calculator
1. Create a class named RetailPriceCalculator.
2. Define a static method in the class:
- Method name: calculateRetail
- Input: wholesale_cost (float), markup_percentage (float)
- Output: retail_price (float)
3. Inside calculateRetail method:
a. Check if wholesale_cost is less than 0:
- Return 0.00
b. Check if markup_percentage is less than -100:
- Return 0.00
c. Calculate retail_price as wholesale_cost * (1 + markup_percentage / 100).
d. Return retail_price.
4. Define a main function:
a. Initialize a while loop:
- Prompt the user to enter the wholesale cost.
- If the user enters -1, exit the loop.
- Convert the input to a float.
- If wholesale_cost is less than 0, print an error message and continue the loop.
- Prompt the user to enter the markup percentage.
- If the user enters -1, exit the loop.
- Convert the input to a float.
- If markup_percentage is less than -100, print an error message and continue the loop.
- Call the calculateRetail method with wholesale_cost and markup_percentage as arguments.
- Print the retail price with two decimal places.
5. In the main block:
a. Call the main function if the script is executed directly.
6. End.
Step by step
Solved in 4 steps with 6 images