Colindapieman

Step 6

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