0
我想創建一個基本的計算程序,使用用戶輸入(幾乎只是我自己的)和處理非常小的計算。雖然我似乎無法得到計算結果。我做我所有的計算,在該文件中:Java新手,試圖做一個基本的程序,但遇到問題
public class Drug {
private double goalForQuarter = 3716.0;
private double currentScripts;
private double currentDaysIntoQuarter;
private double scriptsNeededDaily100 = goalForQuarter/currentDaysIntoQuarter;
private double scriptsNeededDaily105 = scriptsNeededDaily100 * 1.05;
private double scriptPercentage = currentScripts/scriptsNeededDaily100;
public Drug() {
}
public Drug (double currentScripts) {
this.currentScripts = currentScripts;
}
public Drug (double currentScripts, double currentDays){
this.currentScripts = currentScripts;
this.currentDaysIntoQuarter = currentDays;
}
public double calcDrug100(){
return this.scriptPercentage;
}
}
這個主程序運行這裏:
進口java.util.Scanner的;
public class Main {
public static void main(String[] args){
Scanner reader = new Scanner(System.in);
System.out.print("Input number of days into Quarter: ");
double days = Integer.parseInt(reader.nextLine());
System.out.println("Input current number of Scripts: ");
double scripts = Integer.parseInt(reader.nextLine());
Drug drug1 = new Drug(scripts, days);
System.out.println(drug1.calcDrug100());
}
}
即使有用戶輸入,我仍然打印出0.0。我玩過我的變量和方法,但似乎無法使其工作。任何幫助,將不勝感激!
即使有此更正,我仍然返回0.0。我錯過了什麼 – Jesse730
你輸入了什麼數字? –
天:16個 腳本:567,程序運行爲這樣:輸入的天數成季:16 輸入電流數量的腳本: 0.0 – Jesse730