Advertisement
Guest User

Untitled

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