java设计 定义并测试一个名为Student的类

定义并测试一个名为Student的类,包括属性有“学号”、“姓名”,以及3门课程“数学”、“英语”和“计算机”的成绩,包括的方法有计算3门课程的“总分”、“平均分”、“最高分”及“最低分”。


public class Student
{
private String stuNo;
private String stuName;
private int sxCj;
private int yuCj;
private int jsjCj;

public Student(String stuNo,String stuName,int sxCj,int yuCj,int jsjCj)
{
this.stuNo = stuNo;
this.stuName = stuName;
this.sxCj = sxCj;
this.yuCj = yuCj;
this.jsjCj = jsjCj;
}

public int zongfen()
{
return sxCj + yuCj + jsjCj;
}
public String getStuNo()
{
return stuNo;
}

public String getStuName()
{
return stuName;
}

public int junfen()
{
return zongfen() / 3;
}

public int maxFenshu()
{
return Math.max(Math.max(sxCj, yuCj), jsjCj);
}

public int minFenshu()
{
return Math.min(Math.min(sxCj, yuCj), jsjCj);
}

public static void main(String[] args)
{
Student a = new Student("111", "LIMing", 88, 99, 80);
System.out.println("学号:" + a.getStuNo());
System.out.println("姓名:" + a.getStuName());
System.out.println("总分:" + a.zongfen());
System.out.println("均分:" + a.junfen());
System.out.println("最高分:" + a.maxFenshu());
System.out.println("最低分:" + a.minFenshu());
}
}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-06-23
public class Student {
// 定义并测试一个名为Student的类,包括属性有“学号”、“姓名”,以及3门课程“数学”、
// “英语”和“计算机”的成绩,包括的方法有计算3门课程的“总分”、“平均分”、“最高分”及“最低分”。
private int id;
private String name;
private double math;
private double english;
private double computer;
public Student() {
super();
}
public Student(int id, String name, double math, double english,
double computer) {
super();
this.id = id;
this.name = name;
this.math = math;
this.english = english;
this.computer = computer;
}
public double sum() {
return math + english + computer;
}

public double ave() {
return this.sum() / 3;
}
public double lowest() {
double min = math < english ? math : english;
return min < computer ? min : computer;
}
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 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;
}

public static void main(String[] args) {
Student student = new Student(1, "zs", 66, 44, 55);
System.out.println(student.ave());
System.out.println(student.sum());
System.out.println(student.lowest());
}
}
第2个回答  2019-04-09
public class Student {
public static void main1(String[] args) {
}
private int id;
private String name;
private double math;
private double english;
private double computer;
public Student() {
}
public Student(int id, String name, double math, double english, double computer) {
this.id = id;
this.name = name;
this.math = math;
this.english = english;
this.computer = computer;
}
public double sum() {
return math + english + computer;
}
public double ave() {
return this.sum() / 3;
}
public double highest() {
double max = math > english ? math : english;
return max > computer ? max : computer;
}
public double lowest() {
double min = math < english ? math : english;
return min < computer ? min : computer;
}
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 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;
}
public static void main(String[] args) {
Student student = new Student(061741014, "lrl", 90, 88, 98);
System.out.println(student.sum());
System.out.println(student.ave());
System.out.println(student.highest());
System.out.println(student.lowest());
}
}
相似回答