SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Stuart Reges, Marty Stepp
Chapter:
Conditional Execution
Exercise:
Programming Projects
Question:3 | ISBN:9780136091813 | Edition: 2

Question

Write a program that compares two college applicants. The program should prompt for each student’s GPA, SAT, and ACT exam scores and report which candidate is more qualified on the basis of these scores.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

PROGRAM CODE:

import java.util.Scanner;

public class CollegeApplicantComparison 
{
    public static void main(String[] args) 
   {
        // Create a Scanner object to read user input
        Scanner scanner = new Scanner(System.in);

        // Prompt for and read the GPA and exam scores for Applicant 1
        System.out.println("Applicant 1");
        System.out.print("Enter GPA: ");
        double gpa1 = scanner.nextDouble();
        System.out.print("Enter SAT score: ");
        int sat1 = scanner.nextInt();
        System.out.print("Enter ACT score: ");
        int act1 = scanner.nextInt();

        // Prompt for and read the GPA and exam scores for Applicant 2
        System.out.println("\nApplicant 2");
        System.out.print("Enter GPA: ");
        double gpa2 = scanner.nextDouble();
        System.out.print("Enter SAT score: ");
        int sat2 = scanner.nextInt();
        System.out.print("Enter ACT score: ");
        int act2 = scanner.nextInt();

        // Calculate total scores for each applicant using a weighted formula (GPA - 40%, SAT - 30%, ACT - 30%)
        double totalScore1 = 0.4 * gpa1 + 0.3 * sat1 + 0.3 * act1;
        double totalScore2 = 0.4 * gpa2 + 0.3 * sat2 + 0.3 * act2;

        // Compare the total scores and determine which applicant is more qualified
        String moreQualifiedApplicant;
        if (totalScore1 > totalScore2) {
            moreQualifiedApplicant = "Applicant 1";
        } else if (totalScore1 < totalScore2) {
            moreQualifiedApplicant = "Applicant 2";
        } else {
            moreQualifiedApplicant = "Both applicants have the same qualifications.";
        }

        // Output the comparison results
        System.out.println("\nComparison Results:");
        System.out.println("Applicant 1 Total Score: " + totalScore1);
        System.out.println("Applicant 2 Total Score: " + totalScore2);
        System.out.println("More Qualified Applicant: " + moreQualifiedApplicant);
    }
}

 

OUTPUT:

Applicant 1
Enter GPA: 3.8
Enter SAT score: 1450
Enter ACT score: 32

Applicant 2
Enter GPA: 3.9
Enter SAT score: 1520
Enter ACT score: 31

Comparison Results:
Applicant 1 Total Score: 1353.0
Applicant 2 Total Score: 1389.1
More Qualified Applicant: Applicant 2

 

0 0

Discussions

Post the discussion to improve the above solution.