0

我收到错误:- 错误:找不到符号 tofile.println("Dancing" + " " + danceminutes + " " + bpm); ^ 符号:变量 tofile 位置:类 CreateFile

我不确定为什么。

  // writing to a file 
     PrintWriter toFile = new PrintWriter(new FileWriter("exLog.txt"));                     

     Random randy = new Random();
     int count = randy.nextInt(12) + 19;
     for (int i = count; i > 0; i--) {

        int exercise = randy.nextInt(3);

        if (exercise == 0) {
           int minutesOne = randy.nextInt(47) + 14;
           int minutesTwo = randy.nextInt(62) + 59;
           int minutesThree = randy.nextInt(122) + 119;
           int roulette = randy.nextInt(100);
           if (roulette <= 74) {
              int runoneminutes = minutesOne;
              double speed = 4.9 + (16.1 - 4.9) * randy.nextDouble();
              double distance = speed * runoneminutes/60;
              tofile.println("Running" + " " + runoneminutes + " " + distance);
           }
           else if (roulette > 74 && roulette < 96) {
              int runtwominutes = minutesTwo;
              double twospeed = 4.9 + (16.1 - 4.9) * randy.nextDouble();
              double twodistance = twospeed * runtwominutes/60;
              tofile.println("Running" + " " + runtwominutes + " " + twodistance);
           }
           else if (roulette >= 96) {
              int runthreeminutes = minutesThree;
              double threespeed = 4.9 + (16.1 - 4.9) * randy.nextDouble();
              double threedistance = threespeed * runthreeminutes/60;
              tofile.println("Running" + " " + runthreeminutes + " " + threedistance);
           }
        }

        if (exercise == 1) {
           int bikeminutesOne = randy.nextInt(62) + 29;
           int bikeminutesTwo = randy.nextInt(212) + 89;
           int bikeroulette = randy.nextInt(100);
           if (bikeroulette <= 49) {
              int bikeoneminutes = bikeminutesOne;
              double bikeonespeed = 7.9 + (25.1 - 7.9) * randy.nextDouble();
              double bikeonedistance = bikeonespeed * bikeoneminutes/60;
              tofile.println("Biking" + " " + bikeoneminutes + " " + bikeonedistance);
           }
           else if (bikeroulette > 49) {
              int biketwominutes = bikeminutesTwo;
              double biketwospeed = 7.9 + (25.1 - 7.9) * randy.nextDouble();
              double biketwodistance = biketwospeed * biketwominutes/60;
              tofile.println("Biking" + " " + biketwominutes + " " + biketwodistance);
           }
        }

        if (exercise == 2) {
           int exercises = randy.nextInt(15) + 1;
           int reps = randy.nextInt(37) + 9;
           double liftminutes;
           int liftminutes = 5*reps*exercises/60 + 2*(exercises-1);
           tofile.println("Lifting" + " " + liftminutes + " " + reps);
        }

        if (exercise == 3) {
           int danceminutes = randy.nextInt(90) + 29;
           double bpm = 79.9 + (220 - 79.9) * randy.nextDouble();
           tofile.println("Dancing" + " " + danceminutes + " " + bpm);
        }
     }


     toFile.close();  //saving output file          




  } // end main

} // 结束 CreateFile 类

4

1 回答 1

0

变量名称是 toFile。编译器抱怨使用“tofile”。

于 2013-03-13T15:24:09.480 回答