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

}

另外的搞不懂了~~

转载于:https://www.cnblogs.com/cocacolaohh/p/11028336.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值