• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

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

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 479
1
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 80954
522
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And why have you got all your methods static?
 
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't see exceptions being handled.
 
Campbell Ritchie
Marshal
Posts: 80954
522
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 326
Android Mac OS X Firefox Browser
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Whip out those weird instruments of science and probe away! I think it's a tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic