ここでかなり苦労している課題があります。これはループに基づく割り当てで、私には少しぼやけています。割り当ては次のとおりです。
- 生徒の名前を聞いてください。
- コース名を尋ねます (0 未満は不可 --> 0 未満の場合はエラー メッセージ)。
- 提出した課題の数を尋ねます。
- #3 に基づいて、可能な合計ポイントや獲得したポイントなどのいくつかの質問をして、進捗レポートを生成します。
#4の冒頭部分以外は苦労していません。提出された課題と同じ数のループを作成する方法がよくわかりません。
これは私がこれまでに持っているものです。提出された課題の数に基づいて繰り返されるループにほとんど苦労しています...試してみましたが、わかりません! 私は残りを行うことができると確信しています:)
String studentName = " ";
String courseName = " ";
int assign = 0;
int loop = 0;
int totalScore = 0;
int scorethisAssign = 0;
System.out.println("Enter student name:");
studentName = input.next();
System.out.println("Enter course name:");
courseName = input.next();
System.out.println("How many assignments have you submitted:");
assign = input.nextInt();
while (assign <= 0) {
System.out.println(" ");
System.out.println("You must enter a number greater than 0 -- TRY AGAIN!");
System.out.println("How many assignments have you submitted:");
assign = input.nextInt();
}
while (assign > loop);
{
System.out.println("How many points was assignment "loop + "worth:");
scorethisAssign = input.nextInt();
totalScore = scorethisAssign + totalScore;
loop++;
}
これは基本的に、プログラムが出力するものです。
Enter student name: Prince Harry
Enter course name: Intro to College Life
How many assignments have you submitted: 4
How many points was assignment 1 worth: 100
How many points did you score: 45
How many points was assignment 2 worth: 75
How many points did you score: 46
How many points was assignment 3 worth: 100
How many points did you score: 83
How many points was assignment 4 worth: 100
How many points did you score: 74
Progress Report for Prince Harry
Course Name is Intro to College Life
-------------------------------------------------
Number of assignments submitted.....4
Total points possible...............375.00
Total points earned.................248.00
Total percent to date...............66.13%
Letter grade to date................D
-------------------------------------------------
Enter yes if there is another class you want to calculate: no