package a; public interface Payment { double downPay(double price,double area); }
package a; public class Residence implements Payment { public double downPay (double price , double area){ return (price * area * 0.20); } }
package a; public class Commercial implements Payment { public double downPay (double price , double area){ return (price * area * 0.45); } }
package a; import java.util.Scanner; public class test { /** * @param args */ public static void main(String[] args) { double price; double area; Residence a=new Residence(); Commercial b= new Commercial(); Scanner re =new Scanner(System.in); System.out.println("输入房屋每平米价格"); price = re.nextDouble(); System.out.println("输入房屋面积"); area = re.nextDouble(); System.out.println("住宅产权房屋的首付:"+a.downPay(price, area)); System.out.println("商业产权房屋的首付:"+b.downPay(price, area)); } }