Okay, I'm having a problem with this java program. It's supposed to compare two applicants based on either their SAT/ACT scores and their GPA. It puts the SAT/ACT scores out of 100 and same for the GPA, and it should add them together to get a score out of 200, but it never adds them together. It's pretty annoying too because I know it's probably due to a dumb error.
Edit: The 'final' version is in my other post.
When I get back to my desk later I will get to writing a fixed version for you... Just a question, is there a reason that you are using System.out instead of JFrames or similiar?
We are limited in what we can use, we can only use up to what we've been taught. The only thing I need to know now is if there are any redundancies.
[code]
// This program compares two applicants to determine which one seems like the stronger applicant.
import java.util.*;
public class Admit {
public static void main(String[] args) {
intro();
Scanner console = new Scanner(System.in);
double test1 = getScore(console, 1);
double gpa1 = pGpa(console);
double score1 = overall(gpa1, test1);
double test2 = getScore(console, 2);
double gpa2 = pGpa(console);
double score2 = overall(gpa2, test2);
reportResults(score1, score2);
}
// Describes the program to the user.
public static void intro() {
System.out.println("This program compares two applicants to");
System.out.println("determine which one seems like the stronger");
System.out.println("applicant. For each candidate I will need");
System.out.println("either SAT or ACT scores plus a weighted GPA.");
System.out.println();
}
// Prompts the user for each person's scores and gpa, and returns their total scores.
// The int x displays the applicant's number.
public static double getScore(Scanner console, int x) {
System.out.println("Information for applicant #" + x + ":");
System.out.print(" do you have 1) SAT scores or 2) ACT scores? ");
String response = console.next();
if (response.equals("1")) {
return pSat(console);
} else { // ACT
return pAct(console);
}
}
// Prompts SAT scores, calls SATCalc to calculate them out of 100, and returns the SAT variable (sat).
public static double pSat(Scanner console) {
System.out.print(" SAT math? ");
double math = console.nextDouble();
System.out.print(" SAT critical reading? ");
double reading = console.nextDouble();
System.out.print(" SAT writing? ");
double writing = console.nextDouble();
double sat = SATCalc(math, reading, writing);
score(sat);
return sat;
}
// Prompts ACT scores, calls ACTCalc to calculate them out of 100, and returns the ACT variable (act).
public static double pAct(Scanner console) {
System.out.print(" ACT English? ");
double English = console.nextDouble();
System.out.print(" ACT math? ");
double actmath = console.nextDouble();
System.out.print(" ACT reading? ");
double actreading = console.nextDouble();
System.out.print(" ACT science? ");
double science = console.nextDouble();
double act = ACTCalc(English, actmath, actreading, science);
score(act);
return act;
}
// Prints the exam score, either SAT or ACT.
public static void score(double test) {
System.out.print(" exam score = ");
System.out.println(round(test));
}
// Prompts for overall GPA and max GPA, calls GPACalc to calculate them out of 100, and returns the GPA variable (gpa).
public static double pGpa(Scanner console) {
System.out.print(" overall GPA? ");
double ogpa = console.nextDouble();
System.out.print(" max GPA? ");
double mgpa = console.nextDouble();
System.out.print(" Transcript Multiplier? ");
double tm = console.nextDouble();
double gpa = GPACalc(ogpa, mgpa, tm);
System.out.print(" GPA score = ");
System.out.println(round(gpa));
System.out.println();
return gpa;
}
// Calculates SAT scores and puts the value into sat.
public static double SATCalc(double math, double reading, double writing) {
return (2 * math + reading + writing) / 32;
}
// Calculates ACT scores and puts the value into act.
public static double ACTCalc(double English, double actmath, double actreading, double science) {
return (English + (2 * actmath) + actreading + science) / 1.8;
}
// Calculates GPA scores and puts the value into gpa.
public static double GPACalc(double ogpa, double mgpa, double tm) {
return (ogpa / mgpa) * 100.0 * tm;
}
// Calculates overall score for each applicant.
public static double overall(double gpa, double test) {
return gpa + test;
}
// Reports the scores of the applicants and compares them
public static void reportResults(double score1, double score2) {
System.out.println("First applicant overall score = " + round(score1));
System.out.println("Second applicant overall score = " + round(score2));
if (score1 > score2) {
System.out.println("The first applicant seems to be better");
} else if (score1 < score2) {
System.out.println("The second applicant seems to be better");
} else { // If they are both equal
System.out.println("The two applicants seem to be equal");
}
}
// Rounds the overall scores to the first digit after the decimal point
public static double round(double n) {
return Math.round(n * 10.0) / 10.0;
}
}
[/code]
Sorry, you need to Log In to post a reply to this thread.