Question
import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.util.Scanner; public class hw5 { public static void main(String[] args) throws IOException { int score1,score2, score3,avg; int ch;
import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.util.Scanner;
public class hw5 { public static void main(String[] args) throws IOException { int score1,score2, score3,avg; int ch; File myFile = new File("myinput.txt"); //file object Scanner inputFile = new Scanner(myFile); //scanner function
PrintWriter outputFile = new PrintWriter("myoutput.txt"); //get score from user do{ System.out.println("Enter Score1: "); score1=inputFile.nextInt(); System.out.println("Enter Score2: "); score2=inputFile.nextInt(); System.out.println("Enter Score3: "); score3=inputFile.nextInt(); if(validgroup(score1,score2,score3,myFile)==false) //check for validation return ; //call the rating function onegamescore(score1); onegamescore(score2); onegamescore(score3); System.out.println(" Average Score: "); //for average avg=avg3scores(score1,score2,score3); //call average function onegamescore(avg); System.out.println("To stop enter 999, to continue enter any key: "); ch=inputFile.nextInt(); }while(ch!=999);
} //check for validation static boolean validgroup(int score1,int score2, int score3,File myFile) { if(score1<0){ System.out.println("Score 1 is less than 0"); return false; } if(score2<0){ System.out.println("Score 2 is less than 0"); return false; } if(score3<0){ System.out.println("Score 3 is less than 0"); return false; } if(score1>300){ System.out.println("Score 1 is greater than 300"); return false; } if(score2>300){ System.out.println("Score 2 is greater than 300"); return false; } if(score3>300){ System.out.println("Score 3 is greater than 300"); return false; } return true; }
//print the rating static void onegamescore(int score) { if(score >=250 && score<=300) System.out.println(score +" professional game"); if(score >=200 && score<=249) System.out.println(score +" excellent game"); if(score >=140 && score<=199) System.out.println(score +" very good game"); if(score >=100 && score<=139) System.out.println(score +" good game"); if(score >=50 && score<=99) System.out.println (score +" poor game"); if(score <50) System.out.println(score +" Horrible game");
}
//caluclate the average and return static int avg3scores(int score1,int score2, int score3) { return (score1+score2+ score3)/3; } }
HOW TO MAKE THIS OUTPUT TO BE FILE DIRECTED.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started