Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How should I split up this big method? Still need help please!

 
Ashley Kin
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 445
1
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I would split the code into:



And call the appropriate methods from testScore() method.

Cheers,
Raj.
 
Ashley Kin
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11070
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49460
64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And why have you got all your methods static?
 
Harsha Smith
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see exceptions being handled.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49460
64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What Exceptions? If you use a Scanner, why bother with Exception handling?
 
Harsha Smith
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 326
Android Firefox Browser Mac OS X
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic