zoukankan      html  css  js  c++  java
  • 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);
        }
    
    }
    

    
    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);
    
    	}
    
    }
    

    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)
    
    
    

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

  • 相关阅读:
    Entity Framework Core 2.0 新特性
    asp.net core部署时自定义监听端口,提高部署的灵活性
    asp.net core使用jexus部署在linux无法正确 获取远程ip的解决办法
    使用xshell连接服务器,数字键盘无法使用解决办法
    使用Jexus 5.8.2在Centos下部署运行Asp.net core
    【DevOps】DevOps成功的八大炫酷工具
    【Network】Calico, Flannel, Weave and Docker Overlay Network 各种网络模型之间的区别
    【Network】UDP 大包怎么发? MTU怎么设置?
    【Network】高性能 UDP 应该怎么做?
    【Network】golang 容器项目 flannel/UDP相关资料
  • 原文地址:https://www.cnblogs.com/tiantianna/p/10666884.html
Copyright © 2011-2022 走看看