Guest User

Untitled

a guest
Oct 17th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.09 KB | None | 0 0
  1. // import-list
  2. import java.text.DecimalFormat;
  3. import java.util.Scanner;
  4.  
  5. /**
  6. * Emits a recipe for some food
  7. *
  8. * @author Kevin Vo
  9. * @version 9/5/12
  10. *
  11. * Enhancements done:
  12. * ---- LIST ANY ENHANCEMENTS YOU HAVE DONE HERE ----
  13. * Pan size computation isn't proportional to the number of serving.
  14. * Converts to higher units for large numbers.
  15. */
  16. public class Recipe {
  17.  
  18. // this is the formatting object
  19. private static DecimalFormat df = new DecimalFormat("##.##");
  20.  
  21. /**
  22. * This is the main method for this program. It prompts the user and
  23. * then prints the recipe.
  24. *
  25. * This starter file does not contain the completed program. In fact,
  26. * it does nothing but prompt the user for the 'enter' key and then
  27. * quits.
  28. *
  29. * @param args command-line arguments
  30. */
  31. public static void main(String[] args) {
  32. // ****** YOUR MODIFICATIONS SHOULD START HERE ******
  33.  
  34. // our scanner object
  35. Scanner keyboard = new Scanner(System.in);
  36.  
  37. // THE FOLLOWING IS JUST AN EXAMPLE. CS 203 students should delete
  38. // (or modify) the lines below.
  39.  
  40. System.out.print("What is your name? ");
  41. String name = keyboard.nextLine();
  42.  
  43. System.out.println("Your name is "+name+".");
  44.  
  45. System.out.print("What kind of sauce do you want? ");
  46. String sauce = keyboard.nextLine();
  47.  
  48. System.out.println("You want "+sauce+" sauce.");
  49.  
  50. System.out.print("How many servings do you want? ");
  51. int serv = keyboard.nextInt();
  52. System.out.println("You want "+serv+" servings.");
  53. System.out.println();
  54. if ((serv == 0 ))
  55. System.out.println("Why did you run this file if you didn't want any of\n"+name+"'s Lasagna with "+sauce+" Sauce?\n\nYou must not be very hungry...");
  56. else
  57. if ((serv <0 ))
  58. System.out.println("I don't even think "+serv+" servings of "+name+"'s Lasagna with "+sauce+" Sauce\nis possible...");
  59. else{
  60. System.out.println(""+name+"'s Lasagna with "+sauce+" Sauce ("+serv+" servings)");
  61.  
  62. //servings
  63. String servs = df.format(serv);
  64. String servcups = df.format(serv/8);
  65. String servpints = df.format(serv/16);
  66. String servquarts = df.format(serv/32);
  67. String servgals = df.format(serv/128);
  68.  
  69. //meat = lbs
  70. double sausage = (serv*0.08333);
  71. String sausages = df.format(sausage);
  72. double dabeef = (serv*0.0625);
  73. String dabeefs = df.format(dabeef);
  74. //onion/tomato = oz
  75. double onion = (serv*0.33328);
  76. String onions = df.format(onion);
  77. String onioncups = df.format(onion/8);
  78. String onionpints = df.format(onion/16);
  79. String onionquarts = df.format(onion/32);
  80. String oniongals = df.format(onion/128);
  81.  
  82. double tomato = (serv*0.21166);
  83. String tomatos = df.format(tomato);
  84. String tomatocups = df.format(tomato/8);
  85. String tomatopints = df.format(tomato/16);
  86. String tomatoquarts = df.format(tomato/32);
  87. String tomatogals = df.format(tomato/128);
  88.  
  89. //sugar = oz
  90. double sugar = (serv*0.33332);
  91. String sugars = df.format(sugar);
  92. String sugarcups = df.format(sugar/8);
  93. String sugarpints = df.format(sugar/16);
  94. String sugarquarts = df.format(sugar/32);
  95. String sugargals = df.format(sugar/128);
  96.  
  97. //cheese = oz
  98. double rcheese = (serv*1.333);
  99. String rcheeses = df.format(rcheese);
  100. String rcheesecups = df.format(rcheese/8);
  101. String rcheesepints = df.format(rcheese/16);
  102. String rcheesequarts = df.format(rcheese/32);
  103. String rcheesegals = df.format(rcheese/128);
  104. double mcheese = (serv*1.333);
  105. String mcheeses = df.format(mcheese);
  106. String mcheesecups = df.format(mcheese/8);
  107. String mcheesepints = df.format(mcheese/16);
  108. String mcheesequarts = df.format(mcheese/32);
  109. String mcheesegals = df.format(mcheese/128);
  110. //water = oz
  111. double water = (serv*0.33328);
  112. String waters = df.format(water);
  113. String watercups = df.format(water/8);
  114. String waterpints = df.format(water/16);
  115. String waterquarts = df.format(water/32);
  116. String watergals = df.format(water/128);
  117.  
  118. //gal > quart > pint > cup > oz > tbsp > tsp
  119.  
  120. System.out.println("Italian Sausage ("+sausages+" lbs)");
  121. System.out.println("Ground Beef ("+dabeefs+" lbs)");
  122. if ((onion >128 ))
  123. System.out.println("Onions ("+oniongals+" gals)");
  124. else
  125. if ((onion >=32) && (onion<128))
  126. System.out.println("Onions ("+onionquarts+" quarts)");
  127. else
  128. if ((onion >=16) && (onion<32))
  129. System.out.println("Onions ("+onionpints+" pints)");
  130. else
  131. if ((onion >= 8) && (onion<16))
  132. System.out.println("Onions ("+onioncups+" cups)");
  133. else
  134. System.out.println("Onions ("+onions+" oz)");
  135. if ((tomato >128 ))
  136. System.out.println("Tomatoes ("+tomatogals+" gals)");
  137. else
  138. if ((tomato >=32) && (tomato<128))
  139. System.out.println("Tomatoes ("+tomatoquarts+" quarts)");
  140. else
  141. if ((tomato >=16) && (tomato<32))
  142. System.out.println("Tomatoes ("+tomatopints+" pints)");
  143. else
  144. if ((tomato >= 8) && (tomato<16))
  145. System.out.println("Tomatoes ("+tomatocups+" cups)");
  146. else
  147. System.out.println("Tomatoes ("+tomatos+" oz)");
  148. if ((serv >128 ))
  149. System.out.println(sauce+" sauce ("+servgals+" gals)");
  150. else
  151. if ((serv >=32) && (serv<128))
  152. System.out.println(sauce+" sauce ("+servquarts+" quarts)");
  153. else
  154. if ((serv >=16) && (serv<32))
  155. System.out.println(sauce+" sauce ("+servpints+" pints)");
  156. else
  157. if ((serv >= 8) && (serv<16))
  158. System.out.println(sauce+" sauce ("+servcups+" cups)");
  159. else
  160. System.out.println(sauce+" sauce ("+servs+" oz)");
  161. if ((rcheese >128 ))
  162. System.out.println("Ricotta Cheese ("+rcheesegals+" gals)");
  163. else
  164. if ((rcheese >=32) && (rcheese<128))
  165. System.out.println("Ricotta Cheese ("+rcheesequarts+" quarts)");
  166. else
  167. if ((rcheese >=16) && (rcheese<32))
  168. System.out.println("Ricotta Cheese ("+rcheesepints+" pints)");
  169. else
  170. if ((rcheese >= 8) && (rcheese<16))
  171. System.out.println("Ricotta Cheese ("+rcheesecups+" cups)");
  172. else
  173. System.out.println("Ricotta Cheese ("+rcheeses+" oz)");
  174. if ((mcheese >128 ))
  175. System.out.println("Mozzarella Cheese ("+mcheesegals+" gals)");
  176. else
  177. if ((mcheese >=32) && (mcheese<128))
  178. System.out.println("Mozzarella Cheese ("+mcheesequarts+" quarts)");
  179. else
  180. if ((mcheese >=16) && (mcheese<32))
  181. System.out.println("Mozzarella Cheese ("+mcheesepints+" pints)");
  182. else
  183. if ((mcheese >= 8) && (mcheese<16))
  184. System.out.println("Mozzarella Cheese ("+mcheesecups+" cups)");
  185. else
  186. System.out.println("Mozzarella Cheese ("+mcheeses+" oz)");
  187. if ((sugar >128 ))
  188. System.out.println("Sugar ("+sugargals+" gals)");
  189. else
  190. if ((sugar >=32) && (sugar<128))
  191. System.out.println("Sugar ("+sugarquarts+" quarts)");
  192. else
  193. if ((sugar >=16) && (sugar<32))
  194. System.out.println("Sugar ("+sugarpints+" pints)");
  195. else
  196. if ((sugar >= 8) && (sugar<16))
  197. System.out.println("Sugar ("+sugarcups+" cups)");
  198. else
  199. System.out.println("Sugar ("+sugars+" oz)");
  200. if ((water >128 ))
  201. System.out.println("Water ("+watergals+" gals)");
  202. else
  203. if ((water >=32) && (water<128))
  204. System.out.println("Water ("+waterquarts+" quarts)");
  205. else
  206. if ((water >=16) && (water<32))
  207. System.out.println("Water ("+waterpints+" pints)");
  208. else
  209. if ((water >= 8) && (water<16))
  210. System.out.println("Water ("+watercups+" cups)");
  211. else
  212. System.out.println("Water ("+waters+" oz)");
  213. System.out.println("Lasagna Noodles ("+servs+")");
  214.  
  215. int containerl = 9^(serv^1/2);
  216. int containerw = 4^(serv^1/2);
  217. System.out.println();
  218. System.out.println("Cook the sausage, ground beef and onions over medium heat until well cooked.\nStir for 5 minutes, adding in some water and tomatoes. Add a thin layer of\nthe mixture to the bottom of a "+containerl+" by "+containerw+" inch pan. On top of this, add\nlasanga noodles and a small layer of cheese on top of the meat. Repeat\nthis until the pan is full.");
  219. }
  220. // ****** YOUR MODIFICATIONS SHOULD END HERE ******
  221. }
  222.  
  223. /**
  224. * This method produces a string with a specified number of blanks.
  225. * CS 203 students should not need to modify anything below
  226. *
  227. * @param count the number of the blanks in the string
  228. * @return a string consisting of the specified number of blanks
  229. */
  230. private static String repeatBlanks(int count) {
  231. if (count <= 0) return ""; // if no blanks required, return empty string
  232. else return " "+repeatBlanks(count-1); // otherwise produce string
  233. }
  234. }
Add Comment
Please, Sign In to add comment