Question
Your instructor would like you to write a program in Java which would ask for the clerk to enter …
Your instructor would like you to write a program in Java which
would ask for the clerk to enter the total amount of the customer’s
order. The program will then calculate a seven percent (7%) sales
tax. Commission is computed based on the following: order amount
id="mce_marker" – $200 commission is 2%, order amount $201 – $400
commission is 3%, order amount $401 – $600 commission is 4%, order
amount > $600 commission is 5%, The program will display the
following: a) The amount of customer’s order (eg. $500.00 or
id="mce_marker",000.00) b) The tax amount c) The total amount
including tax added d) Commission Amount e) The customer will make
five orders, display the average of the total order and the sum of
all orders. You must use at least two methods. Write the output to
a file named “Order.txt” The program should also display “Thanks
for your business and please come again.” Output The amount of
Customer’s order $XXX, XXX.XX The tax amount is: $XXX,XXX.XX The
total Amount plus Tax is $XXX,XXX.XX Average order is $XXX,XXX,XX
Sum of the order is $XXX,XXX.XX
Java only Thanks
Solutions
Expert Solution
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
/*CustomerOrder class */
public class CustomerOrder {
/* Definition of main method */
public static void main(String args[]) throws
IOException {
double
amt,salesTax,commission,totalOrderAmt=0;
int i=0;
String formatted;
FileWriter fw=new
FileWriter("Order.txt"); //attaching
a file to filewriter
//Loop will run 5 times to enter
the customer order amount
while(i < 5) {
i++;
System.out.print("\nEnter customer order: ");
Scanner sc = new Scanner(System.in);
amt = sc.nextDouble();
totalOrderAmt += amt;
salesTax = amt * 0.07;
commission = calculateCommission(amt);
System.out.printf("The amount of customer's order:
$%.2f\n",amt);
System.out.printf("The tax amount: $%.2f\n" ,salesTax);
System.out.printf("The total amount including tax added:
$%.2f\n",(amt + salesTax));
System.out.printf("Commission amount: $%.2f\n",commission);
formatted =
String.format("The amount of customer's order: $%.2f\n",amt);
fw.write(formatted);
formatted =
String.format("The tax amount: $%.2f\n" ,salesTax);
fw.write(formatted);
formatted =
String.format("The total amount including tax added: $%.2f\n",(amt
+ salesTax));
fw.write(formatted);
formatted =
String.format("Commission amount: $%.2f\n\n",commission);
fw.write(formatted);
}
System.out.printf("\n\n\nThe sum of all orders:
$%.2f\n",totalOrderAmt);
System.out.printf("The
average of the total order: $%.2f\n",totalOrderAmt/5);
formatted =
String.format("\n\n\nThe sum of all orders:
$%.2f\n",totalOrderAmt);
fw.write(formatted);
formatted =
String.format("The average of the total order:
$%.2f\n",totalOrderAmt/5);
fw.write(formatted);
System.out.println("\nThanks for your business and please come
again.");
fw.write("\nThanks for
your business and please come again.");
fw.close();
}
/* Function definition to calculate commission*/
public static double calculateCommission(double
amt) {
if(amt <= 200)
return amt * 0.02;
else if(amt > 200
&& amt <= 400)
return amt * 0.03;
else if(amt > 400
&& amt <= 600)
return amt * 0.04;
else
return amt * 0.05;
}
}
SCREEN SHOTS: