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 integer 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
//Hope this code helps you
//If u still face any doubt feel free to ask in the comments
// I will be very happy to solve them
import java.util.*;
import java.util.Scanner;
public class Main
{
/* declaring variable for counting validGroups,Invalid and Total Groups*/
public int countValid=0,countInvalid=0,countTotal=0;
/*isItValidGroup funtion called in main function*/
public boolean isItValidGroup(int a,int b,int c)
{
if((a>=200 && a<=800 && a%10==0) && (b>=200 && b<=800 && b%10==0) && (c>=200 && c<=800 && c%10==0))
return true;
else
{
if(a<200 || a>800 || a%10!=0)
System.out.println(a+": Invalid Score");
if(b<200 || b>800 || b%10!=0)
System.out.println(b+": Invalid Score");
if(c<200 || c>800 || c%10!=0)
System.out.println(c+": Invalid Score");
return false;
}
}
/*classify will be called if group is found valid*/
/*So it is called inside if condition in main program*/
public void classify(int a,int b,int c)
{
rateoneScore(a);
rateoneScore(b);
rateoneScore(c);
int total=findTotalScore(a,b,c);
System.out.println("Total Score is "+total);
ratetheGroup(total,a,b,c);
}
/*rateoneScore will be for each score isnide classify*/
public void rateoneScore(int a)
{
/*setting the conditions*/
if(a<500)
System.out.println(a+":Below 500");
else if(a>=500 && a<800)
System.out.println(a+":More than 500 but less than 800");
else if(a==800)
System.out.println(a+":Perfect 800");
}
/*findTotalScore called in classify to calculate total*/
public int findTotalScore(int a,int b,int c)
{
int sum=0;
sum=a+b+c;
return sum;
}
/*called inside classify() to rate the groups*/
void ratetheGroup(int total,int a,int b,int c)
{
if(total>=2100 && a>=700 && b>=700 && c>=700)
System.out.println("Group is outstanding");
else if(total>=2100 && ((a>=700 && b>=700)||(a>=700 && c>=700)||(b>=700 && c>=700)))
System.out.println("Group is very good");
else if(total>=2100 && (a>=700 || b>=700 || c>=700))
System.out.println("Group is lop-sided");
else if(total<2100 && (a<500 && b<500 && c<500))
System.out.println("Group is weak");
else
System.out.println("Group is erratic");
}
public static void main(String[] args)
{
Main obj=new Main();
Scanner sc=new Scanner(System.in);
while(true)
{
System.out.println("Enter the SAT's Scores: ");
int score1=sc.nextInt();/*Input the scores*/
int score2=sc.nextInt();
int score3=sc.nextInt();
if(obj.isItValidGroup(score1,score2,score3)==true)
{
obj.countValid++;
System.out.println("Group is valid");
obj.classify(score1,score2,score3);/*if function is valid calling classify*/
}
else
{
obj.countInvalid++;
System.out.println("Group is Invalid");
}
obj.countTotal++;
System.out.println("Do tou want to continue,if Yes press 1 else press -1:");
int exit=sc.nextInt();
/*Output the total number of valid, invalid and total groups*/
if(exit==-1)
{
System.out.println("Number of valid groups in the set are "+obj.countValid);
System.out.println("Number of Invalid groups in the set are "+obj.countInvalid);
System.out.println("Number of Total groups in the set are "+obj.countTotal);
break;
}
}
}
}
SCREENSHOTS: