码迷,mamicode.com
首页 > 其他好文 > 详细

三个系别学生类练习题

时间:2017-08-18 23:45:24      阅读:244      评论:0      收藏:0      [点我收藏+]

标签:lis   rtm   pre   put   protected   ldl   als   main   dom   

/Student

package Student;

abstract class Student{
protected int id;
protected String name;
protected char sex;
protected int age;
protected int termEndScore;
protected int termMilldleScore;
protected int totalScore;
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public char getSex() {
return sex;
}
public void setSex(char sex) {
this.sex = sex;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getTermEndScore() {
return termEndScore;
}
public void setTermEndScore(int termEndScore) {
this.termEndScore = termEndScore;
}
public int getTermMilldleScore() {
return termMilldleScore;
}
public void setTermMilldleScore(int termMilldleScore) {
this.termMilldleScore = termMilldleScore;
}
public void setTotalScore(int totalScore) {
this.totalScore = totalScore;
}
public abstract int getTotalScore();
public String toString(){
return  id + "  :" + name + "  : " + sex+ " : " + age + "  : " + getTotalScore();
}
}

  /EnglishMajor

package Student;

class EnglishMajor extends Student{
private int presentationScore;
public int getTotalScore() {
return (int) (presentationScore * 0.5 + termEndScore * 0.25 + termMilldleScore*0.25);
}
public int getPresentationScore() {
return presentationScore;
}
public void setPresentationScore(int presentationScore) {
this.presentationScore = presentationScore;
}
}

  /  ComputerMajor

  

package Student;

class ComputerMajor extends Student{
private int operationScore;
private int englishScore;
public int getTotalScore() {
return (int) (operationScore * 0.4 + operationScore*0.2 + termEndScore * 0.2 + termMilldleScore *0.2);
}
public int getEnglishScore() {
return englishScore;
}
public void setEnglishScore(int englishScore) {
this.englishScore = englishScore;
}
public int getOperationScore() {
return operationScore;
}
public void setOperationScore(int operationScore) {
this.operationScore = operationScore;
}
}

  /ArtMajor

package Student;

class ArtMajor extends Student{
private int prensentationScore;
private int workScore;
public int getTotalScore() {
return (int) (prensentationScore * 0.35 + workScore * 0.35 + termMilldleScore * 0.15 + termEndScore *0.15);
}
public int getPrensentationScore() {
return prensentationScore;
}
public void setPrensentationScore(int prensentationScore) {
this.prensentationScore = prensentationScore;
}
public int getWorkScore() {
return workScore;
}
public void setWorkScore(int workScore) {
this.workScore = workScore;
}
}
package Student;

import java.util.Random;
public class Test {
public static void main(String[] args) {
Student[] students = new Student[5];
Random rand = new Random();
//EnglishMajor student 001
EnglishMajor englishStu001 = new EnglishMajor();
createStudent(rand, englishStu001);
englishStu001.setName("English major student 001");
englishStu001.setPresentationScore(rand.nextInt(101));
englishStu001.setSex(F);
students[0] = englishStu001;
// ArtMajor student 001
ArtMajor artMajorStu = new ArtMajor();
createStudent(rand, artMajorStu);
artMajorStu.setName("ArtMajor major student 002");
artMajorStu.setWorkScore(rand.nextInt(101));
artMajorStu.setPrensentationScore(rand.nextInt(101));
artMajorStu.setSex(M);
students[1] = artMajorStu;
//student 003
ComputerMajor computerMajorStu = new ComputerMajor();
createStudent(rand, computerMajorStu);
computerMajorStu.setName("ComputerMajor major student 003");
computerMajorStu.setOperationScore(rand.nextInt(101));
computerMajorStu.setSex(M);
students[2] = computerMajorStu;
//student 001
Student student = new ComputerMajor();
createStudent(rand, artMajorStu);
student.setName("student 0013");
student.setSex(F);
students[3] = student;
//
artMajorStu = new ArtMajor();
createStudent(rand, artMajorStu);
artMajorStu.setName("ArtMajor major student 004");
artMajorStu.setWorkScore(rand.nextInt(101));
artMajorStu.setPrensentationScore(rand.nextInt(101));
artMajorStu.setAge(F);
students[4] = artMajorStu;
for(int i = 0; i < students.length; i++){
System.out.println(students[i].toString());
}
}
private static void createStudent(Random rand, Student stu) {
stu.setId(rand.nextInt(200));
stu.setTermEndScore(rand.nextInt(101));
stu.setTermMilldleScore(rand.nextInt(101));
stu.setAge(rand.nextInt(100));
}
}

 

三个系别学生类练习题

标签:lis   rtm   pre   put   protected   ldl   als   main   dom   

原文地址:http://www.cnblogs.com/lc-java/p/7392549.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!