实验七

package student;

public class Person {
    public String name;
    public MyDate birthdate;
    public String gender,province,city;
    private static int count=0;
    //构造方法
    public Person(String name,MyDate birthdate,String gender,String province,String city)
    {
        this.set(name,birthdate,gender,province,city);
        count++;
    }
    public Person(String name,MyDate birthdate)
    {
        this(name,birthdate,"","","");
    }
    public Person()
    {
        this("",new MyDate());
    }
    public Person(Person per)
    {
        this(per.name,new MyDate(per.birthdate),per.gender,per.province,per.city);
    }
    public void finalize()
    {
        System.out.println("释放对象("+this.toString()+")");
        Person.count--;
    }
    public static void howMany()
    {
        System.out.print(Person.count+"个Person对象,");
    }
    public void set(String name,MyDate birthdate,String gender,String province,String city)
    {
        this.name=name==null?"":name;
        this.birthdate=birthdate;
        this.gender=gender==null?"":gender;
        this.province=province==null?"":province;
        this.city=city==null?"":city;
    }
    public void set(String name,MyDate birthdate)
    {
        this.set(name, birthdate,"","","");
    }
    public String toString()
    {
        return this.name+","+(this.birthdate==null?"":birthdate.toString())+","+
    this.gender+","+this.province+","+this.city;
    }
}
package student;

public class MyDate {
    private int year,month,day;
    private static int thisYear;
    static
    {
        thisYear=2018;
    }
    public MyDate(int year,int month,int day)
    {
        this.set(year,month,day);
    }
    public MyDate()
    {
        this(1970,1,1);
    }
    public MyDate(MyDate date)
    {
        this.set(date);
    }
    public void set(int year,int month,int day)
    {
        this.year=year;
        this.month=(month>=1&&month<=12)?month:1;
        this.day=(day>=1&&day<=31)?day:1;
    }
    public void set(MyDate date)
    {
        this.set(date.year,date.month,date.day);
    }
    public int getYear()
    {
        return this.year;
    }
    public int getMonth()
    {
        return this.month;
    }
    public int getDay()
    {
        return this.day;
    }
    public String toString()
    {
        return year+"年"+String.format("%02d", month)+"月"+String.format("%02d", day)+"日";
    }
    public static int getThisYear()
    {
        return thisYear;
    }
    public static boolean isLeapYear(int year)
    {
        return year%400==0||year%100!=0&&year%4==0;
    }
    public boolean isLeapYear()
    {
        return isLeapYear(this.year);
    }
    public boolean equals(MyDate date)
    {
        return this==date||date!=null&&this.year==date.year&&this.month==date.month&&this.day==date.day;
    }
    public static int daysOfMonth(int year,int month)
    {
        switch(month)
        {
        case 1:case 3:case 5:case 7: case 8: case 10: case 12: return 31;
        case 4:case 6:case 9:case 11:return 30;
        case 2:return MyDate.isLeapYear(year)?29:28;
        default: return 0;
        }
    }
    public int daysOfMonth()
    {
        return daysOfMonth(this.year,this.month);
    }
    public void tomorrow()
    {
        this.day=this.day%this.daysOfMonth()+1;
        if(this.day==1)
        {
            this.year++;
        }
    }
    public MyDate yesterday()
    {
        MyDate date=new MyDate(this);
        date.day--;
        if(date.day==0)
        {
            this.month=(this.month-2+12)%12+1;
            if(this.month==12)
                this.year--;
        }
        return date;
    }
}
package student;
import java.util.Scanner;
import java.text.SimpleDateFormat;

public class Student extends Person
{
    public String department,speciality,number;
    public boolean member;
    private static int count=0;
    public Student(String name,MyDate birthdate,String gender,String province,String city,
            String department,String speciality,String number,boolean member)
    {
        super(name,birthdate,gender,province,city);
        this.set(department, speciality,number,member);
        count++;
    }
    public Student()
    {
        super();
        this.set("","","", false);
        Student.count++;
    }
    public Student(Person person,String department,String speciality,String number,boolean member)
    {
        super(person);
        this.set(department, speciality,number,member);
        Student.count++;
    }
    public Student(Student stu)
    {
        this(stu,stu.department,stu.speciality,stu.number,stu.member);
    }
    public void finalize()
    {
        super.finalize();
        Student.count--;
    }
    public static void howMany()
    {
        Person.howMany();
        System.out.println(Student.count+"个Student对象");
    }
    public void set(String department,String speciality,String number,boolean member)
    {
        this.department=department==null?"":department;
        this.speciality=speciality==null?"":speciality;
        this.number=number==null?"":number;
        this.member=member;
    }
    public String toString()
    {
        return super.toString()+","+this.department+","+this.speciality+","+this.number+(member?",团员":"");
    }
    private static long n = 1;
    public static long test(long l) {
    String str = new SimpleDateFormat("yyyyMM")
    .format(new java.util.Date());
    long m = Long.parseLong((str)) * 10000;
    long ret = m + l;
    n = l + 1;
    return ret;
    }
    Scanner sc=new Scanner (System.in);
    @SuppressWarnings("unused")
    public void LuRuXinXi() {
        System.out.println("请输入姓名,出生日期(年,月,日),性别,籍贯(省、市),系,专业");
        name=sc.next();
        int year=sc.nextInt();
        int month=sc.nextInt();
        int day=sc.nextInt();
        MyDate myDate=new MyDate(year,month,day);
        gender=sc.next();
        province=sc.next();
        city=sc.next();
        department=sc.next();
        speciality=sc.next();
        System.out.println("录入成功!你的学号是:"+test(n));
    }
    public void LuRuChengji()
    {
        
    }
    public static void main(String[] args)
    {
        for(int i = 1;i<=6;i++) {
            System.out.println("1.录入基本信息");
            System.out.println("2.查找信息");
            System.out.println("3.录入成绩");
            System.out.println("4.成绩统计");
            System.out.println("0.退出 ");
            @SuppressWarnings("resource")
            Scanner sc=new Scanner(System.in);
            System.out.println("请输入您要选择操作的序号:");

            int option=sc.nextInt();
            if(option==0)
                break;
        switch(option){//选择服务
        case 1 :
            
            break;
        case 2:
            
            break;
        case 3:
           
            break;
        case 4:
            
            break;
        case 5:
           
            break;
        default : System.out.println("对不起,您的输入有误");
        break;
        }
        }
    }
    

}

在本次实验中,因能力有限,只初步完成了学号以各专业、年级分类自动编号,查找和增加变量未能实现。

posted @ 2019-05-06 20:49  这个包子有点可爱  阅读(204)  评论(0编辑  收藏  举报
Fork me on GitHub