私が行っているプログラムでは、FileInputStream を使用してコースの成績を計算する必要があります。
私が作成したクラス Course には、次のメソッドがあります。
public double getGradePoint ()
{
if (letterGrade == "A+" || letterGrade == "A")
gradePoint = 4.0;
if (letterGrade == "A-")
gradePoint = 3.7;
if (letterGrade == "B+")
gradePoint = 3.3;
if (letterGrade == "B")
gradePoint = 3.0;
if (letterGrade == "B-")
gradePoint = 2.7;
if (letterGrade == "C+")
gradePoint = 2.3;
if (letterGrade == "C")
gradePoint = 2.0;
if (letterGrade == "C-")
gradePoint = 1.7;
if (letterGrade == "D+")
gradePoint = 1.5;
if (letterGrade == "D")
gradePoint = 1.0;
if (letterGrade == "F")
gradePoint = 0.0;
return gradePoint;
}
そして、テストクライアントには次のものがあります。
String subject;
String number;
String letGrade;
Course course1 = new Course ("ENGL", "1111", "D+");
FileInputStream file1 = new FileInputStream ("test transcript 1.txt");
Scanner readFile = new Scanner (file1);
while (readFile.hasNext ())
{
course1.setSubject (readFile.next ());
subject = course1.getSubject ();
course1.setNumber (readFile.next ());
number = course1.getNumber ();
course1.setLetterGrade (readFile.next ());
letGrade = course1.getLetterGrade ();
course1.getGradePoint ();
System.out.println (course1.toString ());
}
テスト トランスクリプト 1.txt には以下が含まれます。
COMP 1631 A-
ENGL 1101 B
MATH 1200 C+
しかし、何らかの理由で、course1.getGradePoint()を使用すると、常に0.0が返されます
プログラムを実行した後:
COMP 1631 A- (worth = 0.0)
ENGL 1101 B (worth = 0.0)
MATH 1200 C+ (worth = 0.0)
次のように、while コマンドの上で course1.getGradePoint() を使用してみました。
String subject;
String number;
String letGrade;
Course course1 = new Course ("ENGL", "1111", "D+");
course1.getGradePoint ();
FileInputStream file1 = new FileInputStream ("test transcript 1.txt");
Scanner readFile = new Scanner (file1);
while (readFile.hasNext ())
{
course1.setSubject (readFile.next ());
subject = course1.getSubject ();
course1.setNumber (readFile.next ());
number = course1.getNumber ();
course1.setLetterGrade (readFile.next ());
letGrade = course1.getLetterGrade ();
course1.getGradePoint ();
System.out.println (course1.toString ());
}
戻り値:
COMP 1631 A- (worth = 1.5)
ENGL 1101 B (worth = 1.5)
MATH 1200 C+ (worth = 1.5)
何らかの理由で readFile. next () では機能しません。誰かが私を助けることができれば、それはありがたいです.