Advertisement
Guest User

methods1

a guest
Nov 21st, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.00 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package javaapplication4;
  7. import javax.swing.JOptionPane;
  8.  
  9.  
  10.  
  11. public class JavaApplication4 {
  12. public static int i = 1;
  13. public static int stockIphone = 10;
  14. public static int stockSamsung = 8;
  15. public static int stockHuawei = 10;
  16. public static int stockOnePlus = 5;
  17.  
  18. public static void main(String[] args) {
  19. for(i = 1; i <= 10; i++){
  20. String[] ticketButtons = {"Iphone 11 - $1500", "Samsung S10 - $800", "Huawei P30 Pro - $850", "One Plus 7 Pro - $650", "Skip"};
  21. int phoneType = JOptionPane.showOptionDialog(null, "Please select the phone you would like to purchase: ", "phone selection",
  22. JOptionPane.WARNING_MESSAGE, 0, null, ticketButtons, ticketButtons[2]);
  23. int warning = warningMessage("");
  24.  
  25.  
  26.  
  27. if(phoneType==0){
  28. if(stockIphone == 10){
  29.  
  30. String[] phoneButtons = {"Cancel", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"};
  31. int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
  32. JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
  33.  
  34. stockIphone -= phoneAmount;
  35. iPhone11(phoneAmount);
  36. }
  37. else if(stockIphone == 9){
  38.  
  39. String[] phoneButtons = {"Cancel", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
  40. int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
  41. JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
  42.  
  43. stockIphone -= phoneAmount;
  44. iPhone11(phoneAmount);
  45. }
  46. else if(stockIphone == 8){
  47.  
  48. String[] phoneButtons = {"Cancel", "1", "2", "3", "4", "5", "6", "7", "8"};
  49. int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
  50. JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
  51.  
  52. stockIphone -= phoneAmount;
  53. iPhone11(phoneAmount);
  54. }
  55. else if(stockIphone == 7){
  56.  
  57. String[] phoneButtons = {"Cancel", "1", "2", "3", "4", "5", "6", "7"};
  58. int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
  59. JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
  60.  
  61. stockIphone -= phoneAmount;
  62. iPhone11(phoneAmount);
  63. }
  64. else if(stockIphone == 6){
  65.  
  66. String[] phoneButtons = {"Cancel", "1", "2", "3", "4", "5", "6"};
  67. int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
  68. JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
  69.  
  70. stockIphone -= phoneAmount;
  71. iPhone11(phoneAmount);
  72. }
  73. else if(stockIphone == 5){
  74.  
  75. String[] phoneButtons = {"Cancel", "1", "2", "3", "4", "5"};
  76. int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
  77. JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
  78.  
  79. stockIphone -= phoneAmount;
  80. iPhone11(phoneAmount);
  81. }
  82. else if(stockIphone == 4){
  83.  
  84. String[] phoneButtons = {"Cancel", "1", "2", "3", "4"};
  85. int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
  86. JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
  87.  
  88. stockIphone -= phoneAmount;
  89. iPhone11(phoneAmount);
  90. }
  91. else if(stockIphone == 3){
  92.  
  93. String[] phoneButtons = {"Cancel", "1", "2", "3"};
  94. int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
  95. JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
  96.  
  97. stockIphone -= phoneAmount;
  98. iPhone11(phoneAmount);
  99. }
  100. else if(stockIphone == 2){
  101.  
  102. String[] phoneButtons = {"Cancel", "1", "2"};
  103. int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
  104. JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
  105.  
  106.  
  107. stockIphone -= phoneAmount;
  108. iPhone11(phoneAmount);
  109. }
  110. else if(stockIphone == 1){
  111.  
  112. String[] phoneButtons = {"Cancel", "1"};
  113. int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
  114. JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
  115.  
  116. stockIphone -= phoneAmount;
  117. iPhone11(phoneAmount);
  118. }
  119. else if(stockIphone == 0){
  120. JOptionPane.showMessageDialog(null, "No More Iphone 11's remaining");
  121. }
  122. }
  123.  
  124.  
  125.  
  126. else if(phoneType==1){
  127. if(stockSamsung == 10){
  128.  
  129. String[] phoneButtons = {"Cancel", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"};
  130. int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
  131. JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
  132.  
  133. stockSamsung -= howMany;
  134. SamsungS10(howMany);
  135. }
  136. else if(stockSamsung == 9){
  137.  
  138. String[] phoneButtons = {"Cancel", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
  139. int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
  140. JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
  141.  
  142. stockSamsung -= howMany;
  143. SamsungS10(howMany);
  144. }
  145. else if(stockSamsung == 8){
  146.  
  147. String[] phoneButtons = {"Cancel", "1", "2", "3", "4", "5", "6", "7", "8"};
  148. int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
  149. JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
  150.  
  151. stockSamsung -= howMany;
  152. SamsungS10(howMany);
  153. }
  154. else if(stockSamsung == 7){
  155.  
  156. String[] phoneButtons = {"Cancel", "1", "2", "3", "4", "5", "6", "7"};
  157. int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
  158. JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
  159.  
  160. stockSamsung -= howMany;
  161. SamsungS10(howMany);
  162. }
  163. else if(stockSamsung == 6){
  164.  
  165. String[] phoneButtons = {"Cancel", "1", "2", "3", "4", "5", "6"};
  166. int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
  167. JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
  168.  
  169. stockSamsung -= howMany;
  170. SamsungS10(howMany);
  171. }
  172. else if(stockSamsung == 5){
  173.  
  174. String[] phoneButtons = {"Cancel", "1", "2", "3", "4", "5"};
  175. int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
  176. JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
  177.  
  178. stockSamsung -= howMany;
  179. SamsungS10(howMany);
  180. }
  181. else if(stockSamsung == 4){
  182.  
  183. String[] phoneButtons = {"Cancel", "1", "2", "3", "4"};
  184. int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
  185. JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
  186.  
  187. stockSamsung -= howMany;
  188. SamsungS10(howMany);
  189. }
  190. else if(stockSamsung == 3){
  191.  
  192. String[] phoneButtons = {"Cancel", "1", "2", "3"};
  193. int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
  194. JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
  195.  
  196. stockSamsung -= howMany;
  197. SamsungS10(howMany);
  198. }
  199. else if(stockSamsung == 2){
  200.  
  201. String[] phoneButtons = {"Cancel", "1", "2"};
  202. int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
  203. JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
  204.  
  205. stockSamsung -= howMany;
  206. SamsungS10(howMany);
  207. }
  208. else if(stockSamsung == 1){
  209.  
  210. String[] phoneButtons = {"Cancel", "1"};
  211. int phoneAmount = JOptionPane.showOptionDialog(null, "Please select the number of phones you would like to purchase: ", "phone selection",
  212. JOptionPane.WARNING_MESSAGE, 0, null, phoneButtons, phoneButtons[2]);
  213.  
  214. stockSamsung -= howMany;
  215. SamsungS10(howMany);
  216. }
  217. else if(stockSamsung == 0){
  218. JOptionPane.showMessageDialog(null, "No more Samsung S10's Available");
  219. }
  220.  
  221. else if(phoneType==2){
  222. stockHuawei -= howMany;
  223. HuaweiP30Pro(howMany);
  224. }
  225. else if(phoneType==3){
  226. stockOnePlus -= howMany;
  227. OnePlus7(howMany);
  228. }
  229. else if(phoneType==4){
  230. skip(warning);
  231. }
  232. else{
  233. JOptionPane.showMessageDialog(null, "Error, Try again");
  234. i -= 1;
  235. }
  236. }
  237. }
  238. }
  239. public static int getInt(String userMessage) {
  240. int num = Integer.parseInt(JOptionPane.showInputDialog(userMessage));
  241. return num;
  242. }
  243.  
  244. public static double calculate(int quantity, double ticketPrice) {
  245. double amountPayable = quantity * ticketPrice;
  246. return amountPayable;
  247. }
  248. public static void showMessage(double answer) {
  249. JOptionPane.showMessageDialog(null, "Please pay: " +answer);
  250. }
  251. public static int warningMessage(String userMessage){
  252. int skip = JOptionPane.showConfirmDialog(null, "Are you sure you want to be skipped");
  253. if (skip==JOptionPane.YES_OPTION){
  254. JOptionPane.showMessageDialog(null, "Skipped");
  255. }
  256. else if (skip==JOptionPane.NO_OPTION){
  257. i -= 1;
  258. }
  259. return skip;
  260. }
  261. public static void iPhone11(int quantity) {
  262. double price = 1500;
  263. double answer;
  264. answer = calculate(quantity, price);
  265. showMessage(answer);
  266. System.out.println(stockIphone);
  267. }
  268. public static void SamsungS10(int quantity) {
  269. double price = 800;
  270. double answer;
  271. answer = calculate(quantity, price);
  272. showMessage(answer);
  273. System.out.println(stockSamsung);
  274. }
  275. public static void HuaweiP30Pro(int quantity) {
  276. double price = 850;
  277. double answer;
  278. answer = calculate(quantity, price);
  279. showMessage(answer);
  280. }
  281. public static void OnePlus7(int quantity) {
  282. double price = 650;
  283. double answer;
  284. answer = calculate(quantity, price);
  285. showMessage(answer);
  286. }
  287.  
  288. public static void skip(int warning){
  289.  
  290. }
  291. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement