9.19 third day 注意事项
来源:互联网 发布:大数据的意义包括 多选 编辑:程序博客网 时间:2024/06/14 00:03
在对于继承和多态的理解
package third;
public class Test1 {
public static void main(String[] args) {
// Account a = new Account(1122,20000,0.045);
// a.withdraw(30000);
// a.deposit(2500);
CheckAccount c = new CheckAccount(1122, 20000, 0.045, 5000);
c.withdraw(5000);
c.withdraw(18000);
c.deposit(2000);
}
}
class Account{
private int id;
private double balance;
private double annualInterestRate;
public Account (int id, double balance, double annualInterestRate )
{
this.id = id;this.balance = balance;this.annualInterestRate = annualInterestRate;
}
@Override
public String toString() {
return "Account [id=" + id + ", balance=" + balance
+ ", annualInterestRate=" + annualInterestRate + "]";
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public double getBalance() {
return balance;
}
public void setBalance(double balance) {
this.balance = balance;
}
public double getAnnualInterestRate() {
return annualInterestRate;
}
public void setAnnualInterestRate(double annualInterestRate) {
this.annualInterestRate = annualInterestRate;
}
public double getMonthlyInterest(){
return (annualInterestRate/12);
}
public void withdraw (double amount){
if(balance > amount)
{
balance = balance - amount;
System.out.println("your account money:"+balance);
}
else
System.out.println("money not enough");
}
public void deposit (double amount){
balance +=amount;
System.out.println("your account money:"+balance);
System.out.println(getMonthlyInterest());
}
}
class CheckAccount extends Account{
public CheckAccount(int id, double balance, double annualInterestRate, double overDraft) { //在子类继承父类,必须重写父类的构造函数
super(id, balance, annualInterestRate); //super在子类中可以调用父类的构造器。
// TODO Auto-generated constructor stub
this.overDraft = overDraft;
}
private double overDraft;
@Override
public void withdraw(double amount) {
// TODO Auto-generated method stub
if(getBalance()>amount){
super.withdraw(amount);
System.out.println("your can overdraft money:"+ overDraft);
}
else
if((getBalance()+overDraft)>amount){
overDraft = overDraft - amount + getBalance();
setBalance(0);
System.out.println("your account money:"+getBalance());
System.out.println("your can overdraft money:"+ overDraft);
}
else
{
System.out.println("Don't have enough money");
}
}
}
多态(自己初步的偶遇)
在声明函数和调用函数的时候能用上,在函数声明的时候
A a = new B;
其中B是A的子类
在函数调用的时候 toString(A a)
其中的参数a可以是 类B
- 9.19 third day 注意事项
- Culture Sharing(Third Day)
- The third day
- visitor parttern (third day)
- third day 自学测试
- The Third Day
- Python Third Day
- 《黑马程序员》The third day
- 数据结构习题学习笔记(The Third Day)
- php third day 数组相关 013.07.05
- The third day of learning java
- 9.17 first day 注意事项
- 9.18 day second 注意事项
- The third day in the new company called ehealth-china
- 通讯基本概念总结(中软国际Third Day)
- Fish to be a skilled programmer—third day
- Starting From 0 Learning Python(On the third day)
- On the third day learning Python(第三天学习Python)
- Android开源控件----Android显示GIF图像控件------android-gif-drawable
- HDU 2095 find your present (2)
- 【JDBC】day03_数据库连接池
- sublime text 2/3支持中文编码
- Handler的绑定过程
- 9.19 third day 注意事项
- HTML中的文本控制
- Android AIDL技术详解
- 设计模式的认识
- Android内存管理机制详解
- docker学习笔记(一)
- Android Api Demos登顶之路(七十六)Graphics-->ShapeDrawable
- 面试
- 新手报到~对算法的一些思考