In: Computer Science
Write a complete Java program, including comments in each method and in the main program, to do the following:
Outline: The main program will read in a group of three int||eger values which represent a student's SAT scores. The main program will call a method to determine if these three scores are all valid--valid means in the range from 200 to 800, including both end points, and is a multiple of 10 (ends in a 0).
If the scores are all valid, the main program will call a method (which will itself call other methods) to classify the group of three scores in various ways. The main program will repeat this process for the entire set of data, then print some counters. To detect end of data you may use the trailer method, using a special combination of data values as a trailer, or the user response method (“Do you want to continue?”)
Details (describing the main program and then each method):
Main Program:
The main program will read in and print three integer values, representing SAT scores.
Then the main program will call the method isitavalidgroup() to determine whether or not this group is valid. In either case, the main program will print the result of the method call (and add to the appropriate counter – discussed below).
In more detail: If the method isitavalidgroup() says this is a valid group, the main program will print a message, add to the counter of valid groups, and call the method classify().
However, if isitavalidgroup() says the group is not valid, the main program will print a message, add to the counter of invalid groups, and go back to read the next group.
Be sure to skip a few lines on the output sheet between groups.
(And somewhere add to the counter of total groups.)
The main program will continue this process for the entire set of data. When the main program runs out of groups of three values (you must decide when this occurs), print the final values of three counters: the total number of groups processed, how many groups were valid, and how many groups were invalid.
Use three separate counters. Do not compute one from the others.
STYLE: Each method described below should have a good comment explaining its role in the program and what parameter(s) it will receive. If the method calls another method, the comment should say this.
Methods:
1. Write a method isitavalidgroup() which will receive three parameters (plus the PrintWriter*). For each parameter value which is invalid (invalid means less than 200 or more than 800 or not a multiple of 10), the method will print the invalid value. The method will return true if all three values are valid, i.e. in the range from 200 to 800 and a multiple of 10; otherwise it will return false.
2. Write a method classify() which will receive three parameters (at this point, they must be valid values). This method will call the three methods described below, as follows.
Using the method ratesonescore(), classify() will rate each of the three scores, one at a time. There will be three calls to this method, one for each score.
Then classify() will use the method findtotalscore() to find the total of the three scores.
Then classify() will use the method ratethegroup() to rate the three scores and the total together. Finally, classify() will return to the main program.
3. Write a method rateonescore() which will receive one parameter (+ PrintWriter) representing a valid SAT score. The method will determine which of the following three categories the score is in: less than 500, 500 or more but less than 800, or 800 (perfect score). Note this method gets one parameter.
The method will print a message indicating which of these three categories occurred.
4. Write a method findtotalscore() which will receive three parameters, representing the three scores. The method will determine the total score, which is simply the sum of the three scores. The method will return the total score. (Somewhere it should be printed.)
5. Write a method ratethegroup() which will receive four parameters: the three scores and their total (+ the PrintWriter). The method will determine the group status, as follows:
· If the total score is 2100 or above, and the score on each part is 700 or above, the group status is "outstanding";
· if the total score is 2100 or above, and exactly two of the individual scores are 700 or above, the group status is "very good";
· if the total score is 2100 or above, and exactly one individual score is 700 or above, the group status is "lop-sided";
NOTE: the three conditions above should all be grouped by total is 2100 or above
· if the total score is less than 2100, and no individual score is 500 or above, the group status is "weak";
· otherwise (if no condition described above is true), the group status is "erratic".
In all cases, the method will print the group status.
DATA: You will be judged on the quality of your data. Include at least 25 groups, but not necessarily 25! (Your program doesn’t know beforehand how many groups it will process) Include at least 6 invalid groups (spread them through the entire set of data), two with just one invalid (one with score out of range, one with score not a multiple of 10), two groups with two invalids, and two with all three invalids. Also have some in the correct range but not multiple of 10. Have some values below 200, some at 200, some at 800, some above 800, and some exactly 500.
For the valid groups (have at least 18-20), make sure that the ratethegroup() method prints each possible status every way that status can occur. Be sure the validset() method tests each boundary value (199, 200, 201, 799, 800, and 801) at least once.
For the first 3 sets of data use the following:
200 400 600
550 800 650
150 660 455
You may use interactive data entry or an input file for data.
*You must print all output (except for prompts) to an output file. Submit that file with your program. If you are printing in a method be sure to pass the PrintWriter object as a parameter in addition to the parameters enumerated above.
You will submit 2 things: the program code, sent as a java file attachment, and the results printed to the output file (PrintWriter). In addition, if you are using interactive data entry (System.in), provide me with a separate file containing the data values you used. You do not need to send the actual console output.
See next page for sample output,
Sample output:
Scores: 200 400 600
Group is valid
200: Below 500
400: Below 500
600: More than 500 but less than 800
Total score: 1200
Group is erratic
Scores: 150 660 455
Invalid score: 150
Invalid score: 445
Group is invalid
// The code for the above problem is given below with screenshots for the indentation and output
// and if you feel any problem then feel free to ask
// importing java.io.* for using PrintWriter and scanner for taking input from the user
import java.io.*;
import java.util.Scanner;
// defining the class named SATscore
public class SATscore
{
// creating an object wr of PrintWriter class
static PrintWriter wr = new PrintWriter(System.out);
// defining isitvalidgroup function to return true for valid and false for invalid
// also printing the valid or invalid individual score according to the given conditions
public static boolean isitavalidgroup(int v1, int v2, int v3, PrintWriter wr)
{
boolean flag = true;
if(v1<200 || v1>800 || v1%10!=0)
{
wr.println("Invalid score: "+v1);
flag=false;
}
if(v2<200 || v2>800 || v2%10!=0)
{
wr.println("Invalid score: "+v2);
flag=false;
}
if(v3<200 || v3>800 || v3%10!=0)
{
wr.println("Invalid score: "+v3);
flag=false;
}
return flag;
}
//defining a classify function which calls different function and categorises the groups
public static void classify(int v1, int v2, int v3)
{
int totalScore;
ratesonescore(v1, wr);
ratesonescore(v2, wr);
ratesonescore(v3, wr);
totalScore = findtotalscore(v1,v2,v3);
ratethegroup(v1,v2,v3,totalScore,wr);
}
// function to rate one score according to the conditions
public static void ratesonescore(int score,PrintWriter wr)
{
if(score<500)
{
wr.println(score+": Below 500");
}
if(score<800 && score>=500)
{
wr.println(score+": More than 500 but less than 800");
}
if(score==800)
{
wr.println(score+": Perfect score");
}
}
// function to return total score of the group to classify function
public static int findtotalscore(int v1, int v2, int v3)
{ int totalSum = v1+v2+v3;
return totalSum;
}
// function to rate the group or categorise it based on the total and individual score
// according to the given conditions
public static void ratethegroup(int v1, int v2, int v3,int totalScore, PrintWriter wr)
{
wr.println("Total Score: "+totalScore);
if(totalScore>=2100)
{
if(v1>=700 && v2>=700 && v3>=700)
wr.println("Group is outstanding");
else if(v1>=700 && v2>=700 ||v3>=700 && v2>=700||v1>=700 && v3>=700)
wr.println("Group is very good");
else
wr.println("Group is lop-sided");
}
else if(totalScore<2100 &&(v1<500 && v2<500 && v3<500) )
{
wr.println("Group is weak");
}
else
{
wr.println("Group is erratic");
}
}
// main program or method which takes input and calls the necessary functions
public static void main(String[] args)
{
// declaring the required variables
String choice;
int totGroups=0,valGroups=0,invalGroups=0;
int v1,v2,v3;
//creating an obect of scanner to take input from user
Scanner input = new Scanner(System.in);
// using do-while loop to ask the user to continue or not
do{
// asking the user for scores
wr.print("\nEnter the scores for the group: ");
wr.flush();
v1 = input.nextInt();
v2 = input.nextInt();
v3 = input.nextInt();
// printing the entered scores
wr.println("\nScores: "+v1+" "+v2+" "+v3);
// if group is valid calling classify and increasing the count of valid groups by one
// and printing group is valid and if invalid then increased the count for invalid
// groups by one and printing the group is invalid
if(isitavalidgroup(v1,v2,v3,wr))
{
wr.println("Group is valid");
valGroups++;
classify(v1,v2,v3);
wr.flush();
}
else
{
wr.println("Group is invalid");
invalGroups++;
wr.flush();
}
// asking the user to continue or not
wr.print("\nDo you want to continue(y/n): ");
wr.flush();
choice = input.next();
// incrementing the total group count
totGroups++;
}while(choice.charAt(0)=='y'||choice.charAt(0)=='Y');
// after the scores of all the groups are entered the program prints the total number of groups,
// invalid groups and valid groups
wr.println("Total Groups: "+totGroups+"\nValid Groups: "+valGroups+"\nInvalid Groups: "+invalGroups);
wr.flush();
// closing the object of scanner to prevent memory leaks
input.close();
}
}
OUTPUT:- Here I have only used sample data but it works for as many groups