這是我的第一個CS項目。創建我的方法後,我運行代碼以查看它是否工作到目前爲止,一切正常,但實際上並沒有在方法內部進行數學運算。一直在努力工作,無法找到錯誤。任何幫助都會很棒。它的明天應該大聲笑。我的方法並沒有帶來數據(初學者)
public static void main(String[] args) {
int numberOfStudents = 0;
int total = 0;
int value = 0;
int creditHours;
double tuition;
int classesMissed;
System.out.println("Tuition Wasted Based on Student Absences and its effect on GPA.");
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter the number of students to consider: ");
value = keyboard.nextInt();
while (value >= 5)
{
if (value > 5)
System.out.println("Number of students must be between 1 and 5");
System.out.print("Please re-enter a value number of students to consider: ");
value = keyboard.nextInt();
}
System.out.print("Enter the student ID for student 1: ");
value = keyboard.nextInt();
System.out.print("For how many credit hours is the student registered: ");
creditHours = keyboard.nextInt();
System.out.print("Enter the amount of the tuition for the semester: ");
tuition = keyboard.nextDouble();
System.out.print("Enter the average number of classes the student misses in a week: ");
classesMissed = keyboard.nextInt();
while (classesMissed > creditHours)
{
if (classesMissed > creditHours)
System.out.print("That is not possible, please re-enter the number of classes missed in a week: ");
classesMissed = keyboard.nextInt();
}
DetermineWastedTuition(creditHours, tuition, classesMissed);
}
public static void DetermineWastedTuition(int creditHours, double tuition, int classesMissed){
double weeklyTuition;
weeklyTuition = tuition/10;
double weeklyTuitionWasted;
weeklyTuitionWasted = weeklyTuition *(classesMissed/creditHours);
double semesterWasted;
semesterWasted = weeklyTuitionWasted * 16;
System.out.println("Tuition money wasted each week is " + weeklyTuitionWasted);
System.out.println("Tuition money wasted each semester is " + semesterWasted);
}
與樣品輸出爲:
學費浪費基於學生缺勤及其對GPA效果。
輸入學生的數量來考慮:1
輸入學生ID爲學生1:1234555
對於貸多少小時是學生註冊:15
輸入學費的金額爲學期:7500
輸入類的學生錯過了一週的平均次數:2,每星期浪費
學費的錢是0.0浪費每學期
學費的錢是0.0
您是否嘗試過通過與調試代碼加強? – rrirower 2014-10-02 18:00:27
您應該仔細研究代碼的縮進,因爲它會影響可讀性並可能隱藏或隱藏錯誤。在你的方法開始時真的不需要聲明所有的變量。 – 2014-10-02 18:04:33