Colindapieman

Step 4

Feb 11th, 2015
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.18 KB | None | 0 0
  1. import java.text.NumberFormat;
  2. import java.util.Scanner;
  3.  
  4.  
  5.  
  6. public class InvoiceApp
  7.  
  8. {
  9.  
  10.     public static void main(String[] args)
  11.  
  12.     {
  13.  
  14.                 Scanner sc = new Scanner(System.in);
  15.  
  16.                 String choice = "y";
  17.  
  18.  
  19.  
  20.                 while (!choice.equalsIgnoreCase("n"))
  21.  
  22.  
  23.                 {
  24.  
  25.                     // get the input from the user
  26.  
  27.                     System.out.print("Enter customer type (r/c/t): ");
  28.  
  29.                     String customerType = sc.next();
  30.                              
  31.  
  32.                     System.out.print("Enter subtotal:   ");
  33.  
  34.                     double subtotal = sc.nextDouble();
  35.  
  36.  
  37.  
  38.                     // get the discount percent
  39.  
  40.                     double discountPercent = 0;
  41.  
  42.                     if (customerType.equalsIgnoreCase("R"))
  43.  
  44.                     {
  45.  
  46.                         if (subtotal < 100)
  47.  
  48.                             discountPercent = 0;
  49.  
  50.                         else if (subtotal >= 100 && subtotal < 250)
  51.  
  52.                             discountPercent = .1;
  53.  
  54.                         else if (subtotal >= 250 && subtotal <500)
  55.  
  56.                             discountPercent = .25;
  57.                        
  58.                         else if (subtotal >= 500)
  59.  
  60.                             discountPercent = .3;
  61.  
  62.                     }
  63.  
  64.                     else if (customerType.equalsIgnoreCase("C"))
  65.  
  66.                     {        
  67.  
  68.                             discountPercent = .2;                
  69.  
  70.                     }
  71.                  
  72.                     else if (customerType.equalsIgnoreCase("T"))
  73.  
  74.                     {        
  75.                                 if (subtotal <500){
  76.                                         discountPercent = .4;
  77.                                 }
  78.                                 else{
  79.                                         discountPercent = .5;
  80.                                 }
  81.                                            
  82.  
  83.                     }
  84.  
  85.                     else{
  86.  
  87.                         System.out.println("That is not a valid customer type.");
  88.            
  89.                     }
  90.  
  91.  
  92.  
  93.                     // calculate the discount amount and total
  94.  
  95.                     double discountAmount = subtotal * discountPercent;
  96.  
  97.                     double total = subtotal - discountAmount;
  98.  
  99.  
  100.  
  101.                     // format and display the results
  102.  
  103.                     NumberFormat currency = NumberFormat.getCurrencyInstance();
  104.  
  105.                     NumberFormat percent = NumberFormat.getPercentInstance();
  106.                  
  107.  
  108.                     System.out.println(
  109.  
  110.                         "Discount percent: " + percent.format(discountPercent) + "\n" +
  111.  
  112.                         "Discount amount:  " + currency.format(discountAmount) + "\n" +
  113.  
  114.                         "Total:            " + currency.format(total) + "\n");
  115.  
  116.  
  117.  
  118.                     // see if the user wants to continue
  119.  
  120.                     System.out.print("Continue? (y/n): ");
  121.  
  122.                     choice = sc.next();
  123.  
  124.                     System.out.println();
  125.  
  126.                 }
  127.  
  128.     }
  129.  
  130. }
Advertisement
Add Comment
Please, Sign In to add comment