私はこのプログラムをjgraspで作成していますが、エラーが発生しています。私は私のプログラムのスペルや文法をチェックしており、正しいと思われます。私を助けてください - 私はすべてのエラーを引き起こしている欠けているものがありますか?Javaプログラムはコンパイルされません
import javax.swing.*;
public class Testscore
{
public static void main(String[] args)
{
int numberofTests = 0;
double grade = new double[numberofTests];
double startgrade = 0;
int x = 1 ;
String strInput;
// Get how many tests are used
strInput = JOptionPane.showInputDialog(null, "How many tests do you have? ");
numberofTests = Integer.parseInt(strInput);
grade = new double[(int) numberofTests];
do
{
for (int index = 0; index < grade.length; index++)
{
strInput = JOptionPane.showInputDialog(null, "Enter Test Score." + (index + 1));
grade = Double.parseDouble(strInput);
if (grade[index] < 0 || grade[index] > 100)
{
try
{
throw new InvalidTestScore();
x=2;
}
catch (InvalidTestScore e)
{
e.printlnStackTrace();
system.out.println ("Choose a test score between 0 and 100");
}
}
}
}
while (x==1);
for (int index = 0; index < grade.length; index++)
{
startgrade += grade[index];
}
average = startgrade/grade.length;
System.out.print("The average is: " + average);
}
}
ここではエラーが発生しています。 12行目
Testscore.java:12: incompatible types
found : double[]
required: double
double grade = new double[numberofTests];
^
Testscore.java:25: incompatible types
found : double[]
required: double
grade = new double[(int) numberofTests];
^
Testscore.java:30: double cannot be dereferenced
for (int index = 0; index < grade.length; index++)
^
Testscore.java:35: array required, but double found
if (grade[index] < 0 || grade[index] > 100)
^
Testscore.java:35: array required, but double found
if (grade[index] < 0 || grade[index] > 100)
^
Testscore.java:39: cannot find symbol
symbol : class InvalidTestScore
location: class Testscore
throw new InvalidTestScore();
^
Testscore.java:43: cannot find symbol
symbol : class InvalidTestScore
location: class Testscore
catch (InvalidTestScore e)
^
Testscore.java:46: package system does not exist
system.out.println ("Choose a test score between 0
and 100");
^
Testscore.java:53: double cannot be dereferenced
for (int index = 0; index < grade.length; index++)
^
Testscore.java:56: array required, but double found
startgrade += grade[index];
^
Testscore.java:59: cannot find symbol
symbol : variable average
location: class Testscore
average = startgrade/grade.length;
^
Testscore.java:59: double cannot be dereferenced
average = startgrade/grade.length;
^
Testscore.java:61: cannot find symbol
symbol : variable average
location: class Testscore
System.out.print("The average is: " + average);
^
13 errors
あなたはそのプログラムですが、それだけではありませんか?これは深刻な音...あなたはあなたの質問から "宿題"タグを忘れていないと確信していますか? –
変更する必要があります。さもなければ、それは常にそうしません。 – kcoppock