The file is here: https://dl.dropbox.com/u/31003446/InvoiceApp.java In this exer
ID: 3529388 • Letter: T
Question
The file is here: https://dl.dropbox.com/u/31003446/InvoiceApp.java
Explanation / Answer
This is the code for your que..Check it out...sry for late answering
Code
import java.text.NumberFormat;
import java.util.InputMismatchException;
import java.util.Scanner;
public class InvoiceApp
{
public static double getValidSubTotal(Scanner sc)
{
sc=new Scanner(System.in);
double subtotal=0;
try
{
subtotal=sc.nextDouble();
}
catch(InputMismatchException e)
{
System.out.println("Please enter a valid Number");
System.out.println(subtotal);
subtotal=-1;
}
return subtotal;
}
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
String choice = "y";
do
{
String customerType="";
// get the input from the user
do{
System.out.print("Enter customer type (r/c): ");
customerType = sc.next();
if(customerType.length() >= 1)
{
customerType=customerType.substring(0,1);
}
if(! (customerType.equalsIgnoreCase("r") || customerType.equalsIgnoreCase("c")))
{
System.out.println("please enter a valid customer Type");
}
}while(! (customerType.equalsIgnoreCase("r") || customerType.equalsIgnoreCase("c")));
double subtotal=0;
do{
System.out.print("Enter subtotal: ");
subtotal= getValidSubTotal(sc);
}while(subtotal < 0);
// get the discount percent
double discountPercent = 0;
if (customerType.equalsIgnoreCase("R"))
{
if (subtotal < 100)
discountPercent = 0;
else if (subtotal >= 100 && subtotal < 250)
discountPercent = .1;
else if (subtotal >= 250)
discountPercent = .2;
}
else if (customerType.equalsIgnoreCase("C"))
{
if (subtotal < 250)
discountPercent = .2;
else
discountPercent = .3;
}
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) + " " +
"Discount amount: " + currency.format(discountAmount) + " " +
"Total: " + currency.format(total) + " ");
// see if the user wants to continue
System.out.print("Continue? (y/n): ");
choice = sc.next();
if(choice.length()>=1)
{
choice=choice.substring(0,1);
}
System.out.println();
}
while(choice.equalsIgnoreCase("Y"));
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.