Java第二次作业

1.编写“人”类及其测试类。属性:姓名、性别、年龄、身份证号码。

package com.wsy.person;

public class Person {
    private String name ;
    private char sex;
    private int age;
    private String IDCardNumber;
    
    public Person(String name, char sex, int age, String IDCardNumber) {
        
        this.name = name;
        this.sex = sex;
        this.age = age;
        this.IDCardNumber = IDCardNumber;
    }
    public void print() 
    {
        System.out.println("姓名:"+name);
        System.out.println("性别:"+sex);
        System.out.println("年龄:"+age);
        System.out.println("身份证号码:"+IDCardNumber);
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public char getSex() {
        return sex;
    }
    public void setSex(char sex) {
        this.sex = sex;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
    public String getIDCardNumber() {
        return IDCardNumber;
    }
    public void setIDCardNumber(String iDCardNumber) {
        IDCardNumber = iDCardNumber;
    }
    
}
package com.wsy.person;

public class TestPerson {

    public static void main(String[] args) {
        Person p1 = new Person("张三",'男',18,"430101010101010101");
        Person p2 = new Person("李四",'女',18,"123456789009876543");
        p1.print();
        p2.print();
    }

}

2.编写“手机”类及其测试类。属性:手机品牌、手机型号。

package FengZhuang;
import java.util.Scanner;
 class Phone
 {
     String Phonebrand;  /*手机品牌*/
     String Phonemodel;  /*手机型号*/
   public void printf()
   {
      System.out.print("该手机的品牌是:"+Phonebrand+"  ");
      System.out.println("手机型号是:"+Phonemodel);
   }
   
     public Phone(String Phonebrand,String Phonemodel) 
     {
         this.Phonebrand=Phonebrand;
         this.Phonemodel=Phonemodel;
     }
 }
public class TestPhone {

    public static void main(String[] args)
    {   
        Scanner in=new Scanner(System.in);
          String Phonebrand,Phonemodel;
          System.out.println("请输入手机品牌和型号:");
          Phonebrand=in.next();
          Phonemodel=in.next();
         Phone object= new Phone(Phonebrand,Phonemodel);
         object.printf();
    }

}

另外的搞不懂了~~

posted @ 2019-06-15 17:54  可乐ohh  阅读(120)  评论(0编辑  收藏  举报