如何在布尔方法中使用PrintWriter作为参数

ninjakid56810

我正在尝试为我的布尔方法的参数中的输出文件使用PrintWriter。eclipse中的错误告诉我PrintWriter无法解析为变量。错误发生在if(!validgroup)...我是一个非常新手的编码人员,不久前就开始了。任何帮助或建议,将不胜感激。


 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;
 }
 
 
 }

艾略特新鲜

更改

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

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

另外,你是不是实际使用scoresOutputvalidGroup-所以目前尚不清楚为什么你添加它。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在输出中使用布尔方法打印返回类型?

在Java中使用布尔方法循环程序

用浮点数组和布尔值作为参数编写布尔方法

如何在Java中返回布尔方法?

如何在方法中使用获取的数据作为参数

如何在抽象方法中使用通用EnumMap作为参数

如何在扩展方法中使用函数作为参数?

如何在ruby中使用方法参数作为变量

在JavaScript中使用“布尔”作为.filter()的参数

使用带有“?”的布尔方法 算子

Mockito:使用when().. then()测试布尔方法

如何在布尔方法中抛出三个异常?

如何在Java中检查布尔方法的返回值

如何在布尔方法Java中导入文本文件

如何在Java中使用方法引用符号(Class :: method)将方法作为参数传递?

如何在onPause方法中使用将onCreate中的对象作为参数的方法

为没有参数的布尔方法编写Junit测试

如何使用测试驱动的开发方法来验证布尔方法?

我如何使用布尔方法从购物车中删除对象?

如何在Xunit中使用List <List <T>作为输入参数测试方法

如何在“跳转”方法中使用布尔值?

如何更改方法中布尔方法的值?

如何在方法中使用&proc参数

如何在 crontab 中使用文件内容作为参数

如何在函数中使用 dir() 作为默认参数

如何在新对象中使用参数作为键?

如何在函数中使用函数作为参数?

如何在switch语句中使用cin“作为参数”

如何在Python中使用Lambda作为日期时间参数