zoukankan      html  css  js  c++  java
  • 十次作业

    题目1:

    编写一个应用程序,模拟中介和购房者完成房屋购买过程。

    业务接口

    package zhong;
    
    public interface business {
           double ra = 0.022;
           double T = 0.03;
        
           void buying(double p);
        }

    购房者类

    package zhong;
    
    public class buyer implements business {
            String name;
         
         public buyer(String name) {
               this.name = name;
           }
        
           public void buying(double p) {
        
               System.out.println( "购买一套标价为:" + p  );
           }
     }

    中介类

    package zhong;
    
    public class intermediary implements business {
        
          buyer buyer;
        
             public intermediary(buyer buyer) {
    super(); this.buyer = buyer; } public void buying(double p) { buyer.buying(p); this.charing(p); } public void charing(double p) { System.out.println("中介费为:" + p * ra); System.out.println("契税:" + p * T); } }

    测试类

    package zhong;
    public class Test {
        public static void main(String[] args) {
            buyer buyer = new buyer("Lisa");
             intermediary intermediary = new intermediary(buyer);
            intermediary.buying(650000);
        }
    }

    测试结果

    题目二

    输入5个数,代表学生成绩,计算其平均成绩。当输入值为负数或大于100时,通过自定义异常处理进行提示。

    自定义异常类

    package yichang;
    
    public class MyException extends Exception {
         
            double n;
        
          public MyException(double a) {
                n = a;
           }
        
           public String toString() {
        
                return "自定义["+n+"不在0到100中]";
           }
         
        }

    测试类

    package yichang; 
    import java.util.Scanner;
    
    public class tys {
         static void avg()throws MyException {
            double a;
            double sum = 0;
           Scanner s = new Scanner(System.in);
          System.out.println("5名成绩");
           try {
               for (int i = 0; i < 5; i++) {
                    a = s.nextDouble();
                  if (a> 100 || a < 0)
                       throw new MyException(a);
                   sum += a;
               }
                  System.out.println( sum / 5);
           } catch (MyException e) {
              System.out.println("捕获"+e);
           }
    
       }
    }

    结果

  • 相关阅读:
    使用PLSql连接Oracle时报错ORA-12541: TNS: 无监听程序
    算法7-4:宽度优先搜索
    R语言字符串函数
    notepad++ 正则表达式
    MySQL常用命令
    linux下对符合条件的文件大小做汇总统计的简单命令
    Linux系统下统计目录及其子目录文件个数
    R: count number of distinct values in a vector
    ggplot2 demo
    R programming, In ks.test(x, y) : p-value will be approximate in the presence of ties
  • 原文地址:https://www.cnblogs.com/shuang123/p/11852034.html
Copyright © 2011-2022 走看看