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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

 JAVA PROGRAM

Chapter 5. PC #2. Retail Price Calculator (page 312)
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

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

 
 
Please enter the wholesale cost or -1 exit:\n
10ENTER
Please enter the markup percentage or -1 exit:\n
-1ENTER
 

Test Case 2

 
 
Please enter the wholesale cost or -1 exit:\n
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
 
 
 
Test Case 3
Please enter the wholesale cost or -1 exit: \n
10 ENTER
Please enter the markup percentage or -1 exit: \n
50 ENTER
The retail price is: 15.00 \n
Please enter the wholesale cost or -1 exit: \n
10 ENTER
Please enter the markup percentage or -1 exit: \n
100 ENTER
The retail price is: 20.00 \n
Please enter the wholesale cost or -1 exit: \n
10 ENTER
Please enter the markup percentage or −1 exit: \n
-100 ENTER
The retail price is: 0.00 \n
Please enter the wholesale cost or -1 exit: \n
-1 ENTER
Transcribed Image Text:Test Case 3 Please enter the wholesale cost or -1 exit: \n 10 ENTER Please enter the markup percentage or -1 exit: \n 50 ENTER The retail price is: 15.00 \n Please enter the wholesale cost or -1 exit: \n 10 ENTER Please enter the markup percentage or -1 exit: \n 100 ENTER The retail price is: 20.00 \n Please enter the wholesale cost or -1 exit: \n 10 ENTER Please enter the markup percentage or −1 exit: \n -100 ENTER The retail price is: 0.00 \n Please enter the wholesale cost or -1 exit: \n -1 ENTER
Test Case 4
Please enter the wholesale cost or -1 exit: \n
-200 ENTER
Wholesale cost cannot be a negative value.\n
Please enter the wholesale cost again or -1 exit: \n
10 ENTER
Please enter the markup percentage or -1 exit: \n
-200 ENTER
Markup cannot be less than -100%. \n
Please enter the markup again or -1 exit: \n
50 ENTER
The retail price is: 15.00 \n
Please enter the wholesale cost or -1 exit: \n
-1 ENTER
Test Case 5
Please enter the wholesale cost or -1 exit: \n
-1 ENTER
Transcribed Image Text:Test Case 4 Please enter the wholesale cost or -1 exit: \n -200 ENTER Wholesale cost cannot be a negative value.\n Please enter the wholesale cost again or -1 exit: \n 10 ENTER Please enter the markup percentage or -1 exit: \n -200 ENTER Markup cannot be less than -100%. \n Please enter the markup again or -1 exit: \n 50 ENTER The retail price is: 15.00 \n Please enter the wholesale cost or -1 exit: \n -1 ENTER Test Case 5 Please enter the wholesale cost or -1 exit: \n -1 ENTER
Expert Solution
Step 1: Algorithm :

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.


steps

Step by step

Solved in 4 steps with 6 images

Blurred answer
Knowledge Booster
Events
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education