while
ループとループの両方を使用して、入力されたスコアに基づいて成績を検証して学生に割り当てる簡単なプログラムを実行しようとしていdo-while
ます。これは単純なことだと理解しています。コードは検証なしで正常に動作しますが、ループはループせず、プログラムは終了します。これは私がこれまでに得たものです
import io.*;
public class Marks {
public static void main(String[] args) {
double marks, inMarks;
int assess, inAssess, calcMark, ten;
boolean dna, dnc, fail, pass, calcDna, calcDnc, calcF, calcP;
marks = inMarks();
assess = inAssess();
dna = calcDna(assess);
dnc = calcDnc(assess);
fail = calcF(assess, marks);
pass = calcP(assess, marks);
ten = calcMark(marks);
if (dna == false) {
if (dnc == true) {
System.out.println("DNC-" + (int) marks);
} else if (fail == true) {
System.out.println("F-" + (int) marks);
} else if (pass == true) {
System.out.println(ten + "-" + (int) marks);
}
} else {
System.out.println("DNA");
}
}
private static double inMarks() {
double marks;
boolean validMark;
marks = ConsoleInput.readDouble("Input student's mark");
while ((marks < 0) && (marks > 100)) {
System.out.println("invalid mark, please enter again");
marks = ConsoleInput.readDouble("Input student's mark");
}
// Assertion 0 > marks > 100
return marks;
}
private static int inAssess() {
int assess;
boolean validAssess;
do {
assess = ConsoleInput
.readInt("Input number of assessments student completed");
if ((0 > assess) && (assess > 5)) {
System.out
.println("invalid assessment attendence. please enter again");
}
} while ((0 >= assess) && (assess >= 5));
// Assertion 0 < assess < 5
return assess;
}
private static boolean calcDna(int assess) {
boolean calcDna;
calcDna = false;
if ((assess == 0)) {
calcDna = true;
}
return calcDna;
}
private static boolean calcDnc(int assess) {
boolean calcDnc;
calcDnc = false;
if ((assess > 0) && (assess <= 4)) {
calcDnc = true;
}
return calcDnc;
}
private static boolean calcF(int assess, double marks) {
boolean calcF;
calcF = false;
if ((assess == 5) && (marks < 50.0)) {
calcF = true;
}
return calcF;
}
private static boolean calcP(int assess, double marks) {
boolean calcP;
calcP = false;
if ((assess == 5) && (marks > 50.0)) {
calcP = true;
}
return calcP;
}
private static int calcMark(double marks) {
int ten;
ten = (int) marks / 10;
return ten;
}
}