Taking Input
import java.util.Scanner;
* MIT170671.java : a program that prompts the user for information about two
* applicants and that computes an overall score for each applicant
public class MIT170671 {
* Method to take the input from the user and returns the total exam score
* for SAT exam
* @param scan
* scanner object to take the input
* @return exam score for SAT exam
public static double getSatScore(Scanner scan) {
System.out.print(“SAT Math? “);
int math = scan.nextInt();
System.out.print(“SAT verbal? “);
int verbal = scan.nextInt();
System.out.print(“overall GPA? “);
double overallGPA = scan.nextDouble();
System.out.print(“max GPA? “);
double maxGPA = scan.nextDouble();
double satScore = MIT170671.calculateSATScore(verbal, math);
double gpaScore = MIT170671.calculateGPA(maxGPA, overallGPA);
return (satScore + gpaScore);
* Method to take the input from the user and returns the total exam score
* for ACT exam
* @param scan
* scanner object to take the input
* @return exam score for ACT exam
public static double getActScore(Scanner scan) {
System.out.print(“ACT English? “);
int english = scan.nextInt();
System.out.print(“ACT Math? “);
int math = scan.nextInt();
System.out.print(“ACT reading? “);
int reading = scan.nextInt();
System.out.print(“ACT science? “);
int science = scan.nextInt();
System.out.print(“overall GPA? “);
double overallGPA = scan.nextDouble();
System.out.print(“max GPA? “);
double maxGPA = scan.nextDouble();
double actScore = MIT170671.calculateACTScore(english, math, reading, science);
double gpaScore = MIT170671.calculateGPA(maxGPA, overallGPA);
return (actScore + gpaScore);
* To calculate the SAT score using the given condition.
* @param verbal
* marks of verbal subject
* @param math
* marks of math subject
* @return calculated SATScore
public static double calculateSATScore(int verbal, int math) {
return (double) (((2 * verbal) + math) / 24.0);
* To calculate the ACT score using the given condition.
* @param english
* marks of english subject
* @param math
* marks of math subject
* @param reading
* marks of reading
* @param science
* marks of science subject
* @return calculated ACTScore
public static double calculateACTScore(int english, int math, int reading, int science) {
return (double) (((2 * reading) + english + math + science) / 1.8);
* To calculate the GPA score using the given condition.
* @param maxGPA
* maximum GPA
* @param overallGPA
* GPA provided by the user
* @return calculated GPAScore
public static double calculateGPA(double maxGPA, double overallGPA) {
return (overallGPA / maxGPA) * 100;
* This method will compare the scores that are passed as arguments and
* prints the corresponding output in the console.
* @param firstApplicantScore
* score of the first applicant
* @param secondApplicantScore
* score of the second applicant
public static void compareScore(double firstApplicantScore, double secondApplicantScore) {
if (firstApplicantScore > secondApplicantScore) {
System.out.println(“The first applicant seems to be better”);
} else if (firstApplicantScore < secondApplicantScore) {
System.out.println(“The second applicant seems to be better”);
} else {
System.out.println(“The two applicants seem to be equal”);
* To get the first Applicant score. Based on the choice, the corresponding
* method is invoked either SAT or ACT.
* @param scan
* scanner object to take the input
* @return score of the first applicant
public static double getFirstApplicantScore(Scanner scan) {
double firstApplicantScore = 0;
System.out.print(“nInformation for the first applicant:” + “ndo you have 1) SAT scores or 2) ACT scores?”);
int choice = scan.nextInt();
if (choice == 1) {
firstApplicantScore = MIT170671.getSatScore(scan);
} else if (choice == 2) {
firstApplicantScore = MIT170671.getActScore(scan);
return firstApplicantScore;
* To get the second Applicant score. Based on the choice, the corresponding
* method is invoked either SAT or ACT.
* @param scan
* scanner object to take the input
* @return score of the second applicant
public static double getSecondApplicantScore(Scanner scan) {
double secondApplicantScore = 0;
System.out.print(“nInformation for the second applicant:” + “ndo you have 1) SAT scores or 2) ACT scores?”);
int choice = scan.nextInt();
if (choice == 1) {
secondApplicantScore = MIT170671.getSatScore(scan);
} else if (choice == 2) {
secondApplicantScore = MIT170671.getActScore(scan)
return secondApplicantScore;
* Execution begins here. First and second applicant scores are calculated
* and printed on the console.
* @param args
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
double firstApplicantScore = MIT170671.getFirstApplicantScore(scan);
double secondApplicantScore = MIT170671.getSecondApplicantScore(scan);
System.out.println(“nFirst applicant overall score = ” + firstApplicantScore);
System.out.println(“Second applicant overall score = ” + secondApplicantScore);
MIT170671.compareScore(firstApplicantScore, secondApplicantScore)
References:
[1] K. Sierra and B. Bates, Head First Java, 1st ed. Sebastopol: O’Reilly Media, Inc., 2008.
[2] H. Schildt, Java: The Complete Reference, 9th ed. McGraw-Hill education, 2017.