I Need Java Code Help?

okay hers the base line program:

import java.text.NumberFormat;
import java.util.Scanner;
public class InvoiceApp
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();
System.out.print(“Enter subtotal: “);
double subtotal = sc.nextDouble();
// get the discount percent
double discountPercent = 0;
if (customerType.equalsIgnoreCase(“R”))
if (subtotal = 100 && subtotal = 250)
discountPercent = .2;
else if (customerType.equalsIgnoreCase(“C”))
if (subtotal < 250)
discountPercent = .2;
discountPercent = .3;
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();
"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();
i need to
1) modify it so it only accepts the "r" and "c" customer type codes, and it need to discard any extra entries on the customer type line. and if the user enters an invalid code, then the app should display an error message and ask the user to enter a valid code, before they enter the subtotal.
2) code a static method named "getValidCustomerType" that does the validation of step 1. the method needs one parameter that receives a "Scanner object" and it should return a valid customer type code. the method should get user input, check validity, display an error message if its invalid, and discard any other user entries whether or not the entry is valid.
3) modify the application so it uses the method
4) Add a try statement that catches any "InputMismatchException" that the "nextDouble" method of the scanner class might throw. the catch block should display an error message and issue a continue statement
to jump to the beginning of the while loop. it should also discard the invalid entry and any other entries on the line.
5) Code a static method named "getValidSubtotal" that uses the "hasDouble" method of the Scanner class to validate the subtotal entry so the "InputMisMatchException" wont occur. this method should require one parameter that recieves a Scanner object, and it should return a valid subtotal. This method should get an entry from the user, check that it is a valid double value, check that its greater than zero and less than 10000, display appropriate error mesages if it isn't valid, and discard any other user entries whether or not the entry is valid. this should continue until the method gets a valid subtotal entry.
6) Modify the code within the try statement so it uses this method.
7)modify the code so the app works right even if the user enters 2 or more valuse when asked if he wants to continue, to do that you need to discard any extra entries.
Please Help!!!!

Both comments and pings are currently closed.

Comments are closed.

Powered by WordPress | Designed by: free css template | Thanks to hostgator coupon and web hosting reviews