Write an application to be used in a college admission\'s office. To be admitted
ID: 3622985 • Letter: W
Question
Write an application to be used in a college admission's office. To be admitted to this school, the student must have either:•A grade point average of 3.0 or higher and an entrance score of 60 or higher
•An entrance score of 85 or higher and any grade point average
To make things more user friendly, write some code to do some error checking of the data. That is, if the grade point average is not between 0.0 and 4.0 or if the entrance score is not between 0 and 100, then print an appropriate error message to the screen telling the user that they entered invalid data.
Use the above criteria to write a procedure called, accepted, that takes the grade point average and entrance score as parameters and returns no value. This procedure will print either "Accept" or "Reject", accordingly.
Finally, write a main procedure that prompts the user for a grade point average and an entrance score. This procedure should then call the accepted method to display the result.
Explanation / Answer
import java.util.Scanner;
public class Admission
{
public static void main(String[] args)
{
// input
Scanner kb = new Scanner(System.in);
double gpa = -1;
while(true)
{
System.out.print("Enter the gpa: ");
try
{
gpa = kb.nextDouble();
}
catch(Exception ex)
{
System.out.println("Invalid GPA.");
}
if(gpa < 0.0 || gpa > 4.0)
{
System.out.println("Invalid GPA.");
}
else
{
break;
}
}
int score = -1;
while(true)
{
System.out.print("Enter the entrance exam score: ");
try
{
score = kb.nextInt();
}
catch(Exception ex)
{
System.out.println("Invalid score.");
}
if(score < 0 || score > 100)
{
System.out.println("Invalid score.");
}
else
{
break;
}
}
accepted(gpa, score);
}
public void accepted(double gpa, int score)
{
if(gpa >= 3.0 || score >= 60)
{
System.out.println("Accept");
}
else
{
System.out.println("Reject");
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.