2016-08-21 4 views
-2

私は以前これを別のプロジェクトでやったことがありますが、私はこのプロジェクトでどのように行うのか分かりません。別の方法で出力を計算し、mainメソッドからコンソールに出力する必要があります。私はこれがおそらくあなたの大部分にとっては本当に簡単だと知っていますが、私は昨日コーディングを始めましたので、これを学んだことはありません。メソッドに情報を転送してから印刷のメインメソッドに戻す方法はありますか?

マイコード:

import java.util.Scanner; // This allows for the use of the scanner in the class 

public class SavingsAccount // Start of class 
{ 
    public static void main(String[]args) // Start of main 
    { 
     double P; // These store the amounts that will be used in the accruing interest formula 
     double i; 
     double n; 
     double S = 0; 
     int timesLooped = 0; 
     Scanner readConsole = new Scanner(System.in); // This is the scanner 

     System.out.println("I am a savings account interest calculator."); // Prompts the user for input 
     System.out.println("How much money have you deposited?"); 
     P = readConsole.nextDouble(); 
     S = P; 
     System.out.println("Now, what is the annual interest rate? (i.e. .05)"); 
     i = readConsole.nextDouble(); 
     System.out.println("Finally, how long do you plan on having the money in the account?"); 
     n = readConsole.nextDouble(); 
     while (timesLooped <= n) 
     { 
      S = S + (P * i); 
      timesLooped += 1; 
     } 
     System.out.println("Your balance in that time span is " + S + "."); // Tells you your ending balance 
    } 
} 
+2

'return'キーワードは基本的な概念です。 – Li357

+0

私がしようとしていることの正確な記述は、「別々のメソッドの中で計算と変換を行う」であり、メインメソッドのメソッドに必要な情報を渡します。 " –

+0

ええ私は他の人からそれを覚えていますが、私はこのプロジェクトでどのように使うべきかわかりません –

答えて

1
private static double doyourstuff(double d1,double d2,double d3) 
{ 
    write your entire logic here as above written in main method. 
    return calculated_balance; 
} 


public static void main(String[]args) 
    { 
    --read values via scanner as you read above. 
    double S= doyourstuff(d1,d2,d3); 
    System.out.println("Your balance in that time span is " + S + ".");-- your final call 
    } 
関連する問題