This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes How should I split up this big method? Still need help please! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How should I split up this big method? Still need help please!" Watch "How should I split up this big method? Still need help please!" New topic
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: 443
    
    1

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: 10489
    
    9

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.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39478
    
  28
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: 39478
    
  28
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: 3720
    
  16
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How should I split up this big method? Still need help please!