java中的方法(等级计算器) [英] Methods in java (grade calculator)
问题描述
我们一直在学习java中的方法(使用netbeans),我仍然对使用方法感到困惑。一个功课问题基本上要求使用方法设计一个等级计算器,方法是提示用户输入标记,最大标记,加权测试然后产生该测试的最终得分。
例如。 (35/50)* 75%=整体分数
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 calculator using methods by prompting the user for a mark, the max mark possible, the weighting of that test and then producing a final score for that test. eg. (35/50)*75% = overall mark
然而,我正在努力使用方法,我想知道是否有人可以指出我正确的方向为什么我的代码下面有一些错误,不运行?我不想要任何完整的答案,因为我想尝试尽我所能,而不是抄袭。任何帮助将不胜感激 :)! (也许很好,因为我是编程的新手,我不是很好)
谢谢!
However, I am struggling to use methods and I was wondering if someone could point me in the right direction as to why my code below has some errors and doesn't run? I don't want any full answers because I would like to try and do it best on my own and not plagiarise. Any help would be greatly appreciated :)! (Also pls be nice because I am new to programming and I'm not very good) Thanks!
import java.util.Scanner;
public class gradeCalc
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
scoreCalc();
System.out.print("Your score is" + scoreCalc());
}
public static double scoreCalc (int score1, int maxMark, double weighting, double finalScore)
{
Scanner in = new Scanner(System.in);
System.out.print("Enter mark");
in.hasNextInt();
score1 = in.nextInt();
System.out.print("Enter Max mark");
in.hasNextInt();
maxMark = in.nextInt();
System.out.print("Enter weighting as a decimal (eg. 75% = 0.75)");
in.hasNextInt();
weighting = in.nextInt();
finalScore = (score1/maxMark)* weighting;
return finalScore;
}
}
推荐答案
你正在调用您的方法 scoreCalc()
而不传递您定义的参数。
当你打电话时,它被定义为有3个参数。
You are calling your method scoreCalc()
without passing the parameters you defined.
When you are calling it, it was defined as having 3 parameters.
scoreCalc(7, 10, 3.0, 8.0);
此外,创建类时,请使用大写字母 GradeCalc
Also, when creating a class, start it with upper case, GradeCalc
这篇关于java中的方法(等级计算器)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!