java输出各种学生成绩

时间:2023-03-08 17:53:25
 class stu
{
public String stuno;
public String name;
public float math;
public float english;
public float computer;
public float sum;
public float average;
stu(String stuno1,String name1,float math1,float english1,float computer1) //构造函数
{
this.stuno = stuno1;
this.name = name1;
this.math = math1;
this.english = english1;
this.computer = computer1;
}
public void sum() //求和方法
{
sum = math + english + computer;
System.out.println("sum = " + sum);
}
public void average() //求平均值方法
{
average = sum / ;
System.out.println("average = " + average);
}
public void max() //求最大值方法
{
float max;
if(math > english)
if(math > computer)
max = math;
else
max = computer;
else
if(english > computer)
max = english;
else
max = computer;
System.out.println("最高分为:" + max);
}
public void min() //求最小值方法
{
float min;
if(math < english)
if(math < computer)
min = math;
else
min = computer;
else
if(english < computer)
min = english;
else
min = computer;
System.out.println("最低分为:" + min);
}
public void print() //输出方法
{
System.out.println("姓名:" + name + " 学号:" + stuno );
System.out.println("数学成绩:" + math + " 英语成绩:" + english + " 计算机成绩:" + computer);
}
}
class Student
{
public static void main(String args[])
{
stu stu1 = new stu("","马云",,,);
stu1.print();
stu1.sum();
stu1.average();
stu1.max();
stu1.min();
}
}

运行结果:

java输出各种学生成绩