package test;
class xuesheng
{
private String name;
private int age;
private float computer;
private float math;
private float english;
public xuesheng(){}
public xuesheng(String n,int a,float c,float m,float e) {
this.setName(n);
this.setAge(a);
this.setComputer(c);
this.setMath(m);
this.setEnglish(e);
}
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"学生信息 : \n"+
"\t|-姓名:" + this.getName() + "\n" +
"\t|-年龄:" + this.getAge() + "\n" +
"\t|-计算机成绩:" + this.getComputer() + "\n" +
"\t|-数学成绩:" + this.getMath() + "\n" +
"\t|-英语成绩:" + this.getEnglish();
}
public void setName(String n)
{
name = n;
}
public void setAge(int a)
{
age = a;
}
public void setComputer(float c)
{
computer = c;
}
public void setMath(float m)
{
math = m;
}
public void setEnglish(float e)
{
english = e;
}
public String getName()
{
return name;
}
public int getAge()
{
return age;
}
public float getComputer()
{
return computer;
}
public float getMath()
{
return math;
}
public float getEnglish()
{
return english;
}
}
public class two {
public static void main(String args[])
{
xuesheng xue = new xuesheng("李四",16,99f,85f,90f);
System.out.println(xue.getInfo());
System.out.println("总分" + xue.sum());
System.out.println("平均分" + xue.avg());
System.out.println("最高分" + xue.max());
System.out.println("最低分" + xue.min());
}
}
试问,类为什么这样创建?其中的"get..." "set....."起什么作用?这个类的创建基本方法是啥?
class xuesheng
{
private String name;
private int age;
private float computer;
private float math;
private float english;
public xuesheng(){}
public xuesheng(String n,int a,float c,float m,float e) {
this.setName(n);
this.setAge(a);
this.setComputer(c);
this.setMath(m);
this.setEnglish(e);
}
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"学生信息 : \n"+
"\t|-姓名:" + this.getName() + "\n" +
"\t|-年龄:" + this.getAge() + "\n" +
"\t|-计算机成绩:" + this.getComputer() + "\n" +
"\t|-数学成绩:" + this.getMath() + "\n" +
"\t|-英语成绩:" + this.getEnglish();
}
public void setName(String n)
{
name = n;
}
public void setAge(int a)
{
age = a;
}
public void setComputer(float c)
{
computer = c;
}
public void setMath(float m)
{
math = m;
}
public void setEnglish(float e)
{
english = e;
}
public String getName()
{
return name;
}
public int getAge()
{
return age;
}
public float getComputer()
{
return computer;
}
public float getMath()
{
return math;
}
public float getEnglish()
{
return english;
}
}
public class two {
public static void main(String args[])
{
xuesheng xue = new xuesheng("李四",16,99f,85f,90f);
System.out.println(xue.getInfo());
System.out.println("总分" + xue.sum());
System.out.println("平均分" + xue.avg());
System.out.println("最高分" + xue.max());
System.out.println("最低分" + xue.min());
}
}
试问,类为什么这样创建?其中的"get..." "set....."起什么作用?这个类的创建基本方法是啥?
