0

次のエラーが表示されます:- error: cannot find symbol 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 に答える