2016-08-05 13 views
0

私はユーザー入力を使って基本的な計算プログラムを作成しようとしています。私は計算を返すように見えることはできません。このメインプログラムは、ここで実行される基本的なプログラムを作成しようとしましたが、問題が発生しました。

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に関係なく印刷しています。私は変数とメソッドを使っていましたが、それを動作させるようには見えません。どんな助けもありがとう!

答えて

2

scriptPercentageはフィールドです。 currentScriptsまたはscriptsNeededDaily100の場合は自動的に更新されません。

public double calcDrug100(){ 
    this.scriptPercentage = this.currentScripts/this.scriptsNeededDaily100; 
    return this.scriptPercentage; 
} 
+0

この修正でも、私はまだ0.0を返しています。私は何かをさらに逃していますか – Jesse730

+0

何番に入っていますか? –

+0

日:16の スクリプト:567、プログラムが実行されるように:四半期に日の入力数:スクリプトの16 入力電流の数: 0.0 – Jesse730

関連する問題