We\'ve been learning about methods in java (using netbeans) in class and I\'m still a bit confused about using methods. One homework question basically asks to design a grade ca
Some mistakes/errors to point out are:-
1) You do not need this statement Scanner in = new Scanner(System.in);
in your main()
, as you are not taking input from user through that function.
2) Your function scoreCalc (int score1, int maxMark, double weighting, double finalScore)
takes parameters, for example its call should look like scoreCalc(15, 50, 1.5, 2.7)
, but you are calling it as scoreCalc()
, that is without paramters from main()
.
Edit:- There is one more serious flaw in your program, which might work , but is not good coding. I wont provide code for it , and will leave implementation to you. Take input from user in the main()
(using scanner
) , assign the result to a temp variable there, and then pass that variable as parameter to the function scoreCalc()
//pseudocode in main()
Scanner in = new Scanner(System.in);
int score= in.nextInt();
.
.
.
scoreCalc(score,...);
Or you can make your scoreCalc function without parameters, and take user input in it (like present), and finally return just the result to main()
.
Both approaches seem appropriate and you are free to choose :)