Write a program in Java which would ask for the clerk to enter the total amount
ID: 3861039 • Letter: W
Question
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.”
Explanation / Answer
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.Scanner;
public class Clerck {
public static void main(String args[]) throws FileNotFoundException
{
Scanner sc=new Scanner(System.in);
int i=0;
float[] order=new float[5];
//writing the every output to output.txt file
PrintStream out = new PrintStream(new FileOutputStream("order.txt"));
PrintStream stdout = System.out;
System.setOut(out);
while(i<5)
{
System.out.println("Enter "+(i+1)+"st order amount");
order[i]=sc.nextFloat();
System.out.println("order amount"+order[i]);
System.out.println("tax amount"+tax(order[i]));
System.out.println("amount including tax"+(order[i]+tax(order[i])));
System.out.println("comission amount"+comission(order[i]));
i++;
}
System.out.println("average and sum of orders"+sum(order)+","+(sum(order)/5));
out.close();
System.setOut(stdout);
//setting output back to console
System.out.println("Thanks for the business");
}
//method to caluclate tax
static float tax(float order)
{
float tax;
tax=((order*7)/100);
return tax;
}
//method to caluclate comission
static float comission(float order)
{
if(order<=200)
return ((order*2)/100);
else if(order>200&&order<=400)
return ((order*3)/100);
else if(order>400&&order<=600)
return ((order*4)/100);
else
return ((order*5)/100);
}
//method to sum up array
static float sum(float[] order)
{
float sum=0;
for(int i=0;i<5;i++)
{
sum=sum+order[i];
}
return sum;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.