求大神编一个JAVA小程序
父类:人(姓名,年龄,性别);子类:学生(学生号,专业,入学时间,课程(4门)//数组);//需课程类方法:1.构造方法2.get/set方法3.显示所有信息toStri...
父类:人(姓名,年龄,性别);
子类:学生(学生号,专业,入学时间,课程(4门)//数组);//需课程类
方法:1.构造方法
2.get/set方法
3.显示所有信息toString方法
测试TestStudent.java 展开
子类:学生(学生号,专业,入学时间,课程(4门)//数组);//需课程类
方法:1.构造方法
2.get/set方法
3.显示所有信息toString方法
测试TestStudent.java 展开
4个回答
2015-05-23
展开全部
/**
* 父类:人(姓名,年龄,性别);
子类:学生(学生号,专业,入学时间,课程(4门)//数组);//需课程类
方法:1.构造方法
2.get/set方法
3.显示所有信息toString方法
测试TestStudent.java
* @author owner
*
*/
public class Person {
private String name;
private int age;
private String gender;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String toString() {
return "Person [age=" + age + ", gender=" + gender + ", name=" + name
+ "]";
}
public Person(String name, int age, String gender) {
super();
this.name = name;
this.age = age;
this.gender = gender;
}
public Person() {
super();
}
}
import java.util.Arrays;
import java.util.Date;
/**
* 子类:学生(学生号,专业,入学时间,课程(4门)//数组);
* @author owner
*
*/
public class Student extends Person {
public Student(String name, int age, String gender, int iD, String major,
Date enrollTime, Course[] stucourse) {
super(name, age, gender);
ID = iD;
this.major = major;
this.enrollTime = enrollTime;
this.stucourse = stucourse;
}
public Student() {
super();
}
public int getID() {
return ID;
}
public void setID(int iD) {
ID = iD;
}
public String toString() {
return "Student [ID=" + ID + ", enrollTime=" + enrollTime + ", major="
+ major + ", stucourse="
+ (stucourse != null ? Arrays.asList(stucourse) : null) + "]";
}
public String getMajor() {
return major;
}
public void setMajor(String major) {
this.major = major;
}
public Date getEnrollTime() {
return enrollTime;
}
public void setEnrollTime(Date enrollTime) {
this.enrollTime = enrollTime;
}
public Course[] getStucourse() {
return stucourse;
}
public void setStucourse(Course[] stucourse) {
this.stucourse = stucourse;
}
private int ID;
private String major;
private Date enrollTime;
private Course[] stucourse;
}
public class Course {
private int courseid;
private String coursename;
public int getCourseid() {
return courseid;
}
public void setCourseid(int courseid) {
this.courseid = courseid;
}
public String getCoursename() {
return coursename;
}
public void setCoursename(String coursename) {
this.coursename = coursename;
}
public Course(int courseid, String coursename) {
super();
this.courseid = courseid;
this.coursename = coursename;
}
public Course() {
super();
}
public String toString() {
return "Course [courseid=" + courseid + ", coursename="
+ coursename + "]";
}
}
import java.util.Date;
public class TestStudent {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Course c[]=new Course[2];
c[0].setCourseid(101);
c[0].setCoursename("程序设计");
c[1].setCourseid(102);
c[1].setCoursename("计算机分析");
c[0].toString();
Student s1=new Student("张三",18,"男",1001,"计算机",new Date(),c);
s1.toString();
}
}
* 父类:人(姓名,年龄,性别);
子类:学生(学生号,专业,入学时间,课程(4门)//数组);//需课程类
方法:1.构造方法
2.get/set方法
3.显示所有信息toString方法
测试TestStudent.java
* @author owner
*
*/
public class Person {
private String name;
private int age;
private String gender;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String toString() {
return "Person [age=" + age + ", gender=" + gender + ", name=" + name
+ "]";
}
public Person(String name, int age, String gender) {
super();
this.name = name;
this.age = age;
this.gender = gender;
}
public Person() {
super();
}
}
import java.util.Arrays;
import java.util.Date;
/**
* 子类:学生(学生号,专业,入学时间,课程(4门)//数组);
* @author owner
*
*/
public class Student extends Person {
public Student(String name, int age, String gender, int iD, String major,
Date enrollTime, Course[] stucourse) {
super(name, age, gender);
ID = iD;
this.major = major;
this.enrollTime = enrollTime;
this.stucourse = stucourse;
}
public Student() {
super();
}
public int getID() {
return ID;
}
public void setID(int iD) {
ID = iD;
}
public String toString() {
return "Student [ID=" + ID + ", enrollTime=" + enrollTime + ", major="
+ major + ", stucourse="
+ (stucourse != null ? Arrays.asList(stucourse) : null) + "]";
}
public String getMajor() {
return major;
}
public void setMajor(String major) {
this.major = major;
}
public Date getEnrollTime() {
return enrollTime;
}
public void setEnrollTime(Date enrollTime) {
this.enrollTime = enrollTime;
}
public Course[] getStucourse() {
return stucourse;
}
public void setStucourse(Course[] stucourse) {
this.stucourse = stucourse;
}
private int ID;
private String major;
private Date enrollTime;
private Course[] stucourse;
}
public class Course {
private int courseid;
private String coursename;
public int getCourseid() {
return courseid;
}
public void setCourseid(int courseid) {
this.courseid = courseid;
}
public String getCoursename() {
return coursename;
}
public void setCoursename(String coursename) {
this.coursename = coursename;
}
public Course(int courseid, String coursename) {
super();
this.courseid = courseid;
this.coursename = coursename;
}
public Course() {
super();
}
public String toString() {
return "Course [courseid=" + courseid + ", coursename="
+ coursename + "]";
}
}
import java.util.Date;
public class TestStudent {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Course c[]=new Course[2];
c[0].setCourseid(101);
c[0].setCoursename("程序设计");
c[1].setCourseid(102);
c[1].setCoursename("计算机分析");
c[0].toString();
Student s1=new Student("张三",18,"男",1001,"计算机",new Date(),c);
s1.toString();
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
class Person{
private String name;
private int age;
private String sex;
get set toString 都自己写吧
}
class Student extend Person{
属性 和 get set toString 都自己写吧
}
public class TestStudent{
public static void main(String[] args){
Person p = new Person();
system.out.println(p);
Person s = new Student();
system.out.println(s)
}
}
private String name;
private int age;
private String sex;
get set toString 都自己写吧
}
class Student extend Person{
属性 和 get set toString 都自己写吧
}
public class TestStudent{
public static void main(String[] args){
Person p = new Person();
system.out.println(p);
Person s = new Student();
system.out.println(s)
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
System.out.println("=======a======");
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
给五分让人写程序 够大方的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询