找回感觉的练习
一:注释
参数price代表房屋每平方米的价格,area代表房屋的总平方数
double downPay(double price,double area):一个计算房屋首付款的方法,重写计算房屋首付款的方法
三 代码部分
1.Payment类
package com;
public interface Payment {
double downPay(double price,double area);
}
2.test类
package com;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
Residence re=new Residence();
Payment pay=new Commercial();//接口回调
System.out.println("住宅产权房屋的首付总房款"+re.downPay(5, 100));
System.out.println("商业产权房屋的首付总房款"+pay.downPay(5, 100));
}
}
3.Residence类
package com;
public class Residence implements Payment {//(住宅产权房屋类)
public double downPay(double price,double area){
return(0.2*price*area);
}
}
4.Commercial类
package com;
public class Commercial implements Payment { //(商业产权房屋类)
public double downPay(double price,double area){
return(0.45*price*area);
}
}
5.测试部分