Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Well, If I don't missunderstanding your questions, you want validate if the user only input r and c for customer type.</p> <p>So, just add another condition in your if statement.</p> <p>Try this :</p> <pre><code>public static void main(String[] args) { Scanner sc = new Scanner(System.in); String choice = "y"; while (!choice.equalsIgnoreCase("n")) { // get the input from the user System.out.print("Enter customer type (r/c): "); String customerType = sc.next(); // VALIDATE ONLY R and C customer type. if (!customerType.equalsIgnoreCase("R") &amp;&amp; !customerType.equalsIgnoreCase("C")) { sc.nextLine(); System.out.println("Error! Invalid Customer Type. Try Again "); continue; } else { System.out.print("Enter subtotal: "); double subtotal = sc.nextDouble(); // get the discount percent double discountPercent = 0; if (customerType.equalsIgnoreCase("R")) { if (subtotal &lt; 100) discountPercent = 0; else if (subtotal &gt;= 100 &amp;&amp; subtotal &lt; 250) discountPercent = .1; else if (subtotal &gt;= 250) discountPercent = .2; } else if (customerType.equalsIgnoreCase("C")) { if (subtotal &lt; 250) discountPercent = .2; else discountPercent = .3; } //else //{sc.nextLine(); //System.out.println("Error! Invalid Customer Type. Try Again "); //continue; //} //else} // { // discountPercent = .1; // } // calculate the discount amount and total double discountAmount = subtotal * discountPercent; double total = subtotal - discountAmount; // format and display the results NumberFormat currency = NumberFormat.getCurrencyInstance(); NumberFormat percent = NumberFormat.getPercentInstance(); System.out.println( "Discount percent: " + percent.format(discountPercent) + "\n" + "Discount amount: " + currency.format(discountAmount) + "\n" + "Total: " + currency.format(total) + "\n"); // see if the user wants to continue System.out.print("Continue? (y/n): "); choice = sc.next(); System.out.println(); } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload