Java Program    PLEASE FIX AND MODIFY THIS JAVA SO WHEN I UPLOAD IT TO HYPERGRADE IT PASSES ALL TEST CASSES PLEASES. RIGHT NOW IT SAYS 0 OUT 5 PASSED. THE PICTURES THAT I PROVIDED PROOF THAT WHEN I UPLOAD IT TO HYPERGRADES IT FAILS TEST CASSES. THANK YOU   import java.util.Scanner; public class RetailPriceCalculator {     public static double calculateRetail(double wholesale, double percentage) {         double retailPrice = wholesale + wholesale * (percentage / 100);         return retailPrice;     }     public static void main(String[] args) {         Scanner sc = new Scanner(System.in);         double wholesale = 0;         double percentage = 0;         // To check if it is the first or second input error         int n = 0;         boolean wholeSale = true;         boolean percent = true;         boolean condition = true;         while (condition) {             while (wholeSale) { // loop to prevent invalid input for wholesale                 if (n == 0) {                     System.out.println("Please enter the wholesale cost or -1 to exit: ");                 } else {                     System.out.println("Please enter the wholesale cost again or -1 to exit: ");                     n = 0;                 }                 wholesale = sc.nextDouble();                 if (wholesale == -1) {                     condition = false; // Exit the loop                     break;                 } else if (wholesale < 0) {                     System.out.println("Wholesale cost cannot be a negative value.");                     n = 1; // Set the flag to indicate a second input error                     continue; // Continue to prompt for input                 }                 wholeSale = false; // Valid input received, exit the inner loop             }             if (condition == false) {                 break; // Exit the outer loop             }             while (percent) { // loop to prevent invalid input for markup percentage                 if (n == 0) {                     System.out.println("Please enter the markup percentage or -1 to exit: ");                 } else {                     System.out.println("Please enter the markup again or -1 to exit: ");                     n = 0;                 }                 percentage = sc.nextDouble();                 if (percentage == -1) {                     condition = false; // Exit the loop                     break;                 } else if (percentage < -100) {                     System.out.println("Markup cannot be less than -100%.");                     n = 1; // Set the flag to indicate a second input error                     continue; // Continue to prompt for input                 }                 percent = false; // Valid input received, exit the inner loop             }             if (condition == false) {                 break; // Exit the outer loop             }             // Reset the flags for the next input             wholeSale = true;             percent = true;             // Calculate and display the retial price of the item             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

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

 
 PLEASE FIX AND MODIFY THIS JAVA SO WHEN I UPLOAD IT TO HYPERGRADE IT PASSES ALL TEST CASSES PLEASES. RIGHT NOW IT SAYS 0 OUT 5 PASSED. THE PICTURES THAT I PROVIDED PROOF THAT WHEN I UPLOAD IT TO HYPERGRADES IT FAILS TEST CASSES. THANK YOU
 

import java.util.Scanner;

public class RetailPriceCalculator {
    public static double calculateRetail(double wholesale, double percentage) {
        double retailPrice = wholesale + wholesale * (percentage / 100);
        return retailPrice;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double wholesale = 0;
        double percentage = 0;
        // To check if it is the first or second input error
        int n = 0;
        boolean wholeSale = true;
        boolean percent = true;
        boolean condition = true;

        while (condition) {
            while (wholeSale) { // loop to prevent invalid input for wholesale
                if (n == 0) {
                    System.out.println("Please enter the wholesale cost or -1 to exit: ");
                } else {
                    System.out.println("Please enter the wholesale cost again or -1 to exit: ");
                    n = 0;
                }
                wholesale = sc.nextDouble();

                if (wholesale == -1) {
                    condition = false; // Exit the loop
                    break;
                } else if (wholesale < 0) {
                    System.out.println("Wholesale cost cannot be a negative value.");
                    n = 1; // Set the flag to indicate a second input error
                    continue; // Continue to prompt for input
                }
                wholeSale = false; // Valid input received, exit the inner loop
            }
            if (condition == false) {
                break; // Exit the outer loop
            }

            while (percent) { // loop to prevent invalid input for markup percentage
                if (n == 0) {
                    System.out.println("Please enter the markup percentage or -1 to exit: ");
                } else {
                    System.out.println("Please enter the markup again or -1 to exit: ");
                    n = 0;
                }

                percentage = sc.nextDouble();

                if (percentage == -1) {
                    condition = false; // Exit the loop
                    break;
                } else if (percentage < -100) {
                    System.out.println("Markup cannot be less than -100%.");
                    n = 1; // Set the flag to indicate a second input error
                    continue; // Continue to prompt for input
                }
                percent = false; // Valid input received, exit the inner loop
            }
            if (condition == false) {
                break; // Exit the outer loop
            }
            // Reset the flags for the next input
            wholeSale = true;
            percent = true;

            // Calculate and display the retial price of the item
            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
10ENTER
Please enter the markup percentage or -1 exit:\n
50ENTER
The retail price is: 15.00\n
Please enter the wholesale cost or -1 exit:\n
10ENTER
Please enter the markup percentage or -1 exit:\n
100ENTER
The retail price is: 20.00\n
Please enter the wholesale cost or -1 exit:\n
10ENTER
Please enter the markup percentage or -1 exit:\n
-100ENTER
The retail price is: 0.00\n
Please enter the wholesale cost or -1 exit:\n
-1ENTER
 

Test Case 4

 
 
Please enter the wholesale cost or -1 exit:\n
-200ENTER
Wholesale cost cannot be a negative value.\n
Please enter the wholesale cost again or -1 exit:\n
10ENTER
Please enter the markup percentage or -1 exit:\n
-200ENTER
Markup cannot be less than -100%.\n
Please enter the markup again or -1 exit:\n
50ENTER
The retail price is: 15.00\n
Please enter the wholesale cost or -1 exit:\n
-1ENTER
 

Test Case 5

 
 
Please enter the wholesale cost or -1 exit:\n
-1ENTER
 
 
 
 
 
 
 
 
 
Test Case 3 Failed Show what's missing
Please enter the wholesale cost or -1 to exit: |\n|
10 ENTER
Please enter the markup percentage or -1 to exit: \n
50 ENTER
The retail price is: 15.00 \n
Please enter the wholesale cost or -1 to exit:
10 ENTER
Please enter the markup percentage or -1 to exit: \n
100 ENTER
The retail price is: 20.00 \n
Please enter the wholesale cost or -1 to exit: \n
10 ENTER
Please enter the markup percentage or -1 to exit: \n
-100 ENTER
The retail price is: 0.00 \n
Please enter the wholesale cost or -1 to exit:
-1 ENTER
|\n
|\n
Transcribed Image Text:Test Case 3 Failed Show what's missing Please enter the wholesale cost or -1 to exit: |\n| 10 ENTER Please enter the markup percentage or -1 to exit: \n 50 ENTER The retail price is: 15.00 \n Please enter the wholesale cost or -1 to exit: 10 ENTER Please enter the markup percentage or -1 to exit: \n 100 ENTER The retail price is: 20.00 \n Please enter the wholesale cost or -1 to exit: \n 10 ENTER Please enter the markup percentage or -1 to exit: \n -100 ENTER The retail price is: 0.00 \n Please enter the wholesale cost or -1 to exit: -1 ENTER |\n |\n
Test Case 1 Failed Show what's missing
Please enter the wholesale cost or -1 to exit: \n
10 ENTER
Please enter the markup percentage or -1 to exit: \n
-1 ENTER
Test Case 2 Failed Show what's missing
Please enter the wholesale cost or -1 to exit: \n
100 ENTER
Please enter the markup percentage or -1 to exit: \n
100 ENTER
The retail price is: 200.00 \n
Please enter the wholesale cost or -1 to exit:
-1 ENTER
Transcribed Image Text:Test Case 1 Failed Show what's missing Please enter the wholesale cost or -1 to exit: \n 10 ENTER Please enter the markup percentage or -1 to exit: \n -1 ENTER Test Case 2 Failed Show what's missing Please enter the wholesale cost or -1 to exit: \n 100 ENTER Please enter the markup percentage or -1 to exit: \n 100 ENTER The retail price is: 200.00 \n Please enter the wholesale cost or -1 to exit: -1 ENTER
Expert Solution
Step 1: Introduction

The previous codе is a Java program to calculatе thе rеtail pricе of an itеm. The program has two mеthods:

Thе calculatеRеtail() calculatеs thе rеtail pricе of an itеm givеn thе wholеsalе cost and thе markup pеrcеntagе.

Thе main() mеthod prompts thе usеr for thе wholеsalе cost and thе markup pеrcеntagе, and thеn calls thе calculateRеtail() mеthod to calculatе thе rеtail pricе.

The previous codе had two problems:

Thе calculatеRеtail() mеthod doеs do not throw an еxcеption if thе markup pеrcеntagе is lеss than -100. This means that thе program will not tеrminatе if thе usеr еntеrs a nеgativе markup pеrcеntagе.

Thе main() mеthod doеs not kееp prompting thе usеr for input until thеy еntеr a valid wholеsalе cost and markup pеrcеntagе. This mеans that thе program will tеrminatе if thе usеr еntеrs an invalid input for еithеr thе wholеsalе cost or thе markup pеrcеntagе. 

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Random Class and its operations
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