Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Tax_Package;
- import java.util.ArrayList;
- import java.util.Scanner;
- import javax.swing.JOptionPane;
- public class Tax_Calculator {
- public void begin() {
- // create the Game ArrayList to store the data while the program is running
- ArrayList<Customer> Customerus = new ArrayList<Customer>();
- // display the menu and process PC Game & Board Game data
- boolean finished = false;
- while(!finished) {
- // a loop to allow the program to continue until the user chooses to exit program
- int selection = showMenu();
- switch(selection) {
- case 1: Customerus.add(addBusiness_Customer()); // add a PC Game
- break;
- case 2: Customerus.add(addBoardGame()); // add a Board Game
- break;
- case 3: JOptionPane.showMessageDialog(null, "Displaying the game information...", "Game List",
- JOptionPane.PLAIN_MESSAGE); // display the Game data
- for(int i = 0; i < Customerus.size(); i++) {
- JOptionPane.showMessageDialog(null, Customerus.get(i), "Game Details", JOptionPane.PLAIN_MESSAGE);
- }
- JOptionPane.showMessageDialog(null, "There are " + Customerus.size() + " record(s) in the list", "Totalrecords", JOptionPane.PLAIN_MESSAGE);
- break;
- case 4: finished = true; // the boolean variable 'finished' is used to control the loop
- JOptionPane.showMessageDialog(null, "*** Program Ended ***\n" + "*** Thank you for using this program");
- break;
- default:
- JOptionPane.showMessageDialog(null, "\n*** Invalid Selection ***\n", "ERROR",
- JOptionPane.ERROR_MESSAGE);
- } //end switch
- } //end while loop
- } //end begin()
- // showMenu() β Userβs program selection menu
- public int showMenu() {
- int selection = 0;
- String stringSelection = JOptionPane.showInputDialog(
- "******MENU******\n\n"+
- "1. Add a new PC Game\n"+
- "2. Add a new Board Game\n"+
- "3. Display all games\n"+
- "4. Exit program\n"+
- "Type in the number of your selection and click OK: ");
- selection = Integer.parseInt(stringSelection.trim());
- return selection;
- } //end menu
- // addBusiness_Customer()β Method to collect Business_Customer data
- public Business_Customer addTax() {
- String userInput = JOptionPane.showInputDialog(null, "\nWhat is your name?: ").trim();
- int taxFn = 0;
- int finYear = 0;
- do {
- String taxFnq = JOptionPane.showInputDialog(null, "\nWhat is your tax file number?: ").trim();
- double doubletax = Double.parseDouble(taxFnq);
- taxFn = (int) doubletax;
- if (taxFn<= 0) {
- JOptionPane.showMessageDialog(null, "Error -Please enter a valid Tax file number1", "ERROR",
- JOptionPane.ERROR_MESSAGE);
- }
- } while (taxFn <=0);
- do {
- String finYearq = JOptionPane.showInputDialog(null, "\nWhat is the financial year: ").trim();
- double doubleyear = Double.parseDouble(finYearq);
- taxFn = (int) doubleyear;
- if (finYear<= 0) {
- JOptionPane.showMessageDialog(null, "Error -Please enter a valid financial year", "ERROR",
- JOptionPane.ERROR_MESSAGE);
- }
- } while (finYear <=0);
- //String Cust = JOptionPane.showInputDialog(null, "\nWhat is the game key?");
- //String gRating = JOptionPane.showInputDialog(null, "\nMaturity rating of the game?");
- // String gName = JOptionPane.showInputDialog(null, "\nName of store where available?");
- //String gLocation = JOptionPane.showInputDialog(null, "\nWhere is the store located?");
- Tax ai = new Tax(gName, gLocation); //create a new Tax object
- Business_Customer p = new Business_Customer(n, c, (int) taxFn, ga, gGameKey, gRating); //create new Business_Customer object
- JOptionPane.showMessageDialog(null, "Thank you, PC Game added to the list", "PC Game added", JOptionPane.PLAIN_MESSAGE);
- return p;
- } //end addBusiness_Customer
- //addBoardGame() - Method to collect BoardGame data
- public BoardGame addBoardGame() {
- String n = JOptionPane.showInputDialog(null, "\nWhat is the name of the game? ").trim();
- String c = JOptionPane.showInputDialog(null, "\nWhat is the category of the game? ");
- int taxFn = 0;
- do {
- String p = JOptionPane.showInputDialog(null, "\nWhat is the taxFn of the game? ").trim();
- double doubleSize = Double.parseDouble(p);
- taxFn = (int) doubleSize;
- if (taxFn<= 0) {
- JOptionPane.showMessageDialog(null, "Error -taxFn must be greater than zero", "ERROR",
- JOptionPane.ERROR_MESSAGE);
- }
- } while (taxFn <=0);
- String gHasPlayers = JOptionPane.showInputDialog(null, "\nDoes it have players?");
- String gBrand = JOptionPane.showInputDialog(null, "\nWhat is the brand?");
- String gName = JOptionPane.showInputDialog(null, "\nName of store where available?");
- String gLocation = JOptionPane.showInputDialog(null, "\nWhere is the store located?");
- Tax ai = new GameShop(gName, gLocation); //create a new GameShop object
- BoardGame bg = new BoardGame(n, c, (int) taxFn, ga, gBrand, gHasPlayers); //create new Business_Customer object
- JOptionPane.showMessageDialog(null, "Thank you, Board Games added to the list", "Board Game added", JOptionPane.PLAIN_MESSAGE);
- return bg;
- }
- } //end addBoardGame()
- //end UserInterface class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement