ログインしてさらにmixiを楽しもう

コメントを投稿して情報交換!
更新通知を受け取って、最新情報をゲット!

Javaの課題丸投げコミュのメソッドの呼び出し

  • mixiチェック
  • このエントリーをはてなブックマークに追加
はじめまして。
1週間悩み続けています!
独学ですので、まわりに聞ける人が誰もいません・・。
ご教示いただけたら助かります。

メインメソッド内のメソッドで計算した結果を、メインメソッド内で呼び出して表示したいのです。


import javax.swing.*;
import java.text.*;

public class Chp5ass


{
public static void main (String [ ] args)
{

String response;
response = JOptionPane.showInputDialog(null, "How many dollars do you wish to borrow?");
int dollars = (int) Double.parseDouble(response); //bollow money

response = JOptionPane.showInputDialog(null, "What is the interest rate?");
double rate = Double.parseDouble(response); //interest rate

response = JOptionPane.showInputDialog(null, "How many years will take the loan?(whole number)?");
int years = Integer.parseInt(response); //loan years

// begin the calculations


double totalInterest = calculateInterest();


DecimalFormat patternFormatter = new DecimalFormat("$###,##0.00");
JOptionPane.showMessageDialog(null, "If you loan " +patternFormatter.format(dollars)+" at an interest rate of " + rate
+"\nfor" + years +" years, you must pay " +patternFormatter.format(totalInterest) +" in interest." );

System.exit(0);
}//ends main method

public static double calculateInterest(int dollars,double rate,int years)
{

return (int)dollars * rate / (int)years;

}//ends calculateInterest method

} // ends program



エラーはこう出ます。

Chp5ass.java:33: calculateInterest(int,double,int) (Chp5ass 内) を () に適用できません
double totalInterest = calculateInterest();
^
エラー 1 個

java.lang.NoClassDefFoundError: Chp5ass
Exception in thread "main"

コメント(2)

calculateInterest メソッドは、int と double と int の3つの引数を取らなければならないので、引数無しでは呼び出せません。

変数名から予想すると、
> double totalInterest = calculateInterest(dollars, rate, years);
と書き換えればいいのでは?
杵搗き餅@反省中さん、本当にありがとうございました!

引数を入れてみたら、できました!!

>引数無しでは呼び出せません。

大変勉強になりました。ありがとうざいました。

ログインすると、みんなのコメントがもっと見れるよ

mixiユーザー
ログインしてコメントしよう!

Javaの課題丸投げ 更新情報

Javaの課題丸投げのメンバーはこんなコミュニティにも参加しています

星印の数は、共通して参加しているメンバーが多いほど増えます。