Advertisement
Guest User

Untitled

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