This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes How to return value back to main? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to return value back to main?" Watch "How to return value back to main?" New topic
Author

How to return value back to main?

Ashley Kin
Ranch Hand

Joined: Oct 18, 2011
Posts: 36
Hi, this program takes user input for two applicants and assigns them scores based on SAT/ACT scores and GPA. For the test scores portion, I'm having trouble returning one final score back to main.
Someone suggested setting score = inputSATScore(console); but then what would happen if it were an ACT score?
Any help is appreciated, thank you!
(And sorry, but I can't figure out how to use clipboard to post my code).

public static double testScore(Scanner console)
{
System.out.print("do you have 1) SAT scores or 2) ACT scores?");
int test = console.nextInt();
double score = 0
if (test==1)
{
inputSATScore(console);
}
else{
inputACTScore(console);
}
return score;
}

public static double inputSATScore(Scanner console)
{
System.out.print("SAT math?");
double math = console.nextDouble();

System.out.print("SAT verbal?");
double verbal = console.nextDouble();

double score = (2 * verbal + math)/24;

return (double) score;
}

public static double inputACTScore(Scanner console)
{
System.out.print("ACT English?");
double English = console.nextDouble();

System.out.print("ACT math?");
double math = console.nextDouble();

System.out.print("ACT reading?");
double reading = console.nextDouble();

System.out.print("ACT science?");
double science = console.nextDouble();

double score = (2 * reading + English + math + science)/1.8;

return (double) score;
}
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3432
    
  12
Ashley Kin wrote:Someone suggested setting score = inputSATScore(console); but then what would happen if it were an ACT score?

You make the same change (i.e put 'score = ' at the start) to the inputACTScore(console) line.


Joanne
Carey Brown
Ranch Hand

Joined: Nov 19, 2001
Posts: 174

Did you mean:
double score = (2 * (verbal + math))/24;
 
 
subject: How to return value back to main?
 
Similar Threads
Having trouble organizing the layout of my program?
Getting rid of redundancy?
How should I split up this big method? Still need help please!
Trying to get rid of redundancy?
Please help