⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 25.txt

📁 是一个 java 基础学习软件 有设计说明
💻 TXT
字号:
//
//  类实例  --  生日

////   main
public class Birthday
{
	public static void main(String[] args)
	{
		Birthday d1 = new Birthday(11,3,2003);
		Birthday d2 = new Birthday();

		System.out.println("功能1");
		d1.showDay();        ///  d1 11-3-2003
		d2.copyDay(d2,d1);  ///  copy d1 to d2

		d2.showDay();      ///    d2 11-3-2003
		d1.showDay();	  ///     d1 11-3-2003

		System.out.println("功能2");
		d2.addAweek(d2);      ///   add a week
		d2.showDay();       ///  d2  18-3-2003

		d1.setBirthday(25,12,2003);
		d1.showDay();          ///d1  25-3-2003
		d1.addAweek(d1);
		d1.showDay();         /// d1  2-4-2003
		d2.showDay();        ///  d2  18-3-2003

		System.out.println(d1+"  "+d2);    ///  d1  !=  d2
	}

	private int day;
	private int month;
	private int year;
	public Birthday(){}
	public Birthday(int d,int m,int y)
	{
			day = d;
			month = m;
		year = y;
	}
	public void setBirthday(int d,int m,int y) ///set day
	{
		day = d;
		month = m;
		year = y;
	}
	public int getDay()    { return day; }
	public int getMonth()    { return month; }
	public int getYear()    { return year;}

	public Birthday copyDay(Birthday d1,Birthday d2)   ///  copy day
	{
		d1.setBirthday(d2.getDay(),d2.getMonth(),d2.getYear());
		return d1;
	}

	public Birthday addAweek(Birthday d)   ///  add a week
	{

		if(d.day>23)            ///  day >23
		{
			day = d.day+7-30;
			if(d.month==12)     ///  month =12
			{
				year=d.year+1;
				month=1;
			}
			else
			{
				year = d.year;
				month = d.month+1;
			}
		}
		else
		{
			year = d.year;
			month=d.month;
			day = d.day+7;
		}
		return this;
	}

	public void showDay()                   ///  show day
	{
	        System.out.println("Birthday:  "+day + " - " + month + " - " + year);
	}
}

///
实例二      人 -- 学生
//

package test.person;

import java.util.Date;

public class Person
{
	String name;
	int age;
	String sex;
	Date Birthday ;
	/// 得到姓名
	public String getNmae()	{ return name;	}
	/// 得到生日
	public Date getBrithday()   {	return Birthday;	}
	/// 设置年龄  性别
	/// 得到年龄
	public String getSex()	{ return sex;	}
	/// 得到年龄
	public int getAge()   {	return age;	}
	/// 设置年龄  性别
	public void setPro(String name,int age,int j,Date Birthday)
	{
		this.name = name;
		this.age=age;
		if (j==0)
			sex="男";
		else
			sex="女";
		this.Birthday= Birthday;
	}
	public void show()
	{
		System.out.println(name+"  的性别是: "+getSex()+"  "+Birthday+" 出生: 年龄是: "+getAge());
	}
}

//

package test.person;

import test.person.Person;

public class Parent extends Person{

	public String getInfo() {
	     return "Name: "+ name + "\n" +"age: "+ age;
	}

}

//

package test.person;

import test.person.Parent;

public class Child extends Parent {
	protected String nam ="kkkkk";
	protected String school= " hsdj   high school";
	public String getInfo() {
	    return  "Name: "+ name + "\nage: "+ age
	       + "\nschool: "+ school+"\nparent is :"+super.name;
	}

}
//
package test.person;

import test.person.Student;

public class Graduate extends Student
{
	String major;
	public void register(){}
}
//
package test.person;

import test.person.Person;

public class Student extends Person
{
	String school;
	public String getSchool(){return this.school;}
	public void setSchool (String school){ this.school = school; }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -