java类 Account类

主方法

public class TestAccount {
	
	public static void main(String[] args) {
		
		int id=307;
				
		double balance=10000;
				
		double annualInterestRate=0.12;
		
		Account account=new Account(id,balance);
		account.setAnnualInterestRate(annualInterestRate);
				
		System.out.println("The Account ID is "+account.getID()+", The Balance is "+account.getBalance()
		+", The AnnualInterestRate is "+account.getAnnualInterestRate()+"%");	
		
		double wa=200;
		account.withdraw(wa);
		System.out.println("Account Balance is "+account.getBalance());
				
		double da=300;
		account.deposit(da);
		System.out.println("Account Balance is "+account.getBalance());		
		
		System.out.printf("The monthly interest is %2.2f\n",account.getMonthlyInterestRate());
		System.out.println("The date when this account was created on "+account.getdateCreated().toString());
	}

} 

Account 类

import java.util.Date;

public class Account {
	
		private int ID;
		
		private double Balance;
		
		private double AnnualInterestRate;
		
		private Date dateCreated;
			
		/*	A no-arg constructor that creates a default account.*/		
		 Account(){			
		}		 
		/*	A constructor that creates an account with the specified id and initial balance.*/		
		public Account(int ID,double Balance) {
			this.ID=ID;
			this.Balance=Balance;
			dateCreated=new Date();
		}
		/*  The accessor and mutator methods for id, balance, and annualInterestRate.*/
		public int getID() {
			return 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;
		}
		/*	The accessor method for dateCreated*/
		public Date getdateCreated() {
			return dateCreated;
		}
		/*	A method named getMonthlyInterestRate() that returns the monthly interest rate.*/
		double getMonthlyInterestRate(){
			return AnnualInterestRate/12;
		}
		/*	A method named withdraw that withdraws a specified amount from the account.*/
		public void withdraw(double money) {
			 	this.Balance=Balance-money;
				
		}
		/*	A method named deposit that deposits a specified amount to the account.*/
		public void deposit(double money) {
			this.Balance=Balance+money;
				
		}


}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值