zoukankan      html  css  js  c++  java
  • 三个系别学生类练习题

    /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));
    }
    }
  • 相关阅读:
    python note 30 断点续传
    python note 29 线程创建
    python note 28 socketserver
    python note 27 粘包
    python note 26 socket
    python note 25 约束
    Sed 用法
    python note 24 反射
    python note 23 组合
    python note 22 面向对象成员
  • 原文地址:https://www.cnblogs.com/lc-java/p/7392549.html
Copyright © 2011-2022 走看看