Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 31st, 2012  |  syntax: Java  |  size: 3.80 KB  |  hits: 21  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. package compassignment;
  2. import java.util.Scanner;
  3.  
  4.  
  5. public class Main {
  6.  
  7.     {
  8.         //IF I MAKE THESE ARRAYS STATIC, EVERYTHING IN THE ARRAYS BECOMES AN ERROR
  9.         double[] MET = new double[30]; //Creating array for MET values
  10.  
  11.         MET[0] = 6.83; MET[1] = 8.00; MET[2] = 8.00;
  12.         MET[3] = 4.50; MET[4] = 1.50; MET[5] = 1.80;
  13.         MET[6] = 4.50; MET[7] = 8.00; MET[8] = 2.10;
  14.         MET[9] = 6.00; MET[10] = 2.18; MET[11] = 3.01;
  15.         MET[12] = 2.07; MET[13] = 3.66; MET[14] = 10.00;
  16.         MET[15] = 1.58; MET[16] = 1.64; MET[17] = 2.72;
  17.         MET[18] = 10.00; MET[19] = 18.00; MET[20] = 0.92;
  18.         MET[21] = 7.00; MET[22] = 9.50; MET[23] = 1.82;
  19.         MET[24] = 2.93; MET[25] = 2.05; MET[26] = 3.80;
  20.         MET[27] = 5.22; MET[28] = 6.00; MET[29] = 3.00;
  21.  
  22.         int[] Food = new int[35]; //Creating array for Food values
  23.  
  24.         Food[0] = 301; Food[1] = 725; Food[2] = 438;
  25.         Food[3] = 1179; Food[4] = 580; Food[5] = 288;
  26.         Food[6] = 691; Food[7] = 334; Food[8] = 476;
  27.         Food[9] = 399; Food[10] = 808; Food[11] = 1110;
  28.         Food[12] = 423; Food[13] = 605; Food[14] = 516;
  29.         Food[15] = 606; Food[16] = 22; Food[17] = 1980;
  30.         Food[18] = 622; Food[19] = 33; Food[20] = 362;
  31.         Food[21] = 694; Food[22] = 232; Food[23] = 1869;
  32.         Food[24] = 501; Food[25] = 684; Food[26] = 1045;
  33.         Food[27] = 1012; Food[28] = 627; Food[29] = 207;
  34.         Food[30] = 148; Food[31] = 232; Food[32] = 327;
  35.         Food[33] = 583; Food[34] = 60;
  36.     }
  37.  
  38.     public static void main(String[] args)
  39.     {
  40.         choice();
  41.  
  42.     }
  43.  
  44.     private static void choice() //Code for choosing either Food or Activity
  45.     {
  46.         System.out.println("Welcome to the Energy Balancer. (QUIT to exit)");
  47.         System.out.println("==============================================");
  48.         System.out.print("Are you balancing food or activity?"
  49.                 + " (Help/FOOD/ACTIVITY)");
  50.         Scanner scan = new Scanner(System.in);
  51.         String input = scan.next();
  52.                
  53.         if (input.equalsIgnoreCase("food"))
  54.             foodchoice();
  55.  
  56.         else if (input.equalsIgnoreCase("activity"))
  57.             activitychoice();
  58.        
  59.         else die();
  60.  
  61.     }
  62.     private static void foodchoice()
  63.     {
  64.         System.out.print("Please enter the user's weight in kg: ");
  65.  
  66.         Scanner scan = new Scanner (System.in);
  67.         int weight = scan.nextInt();
  68.  
  69.         System.out.println("Indicate the type of food and number of serves "
  70.                 + "from the list below:");
  71.         System.out.println("0. Apples\n1. Baked Beans\n2. Banana"
  72.                 + "\n3. Beef Steak\n4. Beer\n5. Beetroot\n6. Bread - Pita"
  73.                 + "\n7. Bread - White\n8. Cheese - Cheddar\n9. Chick Peas"
  74.                 + "\n10. Chicken Breast\n11. Chocolate\n12. Corn Flakes"
  75.                 + "\n13. French Fries\n14. Fruit Juice\n15. Ice Cream - Vanilla"
  76.                 + "\n16. Lettuce\n17. Meat Pie\n18. Milk - Regular"
  77.                 + "\n19. Mushrooms - Raw\n20. Oranges\n21. Peanuts"
  78.                 + "\n22. Peas\n23. Pork Steak\n24. Porridge - Instant"
  79.                 + "\n25. Potato\n26. Potato Crisps\n27. Rice - White"
  80.                 + "\n28. Soft Drink\n29. Strawberries\n30. Tofu"
  81.                 + "\n31. Tomato\n32. Tuna\n33. Yoghurt - Plain\n34. Zucchini");
  82.  
  83.         int type = scan.nextInt();
  84.         int serves = scan.nextInt();
  85.        
  86.         if (type > 34)
  87.             die();
  88.         else if (type < 0)     //making sure only positive numbers are entered,
  89.             die();             //as well as type being less than 35.
  90.         if (serves < 0)
  91.             die();
  92.        
  93.         int kcal = MET[type];
  94.         //^HERE IS WHERE IM HAVING TROUBLE^ The "MET" has an error, saying "variable MET not found"
  95.     }
  96. }