| Author |
How should I split up this big method? Still need help please!
|
Ashley Kin
Ranch Hand
Joined: Oct 18, 2011
Posts: 36
|
|
Hi, I'm writing a code to decide which of two applicants is the better pick based on their test scores, SAT or ACT.
I have this one huge method that has the user input which test they took, their scores, and calculates a "score" base on this information.
I pasted the method below, and I'd really appreciate any help about how to split it up into maybe SAT and ACT methods? Thanks!
|
 |
Rajkamal Pillai
Ranch Hand
Joined: Mar 02, 2005
Posts: 434
|
|
Hello,
I would split the code into:
And call the appropriate methods from testScore() method.
Cheers,
Raj.
|
 |
Ashley Kin
Ranch Hand
Joined: Oct 18, 2011
Posts: 36
|
|
Okay so I rewrote my code like this, but I'm having trouble returning one final score back to the main method. Thanks for any help!
|
 |
Maneesh Godbole
Saloon Keeper
Joined: Jul 26, 2007
Posts: 8438
|
|
In future, while posting code, please UseCodeTags. I have added them for you this time. As you can see, it makes the code much more easier to read and understand.
Your methods return the value, but you don't catch it. Change to
When this call returns, the value returned by inputSATScore(console) will be assigned to the score variable.
|
[Donate a pint, save a life!] [How to ask questions] [Onff-turn it on!]
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32689
|
|
|
And why have you got all your methods static?
|
 |
Harsha Smith
Ranch Hand
Joined: Jul 18, 2011
Posts: 287
|
|
|
I don't see exceptions being handled.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32689
|
|
|
What Exceptions? If you use a Scanner, why bother with Exception handling?
|
 |
Harsha Smith
Ranch Hand
Joined: Jul 18, 2011
Posts: 287
|
|
at the prompt, if the user innocently enters a string or something that's not int. The program will throw InputMismatchException
|
 |
Ove Lindström
Ranch Hand
Joined: Mar 10, 2008
Posts: 326
|
|
Harsha Smith wrote:
at the prompt, if the user innocently enters a string or something that's not int. The program will throw InputMismatchException
Premature optimization it the root to all evil.
Start with assuming that the user is a friendly one and does what is supposed... First we take Manhattan, then we take Exception.
|
 |
Ashley Kin
Ranch Hand
Joined: Oct 18, 2011
Posts: 36
|
|
Your methods return the value, but you don't catch it. Change to
When this call returns, the value returned by inputSATScore(console) will be assigned to the score variable.
How would I set the value score = inputACTScore then? And thanks for the help!
|
 |
Joanne Neal
Rancher
Joined: Aug 05, 2005
Posts: 3011
|
|
Ashley Kin wrote:Your methods return the value, but you don't catch it. Change to
When this call returns, the value returned by inputSATScore(console) will be assigned to the score variable.
How would I set the value score = inputACTScore then? And thanks for the help!
Answered here
|
Joanne
|
 |
 |
|
|
subject: How should I split up this big method? Still need help please!
|
|
|