我是靠谱客的博主 单纯老师,这篇文章主要介绍山科java作业2-3 125 - 学生、大学生、研究生类125 - 学生、大学生、,现在分享给大家,希望可以做个参考。

125 - 学生、大学生、

Description

复制代码
1
2
3
4
定义Student学生类,拥有学号、姓名、性别属性,提供构造函数,以及相应属性的get set函数,提供函数attendClass(String className)表示上课。 定义CollegeStudent大学生类继承自Student类,拥有新增属性专业,提供构造函数,提供新增属性的get和set函数 定义GraduateStudent研究生类继承自CollegeStudent类,拥有新增属性导师,提供构造函数,提供新增属性的get和set函数,提供函数doResearch() 表示做研究(打印xx is doing research)。 main函数中对构造的类进行测试

Input

复制代码
1
2
3
学生类信息,学号、姓名、性别 大学生类信息,学号、姓名、性别、专业 研究生类信息,学号、姓名、性别、专业、导师

Output

复制代码
1
2
3
学生类信息 大学生类信息 研究生类信息

Sample Input

复制代码
1
2
3
1 liu female 2 chen female cs 3 li male sc wang

Sample Output

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
no: 1 name: liu sex: female no: 2 name: chen sex: female major: cs no: 3 name: li sex: male major: sc supervisor: wang li is doing research

Pre Append Code

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner scan = new Scanner(System.in); int no = scan.nextInt(); String name = scan.next(); String sex = scan.next(); Student s = new Student(no, name, sex); s.print(); no = scan.nextInt(); name = scan.next(); sex = scan.next(); String major = scan.next(); CollegeStudent c = new CollegeStudent(no, name, sex, major); c.print(); no = scan.nextInt(); name = scan.next(); sex = scan.next(); major = scan.next(); String supervisor = scan.next(); GraduateStudent g = new GraduateStudent(no, name, sex, major, supervisor ); g.print(); g.doResearch(); scan.close(); } }

 Post Append Code

 

答案:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package 学生大学生研究生类; import java.util.Scanner; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner scan = new Scanner(System.in); int no = scan.nextInt(); String name = scan.next(); String sex = scan.next(); Student s = new Student(no, name, sex); s.print(); no = scan.nextInt(); name = scan.next(); sex = scan.next(); String major = scan.next(); CollegeStudent c = new CollegeStudent(no, name, sex, major); c.print(); no = scan.nextInt(); name = scan.next(); sex = scan.next(); major = scan.next(); String supervisor = scan.next(); GraduateStudent g = new GraduateStudent(no, name, sex, major, supervisor ); g.print(); g.doResearch(); scan.close(); } } class Student { int no; String name; String gender; public Student(int _no, String n, String g) { this.no = _no; this.name = n; this.gender = g; } public int getNo() { return no; } public void setNo(int no) { this.no = no; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getGender() { return gender; } public void setGender(String gender) { this.gender = gender; } public void print() { System.out.println("no: "+getNo()); System.out.println("name: "+getName()); System.out.println("sex: "+getGender()); } } class CollegeStudent extends Student { String major; public CollegeStudent(int _no, String n, String g, String major) { super(_no, n, g); this.major = major; } public String getMajor() { return major; } public void setMajor(String major) { this.major = major; } public void print() { super.print(); System.out.println("major: "+getMajor()); } } class GraduateStudent extends CollegeStudent { String supervisor;//导师 public GraduateStudent(int _no, String n, String g, String major, String supervisor) { super(_no, n, g, major); this.supervisor = supervisor; } public String getSupervisor() { return supervisor; } public void setSupervisor(String supervisor) { this.supervisor = supervisor; } public void doResearch() { System.out.println(getName()+" is doing research"); } public void print(){ super.print(); System.out.println("supervisor: "+supervisor); } }

 

最后

以上就是单纯老师最近收集整理的关于山科java作业2-3 125 - 学生、大学生、研究生类125 - 学生、大学生、的全部内容,更多相关山科java作业2-3内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(84)

评论列表共有 0 条评论

立即
投稿
返回
顶部