class Student2{
private String name;
private int age;
private float english;
private float computer;
private float math;
public Student2(){}
public Student2(String n,int a,float e,float c,float m){
this.setName(n);
this.setAge(a);
this.setEnglish(e);
this.setComputer(c);
this.setMath(m);
}
public float sum(){
return english+computer+math;
}
public float avg(){
return this.sum()/3;
}
public float max(){
float max=computer>math?computer:math;
max=max>english?max:english;
return max;
}
public float min(){
float min=computer<math?computer:math;
min=min<english?min:english;
return min;
}
public String getInfo(){
return "student information:\n"+
"\t|- name is"+this.getName()+"\n"+
"\t|- age is"+this.getAge()+"\n"+
"\t|- math is"+this.getMath()+"\n"+
"\t|- english is"+this.getEnglish()+"\n"+
"\t|- computer is"+this.getComputer();
}
public void setName(String n){
name = n;
}
public void setAge(int a){
age = a;
}
public void setEnglish(float e){
english = e;
}
public void setComputer(float c){
computer = c;
}
public void setMath(float m){
math = m;
}
public String getName(){
return name;
}
public int getAge(){
return age;
}
public float getEnglish(){
return english;
}
public float getComputer(){
return computer;
}
public float getMath(){
return math;
}
}
public class Demo12 {
public static void main(String args[]){
Student2 stu = new Student2("zhangsan",30,89.0f,91.0f,87.0f);
System.out.println("the sum"+stu.sum());
System.out.println("the avg"+stu.avg());
System.out.println("the max"+stu.max());
System.out.println("the min"+stu.min());
System.out.println(stu.getInfo());
}
}
各位大神,帮忙看看究竟是哪里出错了。好像环境变量应该没问题,其他程序都可以正常运行~
------解决方案--------------------
public class Demo12 {
public static void main(String args[]){
Student2 stu = new Student2("zhangsan",30,89.0f,91.0f,87.0f);
System.out.println("the sum"+stu.sum());
System.out.println("the avg"+stu.avg());
System.out.println("the max"+stu.max());
System.out.println("the min"+stu.min());
System.out.println(stu.getInfo());
}
把public 删掉
class Demo12 {
public static void main(String args[]){
Student2 stu = new Student2("zhangsan",30,89.0f,91.0f,87.0f);
System.out.println("the sum"+stu.sum());
System.out.println("the avg"+stu.avg());
System.out.println("the max"+stu.max());
System.out.println("the min"+stu.min());
System.out.println(stu.getInfo());
}
------解决方案--------------------
在我这里没有错,请检查你的运行环境
------解决方案--------------------