This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hi, I need to create a program that accepts user input for two applicants: either SAT or ACT scores, and then GPA. Then it will calculate and print a "score" based on given equations for each applicant and print out which applicant is the better choice.
I'm having trouble just thinking about the layout of my program; should I just have separate methods for test scores and GPA, and then have identical methods for the applicants?
And I also can't figure out how to use my returns properly for this purpose.
Any help and feedback is appreciated, thank you!
This is the majority of my program so far, and as you can see, it has a lot of parts that lead to nowhere as of now. I think the errors have something to do with my scanner first of all? And then... the returns.
1. You have the console variable as a static instance variable. But you have created another local variable console in your main() method. So when you think you have initialized the instance static variable console, the local variable is the one that gets initialized. So remove the declaration from the main() method.
2. The instance variables are common to all the methods. So you do not want to have them as method arguments.
3. Your methods testScore() and gpa() does not return anything but have been marked as returning int and double respectively.
Did you forget to copy paste the class declaration?
What instance variables? I can see no instance variables. In fact everything is static. That is usually a mistake. In fact, having a method for first scores and one for second scores suggests you are mistaken in your design.
What you want is a class which represents a pupil or similar. Then you set up two instances (if possible a 2-element array). Then you can call enterScores() methods and displayScores() methods on each. You want to avoid making everything static. You also need to learn about return types for methods; your gpa method says it returns a double, but returns nothing. The compiler won’t be happy with that.
Yes, there does appear to be code missing at the beginning of the post.
Joined: May 31, 2011
My earlier post states -
static instance variable
It's a mistake. A static variable(class variable) is different from the instance variable. Thanks Campbell for pointing that.
Joined: Oct 13, 2005
Closing thread because the discussion appears to continue here.