一道java题 请设计一个学生类Student。属性包括:学号、姓名、英语成绩、数学成绩、计算机

2024-11-18 02:48:16
推荐回答(5个)
回答1:

public class Student
{
    private String stuId;
    private String name;
    private float englishScore;
    private float mathScore;
    private float computerScore;
    private float sumScore;
    public Student()
    {
    }
    public Student(String stuId, String name, float englishScore,
            float mathScore, float computerScore)
    {
        this.stuId = stuId;
        this.name = name;
        this.englishScore = englishScore;
        this.mathScore = mathScore;
        this.computerScore = computerScore;
        this.sumScore = sum();
    }
    
    public String getStuId()
    {
        return stuId;
    }
    public void setStuId(String stuId)
    {
        this.stuId = stuId;
    }
    public String getName()
    {
        return name;
    }
    public void setName(String name)
    {
        this.name = name;
    }
    public float sum()
    {
        return  sumScore = englishScore + mathScore + computerScore;
    }
    public float testScore()
    {
        碰蠢return sum()/3;
    }
    public String compare(Student student)
    {
        if(this.sumScore > student.sum())
            return "大于";
        else if(this.sumScore == student.sum())
            return "等于";
        else return "小于";
    }
    public static void main(String[] args)
    {
        Student tim = new Student("0001", "tim", 90, 90, 90);
        Student tom = new Student("0001", "tom", 80, 90, 95);
        System.out.println("tim的测评成绩:"+tim.testScore());
        System.out.println("tom的测评成绩:"+tom.testScore());
  迹吵橘      System.out.println("tim总成绩姿团  "+tim.compare(tom)+"  tom总成绩");
    }  
}

  上面的代码作为作业应该够用了,如果应用最好重写equals和hashCo方法。

回答2:

ublic class Student { // 学号 private String studentNo; // 姓名 private String name; //迅陵 英语成绩 private Double enlishScore; // 数学成绩 private Double mathScore; // 计算银郑机 private Computer computer; public String getStudentNo() { return studentNo; } public void setStudentNo(String studentNo) { this.studentNo = studentNo; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Double getEnlishScore() { return enlishScore; } public void setEnlishScore(Double enlishScore) { this.enlishScore = enlishScore; } public Double getMathScore() { return mathScore; } public void setMathScore(Double mathScore) { this.mathScore = mathScore; } public Computer getComputer() { return computer; } public void setComputer(Computer computer) { this.computer = computer; }} /** * 计算机类锋昌颂 * * @author Administrator * */class Computer { // 计算机名 private String name; // 系统版本号 private String sysInfo; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getSysInfo() { return sysInfo; } public void setSysInfo(String sysInfo) { this.sysInfo = sysInfo; } }

回答3:

public class Student implements Comparable {
 
 private int id;
 private String name;
 乎桥private int englishScore;
 private int mathScore;
 private int computerScore;
 private int totalScore;
 
 public Student(int id, String name, int englishScore, int mathScore,
   int computerScore, int totalScore) {
  this.id = id;
  this.name = name;
  this.englishScore = englishScore;
  this.mathScore = mathScore;
  this.computerScore = computerScore;
  this.totalScore = sum();
 }
 public int sum() {
  return englishScore 裂胡+ mathScore + computerScore;
 }
 public int compareTo(Student s) {
  if(this.totalScore > s.totalScore) {
 岁源猛  return -1;
  } else if(this.totalScore == s.totalScore) {
   return 0;
  } else {
   return 1;
  }
 }
 
 public double testScore() {
  return (double)this.totalScore/3;
 }
}

回答4:

public class 绝告告Student {
// 学号
private String studentNo;
// 姓名
private String name;
// 英语成绩
private Double enlishScore;
// 数学成绩
private Double mathScore;
// 计算机
private Computer computer;

public String getStudentNo() {
return studentNo;
}

public void setStudentNo(String studentNo) {
this.studentNo = studentNo;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public Double getEnlishScore() {
return enlishScore;
}

public void setEnlishScore(Double enlishScore) {
this.enlishScore = enlishScore;
}

public Double getMathScore() {
return mathScore;
}

public void setMathScore(Double mathScore) {
this.mathScore 并明= mathScore;
}

public Computer getComputer() {
return computer;
}

public void setComputer(Computer computer) {
this.computer = computer;
}
}

/**
 * 计算机类
 * 
 * @author Administrator
 *
 */
class Computer {
// 计算机名
private String name;
// 系统版本号
private String sysInfo;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getSysInfo() {
return sysInfo;
}

public void setSysInfo(String 友基sysInfo) {
this.sysInfo = sysInfo;
}

}

回答5:

package com.zhidao20161213;

public class Student {
    private String num;
    private String name;
    private double math;
    private double english;
    private double computer;
    public String getNum() {
        return num;
    }
    public void setNum(String num) {
        this.num = num;
    }
    public String getName() {
        return 信橘慧name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public double getMath() {
        return math;
    }
    public void setMath(double math) {
        this.math = math;
    }
    伍姿public double getEnglish() {
        return english;
    }
    public void setEnglish(double english) {
        this.english = english;
    }
    public double getComputer() {
        return computer;
    }
    滑答public void setComputer(double computer) {
        this.computer = computer;
    }
    

}