Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // quiz. 3.12: InvoiceTest.java
- import java.util.Scanner;
- public class CalcSaleTest
- {
- // main method begins execution of Java application
- public static void main(String[] args)
- {
- CalcSale invoice1 = new CalcSale("12345", "A Hammer", 2.98); // create Invoice object
- CalcSale invoice2 = new CalcSale("82465", "A bag of Nails", 4.50); // create Invoice object
- CalcSale invoice3 = new CalcSale("15648", "A Screwdriver", 9.98); // create Invoice object
- CalcSale invoice4 = new CalcSale("98652", "A bag of Screws", 4.49); // create Invoice object
- CalcSale invoice5 = new CalcSale("87659", "A Saw", 6.87); // create Invoice object
- // display information of each object
- System.out.printf("Invoice 1 information: Number: %s\nDescription: %s\nPrice: $%.2f\n\n",
- invoice1.getPNumber(), invoice1.getPDesc(), invoice1.getPPrice());
- System.out.printf("Invoice 2 information: Number: %s\nDescription: %s\nPrice: $%.2f\n",
- invoice2.getPNumber(), invoice2.getPDesc(), invoice2.getPPrice());
- System.out.printf("Invoice 3 information: Number: %s\nDescription: %s\nPrice: $%.2f\n\n",
- invoice3.getPNumber(), invoice3.getPDesc(), invoice3.getPPrice());
- System.out.printf("Invoice 4 information: Number: %s\nDescription: %s\nPrice: $%.2f\n",
- invoice4.getPNumber(), invoice4.getPDesc(), invoice4.getPPrice());
- System.out.printf("Invoice 5 information: Number: %s\nDescription: %s\nPrice: $%.2f\n\n",
- invoice5.getPNumber(), invoice5.getPDesc(), invoice5.getPPrice());
- // create Scanner to obtain input from command window
- Scanner input = new Scanner(System.in);
- int quantityAmount; // deposit amount read from user
- int selection = 0; // Menu selection
- while (selection != -1)
- {
- System.out
- .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. ");
- selection = input.nextInt(); // obtain user input
- switch (selection)
- {
- case 1:
- {
- System.out.println("\nEnter amount wanted from Invoice 1: "); // prompt
- quantityAmount = input.nextInt(); // obtain user input
- if (quantityAmount < 0)
- {
- System.out.println("Invalid selection, returning to menu.\n");
- }
- else
- {
- System.out.printf("\nTaking %d of %s\n\n", quantityAmount,
- invoice1.getPDesc());
- invoice1.setPQuantity(quantityAmount); // add to invoice1 balance
- System.out.printf("Invoice 1 balance: $%.2f\n",
- invoice1.getInvoiceQuantity());
- }
- }
- case 2:
- {
- System.out.println("\nEnter amount wanted from Invoice 2: "); // prompt
- quantityAmount = input.nextInt(); // obtain user input
- if (quantityAmount < 0)
- {
- System.out.println("Invalid selection, returning to menu.\n");
- }
- else
- {
- System.out.printf("\nTaking %d of %s\n\n", quantityAmount,
- invoice2.getPDesc());
- invoice2.setPQuantity(quantityAmount); // add to invoice1 balance
- System.out.printf("Invoice 2 balance: $%.2f\n",
- invoice2.getInvoiceQuantity());
- }
- }
- case 3:
- {
- System.out.println("\nEnter amount wanted from Invoice 3: "); // prompt
- quantityAmount = input.nextInt(); // obtain user input
- if (quantityAmount < 0)
- {
- System.out.println("Invalid selection, returning to menu.\n");
- }
- else
- {
- System.out.printf("\nTaking %d of %s\n\n", quantityAmount,
- invoice3.getPDesc());
- invoice3.setPQuantity(quantityAmount); // add to invoice3 balance
- System.out.printf("Invoice 3 balance: $%.2f\n",
- invoice3.getInvoiceQuantity());
- }
- }
- case 4:
- {
- System.out.println("\nEnter amount wanted from Invoice 4: "); // prompt
- quantityAmount = input.nextInt(); // obtain user input
- if (quantityAmount < 0)
- {
- System.out.println("Invalid selection, returning to menu.\n");
- }
- else
- {
- System.out.printf("\nTaking %d of %s\n\n", quantityAmount,
- invoice4.getPDesc());
- invoice4.setPQuantity(quantityAmount); // add to invoice4 balance
- System.out.printf("Invoice 4 balance: $%.2f\n",
- invoice4.getInvoiceQuantity());
- }
- }
- case 5:
- {
- System.out.println("\nEnter amount wanted from Invoice 5: "); // prompt
- quantityAmount = input.nextInt(); // obtain user input
- System.out.printf("\nTaking %d of %s\n\n", quantityAmount, invoice5.getPDesc());
- invoice5.setPQuantity(quantityAmount); // add to invoice5 balance
- if (quantityAmount < 0)
- {
- System.out.println("Invalid selection, returning to menu.\n");
- }
- else
- {
- invoice5.setPQuantity(quantityAmount); // add to invoice5 balance
- System.out.printf("Invoice 5 balance: $%.2f\n",
- invoice5.getInvoiceQuantity());
- }
- }
- case -1:
- {
- System.out.println("Finalizing selection...");
- }
- default:
- {
- if (selection < -1 || selection > 5)
- {
- System.out.println("Invalid selection, returning to menu.\n");
- }
- }
- }
- }
- // display balances
- System.out.printf("Invoice 1 balance: $%.2f\n", invoice1.getInvoiceQuantity());
- System.out.printf("Invoice 2 balance: $%.2f\n", invoice2.getInvoiceQuantity());
- System.out.printf("Invoice 3 balance: $%.2f\n", invoice3.getInvoiceQuantity());
- System.out.printf("Invoice 4 balance: $%.2f\n", invoice4.getInvoiceQuantity());
- System.out.printf("Invoice 5 balance: $%.2f\n", invoice5.getInvoiceQuantity());
- System.out.printf(
- "Final balance: $%.2f\n\n",
- invoice1.getInvoiceQuantity() + invoice2.getInvoiceQuantity()
- + invoice3.getInvoiceQuantity() + invoice4.getInvoiceQuantity()
- + invoice5.getInvoiceQuantity());
- } // end main
- } // end class InvoiceTest
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement