• 第二次作业


    第一题:编写“人”及其测试类:

    package person;

    public class person {  

    String name;    String sex;   String age;   String id;

     void get(String n,String s,String a,String i)

    {   name=n;   sex=s;   age=a;   id=i;  }

     void show() {  

     System.out.println("姓名:"+name);   System.out.println("性别:"+sex);   System.out.println("年龄:"+age);   System.out.println("身份证号码:"+id);  }

    public static void main(String[] args) {

     person zhang=new person();

     System.out.println("第一个人的信息");  zhang.name="张三";  zhang.sex="男";  zhang.age="18";  zhang.id="430101010101010101";

     System.out.println("姓名:"+zhang.name);  System.out.println("性别:"+zhang.sex);  System.out.println("年龄:"+zhang.age);  System.out.println("身份证号码:"+zhang.id);  person li=new person();  System.out.println("第二个人的信息");  li.get("李四", "女", "18", "123456789009876543");  li.show();   }     }

    第二题:编写“手机”类及其测试类:

    public class Phone {
     String brand;
     String model;
    void get(String brand,String model)
    {
     this.brand =brand;
     this.model =model;
    }
    void show() {
     System.out.println("品牌:"+brand);
     System.out.println("型号:"+model);
    }
    public static void main(String[] args) {
     Phone Huawei=new Phone();
     System.out.println("输出手机信息");
     Huawei.brand="华为";
     Huawei.model="荣耀3C";
     System.out.println("品牌:"+Huawei.brand);
     System.out.println("型号:"+Huawei.model);
     Phone Lianxiang=new Phone();
     System.out.println("输出手机信息");
     Lianxiang.brand="联想";
     Lianxiang.model ="A3600D";
     System.out.println("品牌:"+Lianxiang.brand );
     System.out.println("型号:"+Lianxiang.model );
     Phone Xiaomi=new Phone();
     System.out.println("输出手机信息");
     Xiaomi.brand="小米";
     Xiaomi.model ="note";
     System.out.println("品牌:"+Xiaomi.brand );
     System.out.println("型号:"+Xiaomi.model );
    }
    }

    第三题:编写“书籍类”及其测试类:

    public class Book {  String name;  String num;  String author;  String place;  String time;  int totalnum;  int price;

     void get(String name,String num,String author,String place,String time,int totalnum,int price) {

      this.name =name;   this.num =num;   this.author =author;   this.place =place;   this.time =time;   this.totalnum =totalnum;   this.price =price;  }

     public static void main(String[] args) {

      Book Yue=new Book();

      Yue.name="你是人间的四月天";   Yue.num ="ISBN 978-7-80733-655-6";   Yue.author ="林徽因";   Yue.place="古吴轩出版社";   Yue.time ="2011-6";   Yue.totalnum =200;   Yue.price =29;   System.out.println("书名:"+Yue.name);

      System.out.println( "书号:"+Yue.num);   System.out.println("作者:"+Yue.author);   System.out.println("出版社:"+Yue.place);   System.out.println("出版时间:"+Yue.time);   System.out.println("页数:"+Yue.totalnum);   System.out.println("价格:"+Yue.price);

      Book Xia=new Book();  

     Xia.name ="忽而今夏";   Xia.num="ISBN 9787505415157";   Xia.author="明前雨后";   Xia.place ="朝华出版社";   Xia.time ="2006-6";   Xia.totalnum =216;   Xia.price =20;   System.out.println("书名:"+Xia.name);   System.out.println( "书号:"+Xia.num);   System.out.println("作者:"+Xia.author);   System.out.println("出版社:"+Xia.place);   System.out.println("出版时间:"+Xia.time);   System.out.println("页数:"+Xia.totalnum);   System.out.println("价格:"+Xia.price);  }

    }

    第四题:编写“圆柱体类”及其测试类:

    public class cylinder {  double r;  int h;  double s;  double V ;

     void get(double r,int h,double s,double V ) {

      this.r =r;   this.h =h;   this.s =s;   this.V =V;  }

     public static void main(String[] args) {

      double pai=3.14;   double r=2.0;   double s = pai*r*r;   int h=5;   double V=s*h;

     System.out.println("底面积:"+s);  System.out.println("体积:"+V);

     cylinder Circle=new cylinder();

      Circle.r =2.0;  Circle.h =5;  Circle.s =12.56;  Circle.V =62.800000000000004;

     System.out.println("底半径;"+r);  System.out.println("高;"+h);  System.out.println("底面积:"+s);  System.out.println("体积;"+V);   } }

  • 相关阅读:
    CoreAnimation6-基于定时器的动画和性能调优
    CoreAnimation5-图层时间和缓冲
    CoreAnimation4-隐式动画和显式动画
    CoreAnimation3-专用图层
    CoreAnimation2-视觉效果和变换
    CoreAnimation1-图层树、寄宿图以及图层几何学
    Quartz-2D绘图之路径(Paths)详解
    Quartz-2D绘图之图形上下文详解
    Objective-C设计模式——抽象工厂模式Abstract Factory(对象创建)
    Objective-C设计模式——工厂方法模式virtual constructor(对象创建)
  • 原文地址:https://www.cnblogs.com/rfvh/p/10666123.html
Copyright © 2020-2023  润新知