Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 为什么我的代码无法打印arraylist中的内容?_Java_Arrays_Arraylist_Printing - Fatal编程技术网

Java 为什么我的代码无法打印arraylist中的内容?

Java 为什么我的代码无法打印arraylist中的内容?,java,arrays,arraylist,printing,Java,Arrays,Arraylist,Printing,因此,我正在开发一款健身应用程序,它可以接收用户信息,并输出他们燃烧的卡路里数,以及他们根据体重指数应该遵循的膳食计划。嗯,到目前为止,我没有遇到任何麻烦,我把所有关于吃什么样的食物的信息都保存在ArrayList中。但是,我的代码不会打印数组列表中的任何内容。我不知道该怎么办,我甚至在网上查了一些东西,但一切都有帮助。这不是复制品,请帮帮我,我会非常感激的 import java.util.Scanner; import java.util.ArrayList; import ja

因此,我正在开发一款健身应用程序,它可以接收用户信息,并输出他们燃烧的卡路里数,以及他们根据体重指数应该遵循的膳食计划。嗯,到目前为止,我没有遇到任何麻烦,我把所有关于吃什么样的食物的信息都保存在ArrayList中。但是,我的代码不会打印数组列表中的任何内容。我不知道该怎么办,我甚至在网上查了一些东西,但一切都有帮助。这不是复制品,请帮帮我,我会非常感激的

  import java.util.Scanner;
  import java.util.ArrayList;
  import java.io.*;
  import java.lang.Math;
  import java.nio.file.Paths;
  import java.nio.file.Files;


  public class Project5
{
  public static void main(String[] args) throws IOException
 {

    System.out.println("Welcome to the fitness app");
    String name;
    double weight;
    double age;
    int feet;
    int inches;
    double height;
    String gender;
    double bmi;
    double rlweight;
    double rhweight;
    boolean launch;
    double calories = 0.0;
    String juice;
    boolean x = true;
    double inches2;
    boolean underweight = false;
    boolean normal = false;
    boolean overweight = false;
    boolean obese = false;
    boolean xobese = false;
    String status;
    ArrayList<Food> n = new ArrayList<Food>();
    addFoodsToListfast(n);
    ArrayList<obx> obx = new ArrayList<obx>();
    addFoodsToListslow(obx);
    ArrayList<over> ov = new ArrayList<over>();
    addFoodsToListmoderate(ov);
    ArrayList<under> und = new ArrayList<under>();
    addFoodsToListfour(und);
    FileInputStream fileIn = new 
    FileInputStream("Foodstomaintainweight.txt");
    Scanner foods = new Scanner(fileIn);
    String[] foodss = 
每天摄入卡路里。”)

}如果(性别平等(“女性”)和状态平等(“活跃”)){
卡路里=(10*体重+6.25*身高-5*年龄-161)*1.725;
System.out.println(“你燃烧”+数学四舍五入(卡路里)+”
每天摄入卡路里。”);
}否则{
System.out.println(“无效性别或活动状态”);
}
体重指数=(体重)/(身高*身高)*703;
如果(年龄>=18岁){
启动=真;
}否则{
System.out.println(“您还不够大,无法使用此应用程序”);
发射=假;
}
while(启动!=错误){
如果(bmi>30&&bmi<35){
肥胖=正确;
System.out.println(“你太胖了”);
打破
}否则,如果(体重指数>35){
xobese=true;
System.out.println(“你是危险的肥胖者”);
打破
}否则,如果(体重指数<25&&bmi>18.5){
正常=真;
System.out.println(“你是正常体重”);
打破
}否则,如果(bmi>25&&bmi<30){
超重=正确;
System.out.println(“您超重”);
打破
}否则{
体重不足=正确;
System.out.println(“你体重不足”);
打破
}
}
字符串text4;
while(正常==真){
System.out.println(“你状态很好”);
println(“我可以向你推荐一份你可以用来维持当前体重的食物清单。”);
System.out.println(“您喜欢吗?”);
text4=input.next();
如果(text4.equals(“yes”)| text4.equals(“yes”)| text4.equals(“yes”)){
System.out.println(“好的,那么这是列表!”);
for(int i=0;i    Scanner input = new Scanner(System.in);

    System.out.println("Please input your name: ");
    name = input.nextLine();

    System.out.println("How many feet are you?: ");
    feet = input.nextInt();

    System.out.println("How many inches are you?: ");
    inches = input.nextInt();
    height = ((feet * 12) + inches); 
    System.out.println("Please enter your weight: ");
    weight = input.nextInt();

    System.out.println("Please enter your age: ");
    age = input.nextInt();


    System.out.println("Please specify your gender: ");
    gender = input.next();

    System.out.println("Please tell me about your activity status is it 
    sedentary, moderate or active? ");
    status = input.next();


    if(gender.equals("Male") && status.equals("sedentary")){
        calories = (10 * weight + 6.25 * height - 5 * age + 5) * 1.2;
        //Math.round(calories);
        System.out.println("You burn " + Math.round(calories) + " 
       calories everyday.");

    }else if(gender.equals("Male") && status.equals("moderate")){
        //calories = 10 * weight + 6.25 * height - 5 * age - 161;
        calories = (10 * weight + 6.25 * height - 5 * age + 5) * 1.55;
        System.out.println("You burn " + Math.round(calories) + " 
    calories everyday.");

    }else if(gender.equals("Male") && status.equals("active")){
        calories = (10 * weight + 6.25 * height - 5 * age + 5) * 1.725;
        System.out.println("You burn " + Math.round(calories) + " 
  calories everyday.");

    }else if(gender.equals("Female") && status.equals("sedentary")){
        calories = (10 * weight + 6.25 * height - 5 * age - 161) * 1.2;
        //Math.round(calories);
        System.out.println("You burn " + Math.round(calories) + " 
  calories everyday.");

    }else if(gender.equals("Female") && status.equals("moderate")){
        //calories = 10 * weight + 6.25 * height - 5 * age - 161;
        calories = (10 * weight + 6.25 * height - 5 * age - 161) * 1.55;
        System.out.println("You burn " + Math.round(calories) + " 
    }else if(gender.equals("Female") && status.equals("active")){
        calories = (10 * weight + 6.25 * height - 5 * age - 161) * 1.725;
        System.out.println("You burn " + Math.round(calories) + " 
  calories everyday.");

    }else{
        System.out.println("Invalid Gender or Activity status.");

    }





    bmi = (weight) / (height * height) * 703;


    if(age >= 18){
        launch = true;
        }else{

        System.out.println("You are not old enough to use this app");
        launch = false;
      }
     while(launch != false){
          if(bmi > 30 && bmi < 35){
              obese = true;
              System.out.println("You are obese");

              break;
            }else if(bmi > 35){
                xobese = true;
         System.out.println("You are dangerously obese");
         break;
          }else if(bmi < 25 && bmi > 18.5 ) {
              normal = true;
         System.out.println("You are normal weight");

         break;
         }else if(bmi > 25 && bmi < 30){

             overweight = true;
        System.out.println("You are overweight");  
        break;
         } else{

             underweight = true;
        System.out.println("You are underweight");
        break;
       }
    }
    String text4;
     while(normal == true){
     System.out.println("You are in good shape");
     System.out.println("I can recommend you a list of foods you could eat to maintain your current weight.");
     System.out.println("Would you like that? ");
     text4 = input.next();
        if(text4.equals("yes") || text4.equals("Yes") || text4.equals("YES")){
         System.out.println("Alright then here is the list!");
         for (int i =0; i < foodss.length; i ++){
          System.out.println(foodss[i]);
        }     
          break;
      }else{
        System.out.println("Ok thanks for using this app!!");
       break;
      }
    }

   String text;
    while(underweight == true){
    System.out.println("Looks like you are underweight");

    System.out.println("Do you want to gain weight fast or slow? ");
    text = input.next();
    if(text.equals("fast") || text.equals("FAST") || text.equals("Fast")){
        System.out.println("The amount of calories you should take everyday is " + Math.round(calories + 500) + " to gain weight"); 
        System.out.println("I am going to recommend you a 3500 calorie diet plan ");
        String output = "";
        for(int i =0; i < und.size(); i++){
        output = output + und.get(i);
        }
        System.out.println(output);
        break;
    } else{
        System.out.println("Thanks for using the app!.");
   }
   }

    String text1;
    while(overweight == true){
    System.out.println("Looks like you are overweight");
    System.out.println("Do you want to lose weight? ");
    text1 = input.next();
    if(text1.equals("yes") || text1.equals("Yes") || text1.equals("YES")){
        System.out.println("The amount of calories you should take everyday is " + Math.round(calories + 500) + " to gain weight"); 
        break;
    } 
    else{
        System.out.println("Oh well good luck with life.");
   }
   }

    String text2;
    while(obese == true){
    System.out.println("Looks like you are obese");
    System.out.println("Do you want to lose weight? ");
    text2 = input.next();
    if(text2.equals("yes") || text2.equals("Yes") || text2.equals("YES")){
        System.out.println("The amount of calories you should take everyday is " + Math.round(calories + 500) + " to gain weight"); 
        break;
    } else{
        System.out.println("Oh well good luck with life.");
   }
}
    String text3;
    while(xobese == true){
    System.out.println("Looks like you are dangerously obese");
    System.out.println("You should really consider losing weight or you will die!");
    System.out.println("But STILL do you wanna lose weight?");
    text3 = input.next();
    if(text3.equals("yes") || text3.equals("Yes") || text3.equals("YES")){
        System.out.println("The amount of calories you should take everyday is " + Math.round(calories + 500) + " to gain weight"); 
        break;
    } else{
        System.out.println("Oh well good luck with life.");
   }
   }

}

public static void addFoodsToListslow(ArrayList<obx> obx)
  {
      Food butteredtoast = new Food("1-slice Buttered Toast", Food.meal.BREAKFAST, 150);
      Food egg = new Food("1-Egg", Food.meal.BREAKFAST, 80);
      Food Almonds = new Food("27-Almonds", Food.meal.BREAKFAST, 170);
      Food banana = new Food("1-Large Banana", Food.meal.BREAKFAST, 90);
      Food Greekyogurt = new Food("1-cup Greekyogurt", Food.meal.BREAKFAST, 120);
      Food Blueberries = new Food("30-BlueBerries", Food.meal.BREAKFAST, 40);

      Food grilledchicken = new Food("8-oz Grilled Chicken", Food.meal.LUNCH, 225);
      Food Grilledvegetable = new Food("5 oz Grilled vegetable", Food.meal.LUNCH, 125);
      Food Pasta = new Food("1/2 cup Pasta", Food.meal.LUNCH, 185);

      Food Hummus = new Food("1-Dip Hummus", Food.meal.SNACK, 50);
      Food BabyCarrot = new Food("5-Baby Carrots", Food.meal.SNACK, 35);
      Food Crackers = new Food("5-Crackers", Food.meal.SNACK, 65);

      Food salmon = new Food("7-ozSalmon", Food.meal.DINNER, 225);
      Food brownrice = new Food("1-cup Brown Rice", Food.meal.DINNER, 175);
      Food greenbeans = new Food("1/2 cup Green Beans", Food.meal.DINNER, 100);

}
public static void addFoodsToListfast(ArrayList<Food> n)
  {
      Food cereal = new Food("1 serving-All-bran cereal", Food.meal.BREAKFAST, 125);
      Food milk = new Food("1cup-Milk", Food.meal.BREAKFAST, 50);
      Food banana = new Food("1-Large Banana", Food.meal.BREAKFAST, 90);

      Food cucumber = new Food("1-Large Cucumber", Food.meal.SNACK, 30);
      Food avocadodip = new Food("Avocado Dip", Food.meal.SNACK, 50);
      Food grilledcheese = new Food("Grilled Cheese with tomatoes", Food.meal.LUNCH, 300);
      Food salad = new Food("Salad", Food.meal.LUNCH, 50);

      Food Walnuts = new Food("10-Walnuts", Food.meal.SNACK, 100);

      Food grilledchicken = new Food("8oz Grilled Chicken", Food.meal.LUNCH, 225);
      Food BrusselSprouts = new Food("Brussel Sprouts", Food.meal.DINNER, 100);
      Food Quinoa = new Food("Quinoa", Food.meal.DINNER, 105);


}
public static void addFoodsToListmoderate(ArrayList<over> ov)
  {

      Food Granola = new Food("1 Bar Granola", Food.meal.BREAKFAST, 120);
      Food Greekyogurt = new Food("1 Cup Greekyogurt", Food.meal.BREAKFAST, 120);
      Food Blueberries = new Food("15-BlueBerries", Food.meal.BREAKFAST, 40);
      Food butteredtoast = new Food("1slice-Buttered Toast", Food.meal.BREAKFAST, 150);

      Food orange = new Food("1-Orange", Food.meal.SNACK, 70);

      Food chickenandveg = new Food("1-Cup Chicken and Vegetable Soup", Food.meal.LUNCH, 300);
      Food Bread = new Food("2-Slice Bread", Food.meal.LUNCH, 100);

      Food Apple = new Food("1-Apple", Food.meal.SNACK, 75);
      Food PeanutButter = new Food("Peanut Butter", Food.meal.SNACK, 75);

      Food Steak = new Food("5oz Steak", Food.meal.DINNER, 375);
      Food Mashedpotatoes = new Food("1-Cup Mashedpotatoes", Food.meal.DINNER, 150);
      Food Asparagus = new Food("Asparagus", Food.meal.DINNER, 75);


}
public static void addFoodsToListfour(ArrayList<under> und)
  {
      Food cereal = new Food("1-cup All-bran cereal", Food.meal.BREAKFAST, 125);
      Food milk = new Food("1-cup Milk", Food.meal.BREAKFAST, 50);
      Food banana = new Food("1-Large Banana", Food.meal.BREAKFAST, 90);
      Food Greekyogurt = new Food("1-Cup Greekyogurt", Food.meal.BREAKFAST, 120);
      Food Blueberries = new Food("40-BlueBerries", Food.meal.BREAKFAST, 200);

      Food egg = new Food("2-Egg", Food.meal.BREAKFAST, 160);
      Food Almonds = new Food("25-Almonds", Food.meal.BREAKFAST, 300);


      Food Bread = new Food("3-Slices Bread", Food.meal.LUNCH, 200);
      Food grilledchicken = new Food("10oz-Grilled Chicken", Food.meal.LUNCH, 225);
      Food Grilledvegetable = new Food("Grilled vegetable", Food.meal.LUNCH, 125);
      Food Pasta = new Food("1-Cup Pasta", Food.meal.LUNCH, 185);
      Food Apple = new Food("2-Apple", Food.meal.SNACK, 150);
      Food CheesePizza = new Food("2-Cheese Pizza", Food.meal.SNACK, 300);


      Food Steak = new Food("9oz-Steak", Food.meal.DINNER, 375);
      Food Mashedpotatoes = new Food("1cup-Mashedpotatoes", Food.meal.DINNER, 150);
      Food brownrice = new Food("1 Cup-Brown Rice", Food.meal.DINNER, 175);
      Food greenbeans = new Food("1Cup-Green Beans", Food.meal.DINNER, 100);


}
public static void addFoodsToListfast(ArrayList<Food> n) {

    Food cereal = new Food("1 serving-All-bran cereal", Food.meal.BREAKFAST, 125);
    n.add(cereal);
    //and so on
}