Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.73 KB | None | 0 0
  1. String filename = "pizza.txt";
  2. TextFileReader in = new TextFileReader("src\\leefinalproject\\pizza.txt");
  3. String line;
  4. String code = "";
  5. String linesToWrite = "";
  6. while (in.hasNext()) {
  7. line = in.nextLine();
  8. linesToWrite += line + "\n";
  9. System.out.println(line);
  10. switch (line) {
  11. case "*crusts*":
  12. code = "*crusts*";
  13. break;
  14. case "*sauces*":
  15. code = "*sauces*";
  16. break;
  17. case "*toppings*":
  18. code = "*toppings*";
  19. break;
  20. case "*cheeses*":
  21. code = "*cheeses*";
  22. break;
  23. case "*pizzas*":
  24. code = "*pizzas*";
  25. break;
  26. default:
  27. StringTokenizer st = new StringTokenizer(line, ",");
  28. String name = st.nextToken();
  29. double price = Double.parseDouble(st.nextToken());
  30. String desc = st.nextToken();
  31. if (code.equals("*crusts*")) {
  32. Crust newCrust = new Crust(name, price, desc);
  33. crusts.add(newCrust);
  34. } else if (code.equals("*sauces*")) {
  35. Sauce newSauce = new Sauce(name, price, desc);
  36. sauces.add(newSauce);
  37. } else if (code.equals("*toppings*")) {
  38. Topping newTopping = new Topping(name, price, desc);
  39. toppings.add(newTopping);
  40. } else if (code.equals("*cheeses*")) {
  41. Cheese newCheese = new Cheese(name, price, desc);
  42. cheeses.add(newCheese);
  43. } else if (code.equals("*pizzas*")) {
  44. Pizza newPizza = new Pizza(name, price, desc);
  45. pizzas.add(newPizza);
  46. }
  47. }
  48. }
  49. in.close();
  50. TextFileWriter out = new TextFileWriter("out.txt");
  51. out.write(linesToWrite);
  52. out.close();
  53.  
  54. initComponents();
  55.  
  56. }
  57.  
  58. // Convert arrayList into an array for a dropdown menu
  59. String[] convertToArray(ArrayList<Pizza> list) {
  60. // Get the size of the ArrayList.
  61. int size = list.size();
  62.  
  63. // Create the new array of strings to be displayed.
  64. String[] arr = new String[size];
  65.  
  66. // Iterate over all of the items in the list, and add their names and
  67. // prices to the new array.
  68. for (int i = 0; i < size; i++) {
  69. String twoDeciPlaces = String.format("%.02f", list.get(i).price);
  70. arr[i] = list.get(i).name + " $" + twoDeciPlaces;
  71. }
  72. return arr;
  73. }
  74.  
  75. // Convert arrayList into an array for a dropdown menu
  76. String[] convertToArrayCrust(ArrayList<Crust> list) {
  77. // Get the size of the ArrayList.
  78. int size = list.size();
  79.  
  80. // Create the new array of strings to be displayed.
  81. String[] arr = new String[size];
  82.  
  83. // Iterate over all of the items in the list, and add their names and
  84. // prices to the new array.
  85. for (int i = 0; i < size; i++) {
  86. String twoDeciPlaces = String.format("%.02f", list.get(i).price);
  87. arr[i] = list.get(i).name + " $" + twoDeciPlaces;
  88. }
  89. return arr;
  90. }
  91. String[] convertToArraySauce(ArrayList<Sauce> list) {
  92. // Get the size of the ArrayList.
  93. int size = list.size();
  94.  
  95. // Create the new array of strings to be displayed.
  96. String[] arr = new String[size];
  97.  
  98. // Iterate over all of the items in the list, and add their names and
  99. // prices to the new array.
  100. for (int i = 0; i < size; i++) {
  101. String twoDeciPlaces = String.format("%.02f", list.get(i).price);
  102. arr[i] = list.get(i).name + " $" + twoDeciPlaces;
  103. }
  104. return arr;
  105. }
  106. String[] convertToArrayCheese(ArrayList<Cheese> list) {
  107. // Get the size of the ArrayList.
  108. int size = list.size();
  109.  
  110. // Create the new array of strings to be displayed.
  111. String[] arr = new String[size];
  112.  
  113. // Iterate over all of the items in the list, and add their names and
  114. // prices to the new array.
  115. for (int i = 0; i < size; i++) {
  116. String twoDeciPlaces = String.format("%.02f", list.get(i).price);
  117. arr[i] = list.get(i).name + " $" + twoDeciPlaces;
  118. }
  119. return arr;
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement