Advertisement
ZornTaov

calcsaletest

Oct 3rd, 2011
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.80 KB | None | 0 0
  1. // quiz. 3.12: InvoiceTest.java
  2. import java.util.Scanner;
  3.  
  4. public class CalcSaleTest
  5. {
  6.     // main method begins execution of Java application
  7.     public static void main(String[] args)
  8.     {
  9.     CalcSale invoice1 = new CalcSale("12345", "A Hammer", 2.98); // create Invoice object
  10.     CalcSale invoice2 = new CalcSale("82465", "A bag of Nails", 4.50); // create Invoice object
  11.     CalcSale invoice3 = new CalcSale("15648", "A Screwdriver", 9.98); // create Invoice object
  12.     CalcSale invoice4 = new CalcSale("98652", "A bag of Screws", 4.49); // create Invoice object
  13.     CalcSale invoice5 = new CalcSale("87659", "A Saw", 6.87); // create Invoice object
  14.  
  15.     // display information of each object
  16.     System.out.printf("Invoice 1 information: Number: %s\nDescription: %s\nPrice: $%.2f\n\n",
  17.         invoice1.getPNumber(), invoice1.getPDesc(), invoice1.getPPrice());
  18.     System.out.printf("Invoice 2 information: Number: %s\nDescription: %s\nPrice: $%.2f\n",
  19.         invoice2.getPNumber(), invoice2.getPDesc(), invoice2.getPPrice());
  20.     System.out.printf("Invoice 3 information: Number: %s\nDescription: %s\nPrice: $%.2f\n\n",
  21.         invoice3.getPNumber(), invoice3.getPDesc(), invoice3.getPPrice());
  22.     System.out.printf("Invoice 4 information: Number: %s\nDescription: %s\nPrice: $%.2f\n",
  23.         invoice4.getPNumber(), invoice4.getPDesc(), invoice4.getPPrice());
  24.     System.out.printf("Invoice 5 information: Number: %s\nDescription: %s\nPrice: $%.2f\n\n",
  25.         invoice5.getPNumber(), invoice5.getPDesc(), invoice5.getPPrice());
  26.  
  27.     // create Scanner to obtain input from command window
  28.     Scanner input = new Scanner(System.in);
  29.     int quantityAmount; // deposit amount read from user
  30.     int selection = 0; // Menu selection
  31.     while (selection != -1)
  32.     {
  33.         System.out
  34.         .println("\nEnter what you want to do:\n   1 = Change ammount of Invoice 1.\n   2 = Change ammount of Invoice 2.\n   3 = Change ammount of Invoice 3.\n   4 = Change ammount of Invoice 4.\n   5 = Change ammount of Invoice 5.\n   -1 = Print Recipt. ");
  35.         selection = input.nextInt(); // obtain user input
  36.         switch (selection)
  37.         {
  38.         case 1:
  39.         {
  40.             System.out.println("\nEnter amount wanted from Invoice 1: "); // prompt
  41.             quantityAmount = input.nextInt(); // obtain user input
  42.             if (quantityAmount < 0)
  43.             {
  44.             System.out.println("Invalid selection, returning to menu.\n");
  45.             }
  46.             else
  47.             {
  48.             System.out.printf("\nTaking %d of %s\n\n", quantityAmount,
  49.                 invoice1.getPDesc());
  50.             invoice1.setPQuantity(quantityAmount); // add to invoice1 balance
  51.  
  52.             System.out.printf("Invoice 1 balance: $%.2f\n",
  53.                 invoice1.getInvoiceQuantity());
  54.             }
  55.         }
  56.  
  57.         case 2:
  58.         {
  59.             System.out.println("\nEnter amount wanted from Invoice 2: "); // prompt
  60.             quantityAmount = input.nextInt(); // obtain user input
  61.             if (quantityAmount < 0)
  62.             {
  63.             System.out.println("Invalid selection, returning to menu.\n");
  64.             }
  65.             else
  66.             {
  67.             System.out.printf("\nTaking %d of %s\n\n", quantityAmount,
  68.                 invoice2.getPDesc());
  69.             invoice2.setPQuantity(quantityAmount); // add to invoice1 balance
  70.  
  71.             System.out.printf("Invoice 2 balance: $%.2f\n",
  72.                 invoice2.getInvoiceQuantity());
  73.             }
  74.         }
  75.         case 3:
  76.         {
  77.             System.out.println("\nEnter amount wanted from Invoice 3: "); // prompt
  78.             quantityAmount = input.nextInt(); // obtain user input
  79.             if (quantityAmount < 0)
  80.             {
  81.             System.out.println("Invalid selection, returning to menu.\n");
  82.             }
  83.             else
  84.             {
  85.             System.out.printf("\nTaking %d of %s\n\n", quantityAmount,
  86.                 invoice3.getPDesc());
  87.             invoice3.setPQuantity(quantityAmount); // add to invoice3 balance
  88.  
  89.             System.out.printf("Invoice 3 balance: $%.2f\n",
  90.                 invoice3.getInvoiceQuantity());
  91.             }
  92.         }
  93.         case 4:
  94.         {
  95.             System.out.println("\nEnter amount wanted from Invoice 4: "); // prompt
  96.             quantityAmount = input.nextInt(); // obtain user input
  97.             if (quantityAmount < 0)
  98.             {
  99.             System.out.println("Invalid selection, returning to menu.\n");
  100.             }
  101.             else
  102.             {
  103.             System.out.printf("\nTaking %d of %s\n\n", quantityAmount,
  104.                 invoice4.getPDesc());
  105.             invoice4.setPQuantity(quantityAmount); // add to invoice4 balance
  106.  
  107.             System.out.printf("Invoice 4 balance: $%.2f\n",
  108.                 invoice4.getInvoiceQuantity());
  109.             }
  110.         }
  111.  
  112.         case 5:
  113.         {
  114.             System.out.println("\nEnter amount wanted from Invoice 5: "); // prompt
  115.             quantityAmount = input.nextInt(); // obtain user input
  116.             System.out.printf("\nTaking %d of %s\n\n", quantityAmount, invoice5.getPDesc());
  117.             invoice5.setPQuantity(quantityAmount); // add to invoice5 balance
  118.             if (quantityAmount < 0)
  119.             {
  120.             System.out.println("Invalid selection, returning to menu.\n");
  121.             }
  122.             else
  123.             {
  124.             invoice5.setPQuantity(quantityAmount); // add to invoice5 balance
  125.             System.out.printf("Invoice 5 balance: $%.2f\n",
  126.                 invoice5.getInvoiceQuantity());
  127.             }
  128.         }
  129.  
  130.         case -1:
  131.         {
  132.             System.out.println("Finalizing selection...");
  133.         }
  134.         default:
  135.         {
  136.             if (selection < -1 || selection > 5)
  137.             {
  138.             System.out.println("Invalid selection, returning to menu.\n");
  139.             }
  140.         }
  141.         }
  142.     }
  143.     // display balances
  144.     System.out.printf("Invoice 1 balance: $%.2f\n", invoice1.getInvoiceQuantity());
  145.     System.out.printf("Invoice 2 balance: $%.2f\n", invoice2.getInvoiceQuantity());
  146.     System.out.printf("Invoice 3 balance: $%.2f\n", invoice3.getInvoiceQuantity());
  147.     System.out.printf("Invoice 4 balance: $%.2f\n", invoice4.getInvoiceQuantity());
  148.     System.out.printf("Invoice 5 balance: $%.2f\n", invoice5.getInvoiceQuantity());
  149.     System.out.printf(
  150.         "Final balance: $%.2f\n\n",
  151.         invoice1.getInvoiceQuantity() + invoice2.getInvoiceQuantity()
  152.         + invoice3.getInvoiceQuantity() + invoice4.getInvoiceQuantity()
  153.         + invoice5.getInvoiceQuantity());
  154.     } // end main
  155. } // end class InvoiceTest
  156.  
  157.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement