第十次作业
package Test; import java.util.Scanner; public class test13 { public static void main(String[] args) { // TODO Auto-generated method stub Buyer buyer = new Buyer(); buyer.name = "Lisa"; Intermediary inter = new Intermediary(buyer); double price = 0.0; Scanner reader = new Scanner(System.in); System.out.println("请输入房屋的总价格:"); price = reader.nextDouble(); inter.charing(price); } } interface Business{ //房屋中介费 0.022 double RATIO = 0.0; //代表购房税费 double TAX = 0.0; //price表示房屋总价 default void Buying(double price) {} } class Buyer implements Business{ String name ; @Override public void Buying(double price) { // TODO Auto-generated method stub System.out.println(name +"购买一套住宅的价格是:"+price); } } class Intermediary implements Business{ //购房对象 Buyer buyer ; public Intermediary(Buyer buyer) { this.buyer = buyer; } @Override public void Buying(double price) { // TODO Auto-generated method stub } public void charing(double price) { System.out.println(buyer.name+"购买一套"+price+"的住宅需要花费"+price*0.022+"的房屋中介费和"+price*0.03+"的契税费"); } }
package Test; import java.util.Scanner; public class test12 { public static void main(String[] args) { // TODO Auto-generated method stub double total = 0.0; Scanner scanner = new Scanner(System.in); for(int i = 0;i < 5;i++) { double score = scanner.nextDouble(); if(score>100||score<0) { throw new myException1234("分数不能大于100或者小于0"); } total += score; } System.out.println("分数的平均值是:"+total/5); } } class myException1234 extends RuntimeException{ myException1234(String msg){ super(msg); } }