-1
JOptionPaneからオプションの1つを選択するようにします。次にif文でそのオプションを使いたいと思います。しかし、私はそれを行う方法がわかりません?if文のJOptionPaneからユーザが選択したオプションの使い方は?
import javax.swing.JOptionPane;
public class MortgageCalculator {
public static void main(String[]args)
{
JOptionPane.showMessageDialog(null, "Lets calculate your mortgage",null, JOptionPane.PLAIN_MESSAGE);
double principle = Double.parseDouble(JOptionPane.showInputDialog(null, "What is your loan amount?"));
int years = Integer.parseInt(JOptionPane.showInputDialog(null,"Enter the lenght of your loan"));
int n = years * 12;
double rate = Double.parseDouble(JOptionPane.showInputDialog(null, "What is your interest rate?"));
String[] options = new String[] {"Compound", "Simple"};
int response = JOptionPane.showOptionDialog(null, null, "Choose your interest type", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE,null, options, options[0]);
//I want to use my selected option here.
if(options ==compound)
{
double payment = (compound(principle,years,rate))/n;
}
else
{
double payment = (simple(principle, years, rate))/n;
}
}
public static double simple(double principle, int n , double interestRate)
{
double interest = principle * n * (interestRate/100);
double totalLoan = principle + interest;
return totalLoan;
}
public static double compound(double principle, int years, double interestRate)
{
int n = years * 12;
double base = (principle* (1+ (interestRate/100)*1/n));
double amount = Math.pow(base, n);
return amount;
}
ところで、これは完全なコードではありません: はここに私のコードです。構文がありません。 助けてくれてありがとう。