简体   繁体   中英

How to use PrintWriter as a parameter in a boolean method

I am trying to use a PrintWriter to my output file in my parameter for my boolean method. The error in eclipse tells me that PrintWriter cannot be resolved to a variable. The error occurs at if(!validgroup)... I am a very novice coder and started not too long ago. Any help or suggestions would be greatly appreciated.


 import java.io.*;
 import java.util.*;
 
 public class BowlingScores {
     public static void main(String args[]) throws IOException{
     
     File myFile = new File("scoresInput.txt"); // Making a new .txt file for input

     Scanner inputFile = new Scanner(myFile); // Letting it read the file

     PrintWriter outputFile = new PrintWriter("scoresOutput.txt"); // Creating the .txt output file

     
     int score1, score2, score3, totalGroups = 1;
     
     
     score1 = inputFile.nextInt();
     
     while(score1 != -999) {
         score2 = inputFile.nextInt();
         score3 = inputFile.nextInt();
          
         
         
         outputFile.print("Score 1: " + score1 + "   ");
         outputFile.print("Score 2: " + score2 + "    ");
         outputFile.print("Score 3: " + score3 + "   \n\n\n");
         score1 = inputFile.nextInt();
         
         outputFile.println("Total number of groups processed: " + totalGroups);
         
         totalGroups++;
         
         
         if(!validGroup(score1, score2, score3, PrintWriter)) {
             outputFile.println("Group is invalid");
         }
         
         
     }

     
     
     
     inputFile.close();
     outputFile.close();
 }
 
 public static boolean validGroup(int score1, int score2, int score3, PrintWriter scoresOutput) {
     boolean validGroup = true;
     
     
     
     if(score1 > 300 && score1 < 0) {
         validGroup = false;
     }
     
     if(score2 > 300 && score2 < 0) {
         validGroup = false;
     }
     
     if(score3 > 300 && score3 < 0) {
         validGroup = false;
     }
     
     
     
     
     
     
     
     return validGroup;
 }
 
 
 }

Change

if(!validGroup(score1, score2, score3, PrintWriter)) {

to

if(!validGroup(score1, score2, score3, outputFile)) {

Also, you aren't actually using scoresOutput in validGroup - so it isn't clear why you added it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM