Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ShishaShop;
- import javax.swing.*;
- import java.util.ArrayList;
- import java.util.List;
- public class Main {
- public static void main(String[] args) {
- Icon shisha = new ImageIcon("D:\\shisha.jpg");
- List<String> shishas = new ArrayList<>();
- List<Integer> price = new ArrayList<>();
- switch (welcomeMessage(shisha)) {
- case 0: {
- do {
- int priceOfCurrShisha = 0;
- String[] asd = qualityChoice(shisha).split("\n");
- switch (asd[0]) {
- case "Low": {
- priceOfCurrShisha = 80;
- break;
- }
- case "Medium": {
- priceOfCurrShisha = 120;
- break;
- }
- case "High": {
- priceOfCurrShisha = 160;
- break;
- }
- }
- String order = asd[0] + " quality shisha -";
- asd = heightChoice(shisha).split("\n");
- switch (asd[0]) {
- case "100 cm": {
- priceOfCurrShisha += 20;
- break;
- }
- case "120 cm": {
- priceOfCurrShisha += 40;
- break;
- }
- }
- order += asd[0];
- shishas.add(order);
- price.add(priceOfCurrShisha);
- } while (continueMessage(shisha) == 0);
- finalScreen(shishas, price, shisha);
- break;
- }
- case 1: {
- JOptionPane.showMessageDialog(null, "Thank you for visiting our store!\nWelcome back!", "Bye", JOptionPane.INFORMATION_MESSAGE, shisha);
- return;
- }
- }
- }
- public static String heightChoice(Icon shisha) {
- String[] choices = {"80 cm\n+0$", "100 cm\n+20$", "120 cm\n+40$"};
- int index = JOptionPane.showOptionDialog(null, "Choose the height of your shisha!", "Height", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, shisha, choices, null);
- return choices[index];
- }
- public static String qualityChoice(Icon shisha) {
- String[] choices = {"Low\n80 - 120$", "Medium\n120-160$", "High\n160-200$"};
- int index = JOptionPane.showOptionDialog(null, "Choose the quality of your shisha!", "Quality", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, shisha, choices, null);
- return choices[index];
- }
- public static int welcomeMessage(Icon shisha) {
- return JOptionPane.showConfirmDialog(null, "Welcome to our store!\nWould you like to purchase?", "Welcome", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, shisha);
- }
- public static int continueMessage(Icon shisha) {
- String[] options = {"Purchase another", "Finalise order"};
- return JOptionPane.showOptionDialog(null, "Product successfully purchased!\n Would you like to continue purchasing?", "Continue?", JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE, shisha, options, null);
- }
- public static void finalScreen(List<String> shishas, List<Integer> price, Icon shisha) {
- String bill = "";
- for (int i = 0; i < price.size() - 1; i++) {
- if (price.get(i) > price.get(i + 1)) {
- int temp = price.get(i);
- price.set(i, price.get(i + 1));
- price.set(i + 1, temp);
- String temp1 = shishas.get(i);
- shishas.set(i, shishas.get(i + 1));
- shishas.set(i + 1, temp1);
- }
- }
- for (int i = 0; i < shishas.size(); i++) {
- bill += shishas.get(i) + " - " + price.get(i) + "$\n";
- }
- JOptionPane.showMessageDialog(null, bill, "Bill", JOptionPane.INFORMATION_MESSAGE, shisha);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement