0
Arlight 그래서 나는이 모든 코드를 꽤 많이 가지고있다. 기본적으로 은행 계좌를 만드는 것이다. Checking 및 저축 예금에 대한 코드를 만들었습니다. 이 코드는 모두 정확합니다. 내 Testaccount
클래스의 저축 예금 계좌를 만드는 데 도움이 필요합니다.인스턴스 만들기/테스트 코드
홈페이지 계정 코드 :
public class Accountdrv {
public static void main (String[] args) {
Account account = new Account(1122, 20000, 4.5);
account.withdraw(2500);
account.deposit(3000);
System.out.println("Balance is " + account.getBalance());
System.out.println("Monthly interest is " +
account.getMonthlyInterest());
System.out.println("This account was created at " +
account.getDateCreated());
}
}
class Account {
private int id;
private double balance;
private double annualInterestRate;
private java.util.Date dateCreated;
public Account() {
dateCreated = new java.util.Date();
}
public Account(int id, double balance, double annualInterestRate) {
this.id = id;
this.balance = balance;
this.annualInterestRate = annualInterestRate;
dateCreated = new java.util.Date();
}
public int getId() {
return this.id;
}
public double getBalance() {
return balance;
}
public double getAnnualInterestRate() {
return annualInterestRate;
}
public void setId(int id) {
this.id =id;
}
public void setBalance(double balance) {
this.balance = balance;
}
public void setAnnualInterestRate(double annualInterestRate) {
this.annualInterestRate = annualInterestRate;
}
public double getMonthlyInterest() {
return balance * (annualInterestRate/1200);
}
public java.util.Date getDateCreated() {
return dateCreated;
}
public void withdraw(double amount) {
balance -= amount;
}
public void deposit(double amount) {
balance += amount;
}
}
저축 :이
class Savings extends Account{
public Savings(int id, double balance, double annualInterestRate) {
super(id, balance, annualInterestRate);
}
public void withdraw(double amount) {
if(super.getBalance() < amount)
{
System.out.println("Error");
}
else
{
super.withdraw(amount );
System.out.println("Withdraw Completed");
}
}
}
검사 :
public class Checking extends Account{
private double overdraft_limit = 100;
public Checking(int id, double balance, double annualInterestrate){
//super();
super(id, balance, annualInterestrate);
}
public void withdraw(double amount) {
if(super.getBalance() >= (amount + overdraft_limit))
{
System.out.println(" account Overdrawn");
}
else
{
super.withdraw(amount);
System.out.println("Withdraw Completed");
}
}
}
이 좋아이 일이다 내가 도움이 필요한 부분, 아마도 아주 간단하지만 그것을 작성하는 방법에 대한 내 머리를 감쌀 수 없다, 나는 저축 예금을 만들고 확인하고 돈을 인출 할 필요가있다. 내가 여기까지 한 것은 여기있다.
Testaccount :
public class Testaccount {
public static void main(String[] args) {
Account account = new Account(0, 100, 0.6);
System.out.println(account);
account.withdraw(10.50);
System.out.println(account);
account.deposit(5.0);
System.out.println(account);
// Need to add test cases for Savings and Checking
}
}
당신은 사용을 고려해야합니다'JUnit' 또는 코드 –
테스트를위한 또 다른 프레임 워크는 당신이 당신의 '계정'클래스와 같은 파일의 클래스 'Accountdrv'을 발견했다. 그게 니가하고 싶은 일이다. 이제는 관련 사례를 테스트 해보십시오. – AnxGotta