자바 saving account 를 공부하고있는데 class method 에서 막히네요
글쓴이: wndtjr2 / 작성시간: 일, 2011/10/09 - 5:07오전
마지막에 total balance 와 total 입금, total 출금, total 이자 를 나타내야하는데 솔직히 class method 에 대해서 잘 이해를 못해서 뭐가몬지 모르겠습니다.
뭐가 문제고 class method 에대해서 예기좀 해주세요
import java.text.DecimalFormat;
import javax.swing.JOptionPane;
public class SavingAccount {
public static void main(String[] args) {
String intRate, stBalance, psMonth, input;
double interRate, startBalance, depositIn, monthWith;
int passMonth;
DecimalFormat dollar = new DecimalFormat("##0.00");
intRate = JOptionPane.showInputDialog("Enter the annual interest rate.");
interRate = Double.parseDouble(intRate);
stBalance = JOptionPane.showInputDialog("Enter the starting balance.");
startBalance = Double.parseDouble(stBalance);
SAccount sAccount = new SAccount(startBalance, interRate);
psMonth = JOptionPane.showInputDialog("Enter the number of months that have passed since the account was established.");
passMonth = Integer.parseInt(psMonth);
for(int i = passMonth; i < 12; i++){
input = JOptionPane.showInputDialog("Input the amount of money you want to deposit.");
depositIn = Double.parseDouble(input);
sAccount.setDeposit(depositIn);
input = JOptionPane.showInputDialog("Input the amount of money you want to withdraw.");
monthWith = Double.parseDouble(input);
sAccount.setWithdrawal(monthWith);
sAccount.setTotalInt(interRate);
}JOptionPane.showMessageDialog(null, "total ending balance : " + dollar.format(sAccount.getBalance()) +
"\ntotal amount of deposit : " + dollar.format(sAccount.getDeposit()) +
"\ntotal amount of withdral : " + dollar.format(sAccount.getwithdral()) +
"\ntotal interest you earned : " + dollar.format(sAccount.getTotalInt()));
System.exit(0);
}
}public class SAccount {
private double interestRate, interest;
private double balance;
private double deposit;
private double withdral;
public SAccount(double bal,double intRate){
balance = bal;
interestRate = intRate;
}
public void setDeposit(double dposit){
deposit += dposit;
}
public void setWithdrawal(double withd){
withdral -= withd;
}
public void setIntRate(double rate){
interestRate = rate;
}
public void setBalance(double bal){
balance = bal;
balance = deposit - withdral;
balance += balance;
}
public void setTotalInt(double intRate){
interestRate = intRate;
interest = (interestRate / 12) * balance;
}
public double getDeposit(){
return deposit;
}
public double getwithdral(){
return withdral;
}
public double getBalance(){
return balance;
}
public double getTotalInt(){
return interest;
}
}Forums:


댓글 달기