Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.91 KB | None | 0 0
  1. package ShishaShop;
  2.  
  3. import javax.swing.*;
  4. import java.util.ArrayList;
  5. import java.util.List;
  6. import java.util.Scanner;
  7.  
  8. public class Main {
  9. public static void main(String[] args) {
  10. Icon shisha = new ImageIcon("D:\\shisha.jpg");
  11. Scanner scanner = new Scanner(System.in);
  12. List<String> shishas = new ArrayList<>();
  13. List<Integer> price = new ArrayList<>();
  14. switch (welcomeMessage(shisha)) {
  15. case 0: {
  16.  
  17. do {
  18. int priceOfCurrShisha = 0;
  19. String[] asd = qualityChoice(shisha).split("\n");
  20. switch (asd[0]) {
  21. case "Low": {
  22. priceOfCurrShisha = 80;
  23. }
  24. case "Medium": {
  25. priceOfCurrShisha = 120;
  26. }
  27. case "High": {
  28. priceOfCurrShisha = 160;
  29. }
  30. }
  31. String order = asd[0] + " quality shisha -";
  32. asd = heightChoice(shisha).split("\n");
  33. switch (asd[0]) {
  34. case "100 cm":
  35. priceOfCurrShisha += 20;
  36. case "120 cm":
  37. priceOfCurrShisha += 40;
  38. }
  39. order += asd[0];
  40. shishas.add(order);
  41. price.add(priceOfCurrShisha);
  42. } while (continueMessage(shisha) == 0);
  43. finalScreen(shishas, price, shisha);
  44. }
  45. case 1: {
  46. JOptionPane.showMessageDialog(null, "Thank you for visiting our store!\nWelcome back!", "Bye", JOptionPane.INFORMATION_MESSAGE, shisha);
  47. return;
  48. }
  49. }
  50. }
  51.  
  52. public static String heightChoice(Icon shisha) {
  53. String[] choices = {"80 cm\n+0$", "100 cm\n+20$", "120 cm\n+40$"};
  54. int index = JOptionPane.showOptionDialog(null, "Choose the height of your shisha!", "Height", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, shisha, choices, null);
  55. return choices[index];
  56. }
  57.  
  58. public static String qualityChoice(Icon shisha) {
  59. String[] choices = {"Low\n80 - 120$", "Medium\n120-160$", "High\n160-200$"};
  60. int index = JOptionPane.showOptionDialog(null, "Choose the quality of your shisha!", "Quality", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, shisha, choices, null);
  61. return choices[index];
  62. }
  63.  
  64. public static int welcomeMessage(Icon shisha) {
  65. return JOptionPane.showConfirmDialog(null, "Welcome to our store!\nWould you like to purchase?", "Welcome", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, shisha);
  66. }
  67.  
  68. public static int continueMessage(Icon shisha) {
  69. String[] options = {"Purchase another", "Finalise order"};
  70. 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);
  71. }
  72.  
  73. public static void finalScreen(List<String> shishas, List<Integer> price, Icon shisha) {
  74. String bill = "";
  75. for (int i = 0; i < price.size() - 1; i++) {
  76. if (price.get(i) < price.get(i + 1)) {
  77. int temp = price.get(i);
  78. price.set(i, price.get(i + 1));
  79. price.set(i + 1, temp);
  80. String temp1 = shishas.get(i);
  81. shishas.set(i, shishas.get(i + 1));
  82. shishas.set(i + 1, temp1);
  83. }
  84. }
  85. for (int i = 0; i < shishas.size(); i++) {
  86. bill += shishas.get(i) + " - " + price.get(i) + "$\n";
  87. }
  88. JOptionPane.showMessageDialog(null, bill, "Bill", JOptionPane.INFORMATION_MESSAGE, shisha);
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement