자바 9주차 과제

Written by 박민영 on Apr 21st, 2022 Views Report Post

일부는 구글링 했음

import java.util.ArrayList;
import java.util.Arrays;

public class Account1 extends Account {
	private String name;
	
	int i=0;
	
	ArrayList<Transaction> transactions = new ArrayList<>();
	
	public Account1(String newName, int newId, double newBalance) {
		name=newName;
		setId(newId);
		setBalance(newBalance);
	}
	
	public String getName() {
		return name;
	}
	
	public void withdraw(double amount) {
		setBalance(getBalance()-amount); 
		Transaction transaction=new Transaction('W', amount, getBalance(),"Standard");
		transactions.add(transaction);
	  }
	  
    public void deposit(double amount) {
		setBalance(getBalance()+amount); 
		Transaction transaction=new Transaction('D', amount, getBalance(),"Standard");
		transactions.add(transaction);
	 }
    
    public String toString() {
    	return "Name: "+name+"\nAnnual interest rate: "+getAnnualInterestRate()+"\nBalance: "+getBalance()+"\nDate\t\t\t\tType\tAmount\tBalance\n"+Arrays.toString(transactions.toArray());
    }
}

class Account {
	  private int id;
	  private double balance;
	  private static double annualInterestRate;
	  private java.util.Date dateCreated;

	  public Account() {
	    dateCreated = new java.util.Date();
	  }

	  public Account(int newId, double newBalance) {
	    id = newId;
	    balance = newBalance;
	    dateCreated = new java.util.Date();
	  }

	  public int getId() {
	    return this.id;
	  }

	  public double getBalance() {
	    return balance;
	  }

	  public static double getAnnualInterestRate() {
	    return annualInterestRate;
	  }
public class TestAccount1 {
public static void main(String[] args) {
	Account1 testAccount=new Account1("George",1122,1000);
	Account1.setAnnualInterestRate(1.65);
	testAccount.deposit(30);
	testAccount.deposit(40);
	testAccount.deposit(50);
	testAccount.withdraw(5);
	testAccount.withdraw(4);
	testAccount.withdraw(2);
	System.out.println(testAccount.toString());
  }
}

Comments (0)