java,1. 学生类; 2. 课程类; 3. 教师类; 4. 写一个 demo类,这个实例化,学生,课程,老师的对象,在输出一下简单信息

  1. 学生类;
  2. 课程类;
  3. 教师类;
  4. 写一个 demo类,这个实例化,学生,课程,老师的对象,在输出一下简单信息

学生类

package one;
//导入包
import java.util.Date;

public class Student {
	String id;//学号
	String name;//姓名
	String sex;//性别
	Date birthday;//生日
	String address;//家庭住址
	String iddress;//户口所在地
	Date school;//入学时间
	//无参构造
	public Student(){
		
		
	}
	//有参构造
	public  Student(String id,String name,String sex,Date birthday,Date school,String address){
		
		this.id=id;
		this.name=name;
		this.sex=sex;
		this.birthday=birthday;
		this.school=school;
		this.address=address;
	}
	//返回学生,学号
	public String getid(){
		return this.id;
		
	}
	//返回学生姓名
	public String getname(){
		return this.name;
		
	}
	//返回学生性别
		public String getsex(){
			return this.sex;
			
		}
		
		//返回学生年龄
		public int getAge(){
			int age=0;
			Date now=new Date();
			age=now.getYear()-this.birthday.getYear();
			return age;
			
		}
		//返回入学年龄
		public Date getschoolDate(){
			return this.school;
		}
		//返回学生地址
		public String getAddress(){
			return this.address;
		}
		//显示学生所有信息
		public String StudentInfo(){
			String stu="学号:"+this.id+
						"\t姓名:"+this.name+
						"\t性别:"+this.sex+
						"\t生日:"+this.birthday+
						"\t入校时间:"+this.school+
						"\t户口所在地:"+this.iddress+
						"\t家庭住址:"+this.address;
					
			return stu;
			
		}
	
}

老师类

package one;
//教师类
public class Teacher {
	String teacherid;	//工号
	String teacherName;	//姓名
	String teacherPosition;//职位
	int teacherAge;//年龄
	String teacherAddress;//住址
	//无参构造
	public Teacher(){
		
	}
	//有参构造
	public Teacher(String teacherid,String teacherName,String teacherPosition,int teacherAge,String teacherAddress){
		this.teacherid=teacherid;
		this.teacherName=teacherName;
		this.teacherPosition=teacherPosition;
		this.teacherAge=teacherAge;
		this.teacherAddress=teacherAddress;
	}
	public String getteacherid(){
		return this.teacherid;//返回教师工号
	}
	public String getteacherName(){
		return this.teacherName;//返回教师姓名
	}
	public String teacherPosition(){
		return this.teacherPosition();//返回教职工职位
	}
	public int getTeacherAge(){
		return  this.teacherAge;//返回教师年龄
	}
	public String teacherAddress(){
		return this.teacherAddress;//返回教师住址
	}
	//显示教师的所有的信息
	public String teacherInfo(){
		String tea="教师工号:"+this.teacherid+
					"\t教师姓名:"+this.teacherName+
					"\t教师职位:"+this.teacherPosition+
					"\t教师年龄:"+this.teacherAge+
					"\t教师职业:"+this.teacherAddress;
		return tea;
					
	}
}



课程类

package one;
//课程类
public class Course {
//定义课程属性
	String courseid;//课程编号
	String courseName;//课程名字
	//无参构造
	public Course(){
		
	}
	//有参构造
	public Course(String courseid,String courseName){
		this.courseid=courseid;
		this.courseName=courseName;
	}
	public String getcourseid(){//返回课程编号
		return this.courseid;
		
	}
	public String getCoureseName(){//返回课程的名字
		return this.courseName;
		
	}
	//显示课程所以的信息
	public String CourseInfo(){
		String cou="课程编号:"+this.courseid+
				"\t课程名字:"+this.courseName;
		return cou;
		
	}
	
}



测试类

package one;

import java.util.Date;

//测试类
public class Demo {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Student stu=new  Student();//学生实例化
		stu.id="2020";
		stu.name="XXX";
		stu.sex="男";
		
		stu.birthday=new Date();
		stu.school=new Date();
		String Date="2000-11-11";
		Date now=new Date(2000-2088,02,23);
		
		stu.iddress="XX";
		stu.address="XXXX";
		System.out.println(stu.StudentInfo());
		
		Teacher tea=new Teacher();//教师实例化
		tea.teacherid="10000";
		tea.teacherName="李明";
		tea.teacherPosition="讲师";
		tea.teacherAge=36;
		tea.teacherAddress="XXXX";
		System.out.println(tea.teacherInfo());
		
		Course cou=new Course();//课程实例化
		cou.courseid="1000";
		cou.courseName="java 软件编程";
		System.out.println(cou.CourseInfo());
				
	}

}



  • 3
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值