Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package javaapplication1;
- import javax.swing.JOptionPane;
- public class JavaApplication1 {
- public static int i = 1;
- public static int stockIphone = 10;
- public static int stockSamsung = 8;
- public static int stockHuawei = 10;
- public static int stockOnePlus = 5;
- public static void main(String[] args) {
- for(i = 1; i <= 10; i++){
- String[] ticketButtons = {"Iphone 11 - $1500", "Samsung S10 - $800", "Huawei P30 Pro - $850", "One Plus 7 Pro - $650", "Skip"};
- int phoneType = JOptionPane.showOptionDialog(null, "Please select the phone you would like to purchase: ", "phone selection",
- JOptionPane.WARNING_MESSAGE, 0, null, ticketButtons, ticketButtons[2]);
- int warning = warningMessage("");
- if(phoneType==0){
- if(stockIphone == 10){
- String[] phoneButtons = {"Cancel", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"};
- int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
- JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
- stockIphone -= phoneAmount;
- iPhone11(phoneAmount);
- }
- else if(stockIphone == 9){
- String[] phoneButtons = {"Cancel", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
- int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
- JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
- stockIphone -= phoneAmount;
- iPhone11(phoneAmount);
- }
- else if(stockIphone == 8){
- String[] phoneButtons = {"Cancel", "1", "2", "3", "4", "5", "6", "7", "8"};
- int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
- JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
- stockIphone -= phoneAmount;
- iPhone11(phoneAmount);
- }
- else if(stockIphone == 7){
- String[] phoneButtons = {"Cancel", "1", "2", "3", "4", "5", "6", "7"};
- int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
- JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
- stockIphone -= phoneAmount;
- iPhone11(phoneAmount);
- }
- else if(stockIphone == 6){
- String[] phoneButtons = {"Cancel", "1", "2", "3", "4", "5", "6"};
- int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
- JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
- stockIphone -= phoneAmount;
- iPhone11(phoneAmount);
- }
- else if(stockIphone == 5){
- String[] phoneButtons = {"Cancel", "1", "2", "3", "4", "5"};
- int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
- JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
- stockIphone -= phoneAmount;
- iPhone11(phoneAmount);
- }
- else if(stockIphone == 4){
- String[] phoneButtons = {"Cancel", "1", "2", "3", "4"};
- int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
- JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
- stockIphone -= phoneAmount;
- iPhone11(phoneAmount);
- }
- else if(stockIphone == 3){
- String[] phoneButtons = {"Cancel", "1", "2", "3"};
- int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
- JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
- stockIphone -= phoneAmount;
- iPhone11(phoneAmount);
- }
- else if(stockIphone == 2){
- String[] phoneButtons = {"Cancel", "1", "2"};
- int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
- JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
- stockIphone -= phoneAmount;
- iPhone11(phoneAmount);
- }
- else if(stockIphone == 1){
- String[] phoneButtons = {"Cancel", "1"};
- int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
- JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
- stockIphone -= phoneAmount;
- iPhone11(phoneAmount);
- }
- else if(stockIphone == 0){
- JOptionPane.showMessageDialog(null, "No More Iphone 11's remaining");
- }
- }
- else if(phoneType==1){
- if(stockSamsung == 10){
- String[] phoneButtons = {"Cancel", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"};
- int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
- JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
- stockSamsung -= phoneAmount;
- SamsungS10(phoneAmount);
- }
- else if(stockSamsung == 9){
- String[] phoneButtons = {"Cancel", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
- int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
- JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
- stockSamsung -= phoneAmount;
- SamsungS10(phoneAmount);
- }
- else if(stockSamsung == 8){
- String[] phoneButtons = {"Cancel", "1", "2", "3", "4", "5", "6", "7", "8"};
- int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
- JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
- stockSamsung -= phoneAmount;
- SamsungS10(phoneAmount);
- }
- else if(stockSamsung == 7){
- String[] phoneButtons = {"Cancel", "1", "2", "3", "4", "5", "6", "7"};
- int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
- JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
- stockSamsung -= phoneAmount;
- SamsungS10(phoneAmount);
- }
- else if(stockSamsung == 6){
- String[] phoneButtons = {"Cancel", "1", "2", "3", "4", "5", "6"};
- int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
- JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
- stockSamsung -= phoneAmount;
- SamsungS10(phoneAmount);
- }
- else if(stockSamsung == 5){
- String[] phoneButtons = {"Cancel", "1", "2", "3", "4", "5"};
- int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
- JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
- stockSamsung -= phoneAmount;
- SamsungS10(phoneAmount);
- }
- else if(stockSamsung == 4){
- String[] phoneButtons = {"Cancel", "1", "2", "3", "4"};
- int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
- JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
- stockSamsung -= phoneAmount;
- SamsungS10(phoneAmount);
- }
- else if(stockSamsung == 3){
- String[] phoneButtons = {"Cancel", "1", "2", "3"};
- int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
- JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
- stockSamsung -= phoneAmount;
- SamsungS10(phoneAmount);
- }
- else if(stockSamsung == 2){
- String[] phoneButtons = {"Cancel", "1", "2"};
- int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
- JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
- stockSamsung -= phoneAmount;
- SamsungS10(phoneAmount);
- }
- else if(stockSamsung == 1){
- String[] phoneButtons = {"Cancel", "1"};
- int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
- JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
- stockSamsung -= phoneAmount;
- SamsungS10(phoneAmount);
- }
- else if(stockSamsung == 0){
- JOptionPane.showMessageDialog(null, "No more Samsung S10's Available");
- }
- else if(phoneType==2){
- if (stockHuawei == 10){
- String[] phoneButtons = {"Cancel", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"};
- int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
- JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
- stockHuawei -= phoneAmount;
- HuaweiP30Pro(phoneAmount);
- }
- if (stockHuawei == 9){
- String[] phoneButtons = {"Cancel", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"};
- int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
- JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
- stockHuawei -= phoneAmount;
- HuaweiP30Pro(phoneAmount);
- }
- if (stockHuawei == 8){
- String[] phoneButtons = {"Cancel", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"};
- int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
- JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
- stockHuawei -= phoneAmount;
- HuaweiP30Pro(phoneAmount);
- }
- if (stockHuawei == 7){
- String[] phoneButtons = {"Cancel", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"};
- int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
- JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
- stockHuawei -= phoneAmount;
- HuaweiP30Pro(phoneAmount);
- }
- if (stockHuawei == 6){
- String[] phoneButtons = {"Cancel", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"};
- int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
- JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
- stockHuawei -= phoneAmount;
- HuaweiP30Pro(phoneAmount);
- }
- if (stockHuawei == 5){
- String[] phoneButtons = {"Cancel", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"};
- int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
- JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
- stockHuawei -= phoneAmount;
- HuaweiP30Pro(phoneAmount);
- }
- if (stockHuawei == 4){
- String[] phoneButtons = {"Cancel", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"};
- int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
- JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
- stockHuawei -= phoneAmount;
- HuaweiP30Pro(phoneAmount);
- }
- if (stockHuawei == 3){
- String[] phoneButtons = {"Cancel", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"};
- int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
- JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
- stockHuawei -= phoneAmount;
- HuaweiP30Pro(phoneAmount);
- }
- if (stockHuawei == 2){
- String[] phoneButtons = {"Cancel", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"};
- int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
- JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
- stockHuawei -= phoneAmount;
- HuaweiP30Pro(phoneAmount);
- }
- if (stockHuawei == 1){
- String[] phoneButtons = {"Cancel", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"};
- int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
- JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
- stockHuawei -= phoneAmount;
- HuaweiP30Pro(phoneAmount);
- }
- else if(stockSamsung == 0){
- JOptionPane.showMessageDialog(null, "No more Huawei P30 Pro's Available");
- }
- }
- else if(phoneType==3){
- if(stockOnePlus == 10){
- String[] phoneButtons = {"Cancel", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"};
- int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
- JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
- stockOnePlus -= phoneAmount;
- OnePlus7(phoneAmount);
- }
- if(stockOnePlus == 9){
- String[] phoneButtons = {"Cancel", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
- int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
- JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
- stockOnePlus -= phoneAmount;
- OnePlus7(phoneAmount);
- }
- if(stockOnePlus == 8){
- String[] phoneButtons = {"Cancel", "1", "2", "3", "4", "5", "6", "7", "8"};
- int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
- JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
- stockOnePlus -= phoneAmount;
- OnePlus7(phoneAmount);
- }
- if(stockOnePlus == 7){
- String[] phoneButtons = {"Cancel", "1", "2", "3", "4", "5", "6", "7"};
- int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
- JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
- stockOnePlus -= phoneAmount;
- OnePlus7(phoneAmount);
- }
- if(stockOnePlus == 6){
- String[] phoneButtons = {"Cancel", "1", "2", "3", "4", "5", "6"};
- int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
- JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
- stockOnePlus -= phoneAmount;
- OnePlus7(phoneAmount);
- }
- if(stockOnePlus == 5){
- String[] phoneButtons = {"Cancel", "1", "2", "3", "4", "5"};
- int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
- JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
- stockOnePlus -= phoneAmount;
- OnePlus7(phoneAmount);
- }
- if(stockOnePlus == 4){
- String[] phoneButtons = {"Cancel", "1", "2", "3", "4"};
- int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
- JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
- stockOnePlus -= phoneAmount;
- OnePlus7(phoneAmount);
- }
- if(stockOnePlus == 3){
- String[] phoneButtons = {"Cancel", "1", "2", "3"};
- int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
- JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
- stockOnePlus -= phoneAmount;
- OnePlus7(phoneAmount);
- }
- if(stockOnePlus == 2){
- String[] phoneButtons = {"Cancel", "1", "2"};
- int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
- JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
- stockOnePlus -= phoneAmount;
- OnePlus7(phoneAmount);
- }
- if(stockOnePlus == 1){
- String[] phoneButtons = {"Cancel", "1"};
- int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
- JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
- stockOnePlus -= phoneAmount;
- OnePlus7(phoneAmount);
- }
- else if(stockSamsung == 0){
- JOptionPane.showMessageDialog(null, "No more OnePlus 7's Available");
- }
- }
- else if(phoneType==4){
- skip(warning);
- }
- else{
- JOptionPane.showMessageDialog(null, "Error, Try again");
- i -= 1;
- }
- }
- }
- }
- public static int getInt(String userMessage) {
- int num = Integer.parseInt(JOptionPane.showInputDialog(userMessage));
- return num;
- }
- public static double calculate(int quantity, double ticketPrice) {
- double amountPayable = quantity * ticketPrice;
- return amountPayable;
- }
- public static void showMessage(double answer) {
- JOptionPane.showMessageDialog(null, "Please pay: " +answer);
- }
- public static int warningMessage(String userMessage){
- int skip = JOptionPane.showConfirmDialog(null, "Are you sure you want to be skipped");
- if (skip==JOptionPane.YES_OPTION){
- JOptionPane.showMessageDialog(null, "Skipped");
- }
- else if (skip==JOptionPane.NO_OPTION){
- i -= 1;
- }
- return skip;
- }
- public static void iPhone11(int quantity) {
- double price = 1500;
- double answer;
- answer = calculate(quantity, price);
- showMessage(answer);
- for(int i = 0; i <= 1; i++){
- double money = Double.parseDouble(JOptionPane.showInputDialog(null, "Please enter €1500"));
- double change = money - 1500;
- if (change != money || money < price){
- JOptionPane.showMessageDialog(null, "Incorrect amount of change");
- i -= 1;
- }
- else if(money > price){
- JOptionPane.showMessageDialog(null, "Order has been placed. change of " + change + "has been returned");
- }
- else if(money == price){
- JOptionPane.showMessageDialog(null, "Order has been placed");
- }
- }
- System.out.println(stockIphone);
- }
- public static void SamsungS10(int quantity) {
- double price = 800;
- double answer;
- answer = calculate(quantity, price);
- showMessage(answer);
- for(int i = 0; i <= 1; i++){
- double money = Double.parseDouble(JOptionPane.showInputDialog(null, "Please enter €1500"));
- double change = money - 1500;
- if (change != money || money < price){
- JOptionPane.showMessageDialog(null, "Incorrect amount of change");
- i -= 1;
- }
- else if(money > price){
- JOptionPane.showMessageDialog(null, "Order has been placed. change of " + change + "has been returned");
- }
- else if(money == price){
- JOptionPane.showMessageDialog(null, "Order has been placed");
- }
- }
- }
- public static void HuaweiP30Pro(int quantity) {
- double price = 850;
- double answer;
- answer = calculate(quantity, price);
- showMessage(answer);
- for(int i = 0; i <= 1; i++){
- double money = Double.parseDouble(JOptionPane.showInputDialog(null, "Please enter €1500"));
- double change = money - 1500;
- if (change != money || money < price){
- JOptionPane.showMessageDialog(null, "Incorrect amount of change");
- i -= 1;
- }
- else if(money > price){
- JOptionPane.showMessageDialog(null, "Order has been placed. change of " + change + "has been returned");
- }
- else if(money == price){
- JOptionPane.showMessageDialog(null, "Order has been placed");
- }
- }
- }
- public static void OnePlus7(int quantity) {
- double price = 650;
- double answer;
- answer = calculate(quantity, price);
- showMessage(answer);
- for(int i = 0; i <= 1; i++){
- double money = Double.parseDouble(JOptionPane.showInputDialog(null, "Please enter €1500"));
- double change = money - 1500;
- if (change != money || money < price){
- JOptionPane.showMessageDialog(null, "Incorrect amount of change");
- i -= 1;
- }
- else if(money > price){
- JOptionPane.showMessageDialog(null, "Order has been placed. change of " + change + "has been returned");
- }
- else if(money == price){
- JOptionPane.showMessageDialog(null, "Order has been placed");
- }
- }
- }
- public static void skip(int warning){
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement