java 第二次作业

1.编写人类与测试类

package person;

public class person {
    String name;
    char sex;
    int age;
    String num;
    
    public person(String name,char sex,int age,String num) {
        this.name=name;
        this.sex=sex;
        this.age=age;
        this.num=num;
        
    }



    public static void main(String[] args) {
        person s1=new person("张三",'男',18,"430101010101010101");
        person s2=new person("李四",'女',18,"123456789009876543");
        System.out.println("姓名:"+s1.name+",性别:"+s1.sex+",年龄:"+s1.age+",身份证号码:"+s1.num);
        System.out.println("姓名:"+s2.name+",性别:"+s2.sex+",年龄:"+s2.age+",身份证号码:"+s2.num);
    }

}

1632974-20190408194620038-206968937.png


2.编写“手机”类及测试类

package person;

public class Phone {
String brind;//手机品牌
String size;//手机型号
public Phone(String brind,String size) {
this.brind=brind;
this.size=size;
}

public static void main(String[] args) {
    // TODO Auto-generated method stub
    Phone s1=new Phone("华为","荣耀3C");
    Phone s2=new Phone("联想","A3600D");
    Phone s3=new Phone("小米","note");
    
    System.out.println("手机品牌;"+s1.brind+",手机型号;"+s1.size);
    System.out.println("手机品牌;"+s2.brind+",手机型号;"+s2.size);
    System.out.println("手机品牌;"+s3.brind+",手机型号;"+s3.size);

}

}


![](https://img2018.cnblogs.com/blog/1632974/201904/1632974-20190408194651494-1472230872.png)

3.编写书籍类及测试类

package person;

public class book {
    String name;
    String number;
    String editor;
    String publish;
    int year;
    int x;
    int price;
    
    public book(String name,String number,String editor,String publish,int year,int x,int price) {
        this.name=name;
        this.number=number;
        this.editor=editor;
        this.publish=publish;
        this.year=year;
        this.x=x;
        this.price=price;
    }

    
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        book s1=new book("老人与海","003568","海明威","海明威出版社",1978,200,58);
        book s2=new book("假如给我三天光明","005800","海勒","hell出版社",1998,78,36);
        
        System.out.println("名字:"+s1.name+",书号:"+s1.number+",主编:"+s1.editor+",出版社:"+s1.publish+",出版日期:"+s1.year+",页码:"+s1.x+",价格:"+s1.price);
        System.out.println("名字:"+s2.name+",书号:"+s2.number+",主编:"+s2.editor+",出版社:"+s2.publish+",出版日期:"+s2.year+",页码:"+s2.x+",价格:"+s2.price);

    }

}

1632974-20190408192452783-1676327414.png

4.编写“圆柱体”类及测试类

package person;

public class round {
final float PI=3.14f;
float r;
float h;
public round(float r,float h) {
this.r=r;
this.h=h;

        System.out.println("圆底半径="+r+",高="+h+",底面积="+PI*r*r+",体积="+PI*r*r*h);
    }

public static void main(String[] args) {
    // TODO Auto-generated method stub
    
    round s1=new round(2.1f,3.5f);
    round s2=new round(2.3f,5.0f);

}

}



![](https://img2018.cnblogs.com/blog/1632974/201904/1632974-20190408194807218-2129173876.png)

作业总结:总体来说,这四题作业是属于较为基础的题目,可是我却花了很多时间才把它写完的,这和平时的练习是息息相关的,平时练习少导致了写程序时遇到各种基础的问题却没办法去解决。这次作业刚开始我是不知道怎么动笔的,是通过借鉴同学们的作业然后自己才开始慢慢尝试着写,所以我认识到了练习的重要性,之后一有时间我会尽量得去做些练习来让自己更加熟练。

转载于:https://www.cnblogs.com/tiantianna/p/10666884.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值