java编程。急!!! 创建一个学生类,包含其学号,姓名,语文yw 数学sx 外语wy三科成绩 并

java编程。急!!!
创建一个学生类,包含其学号,姓名,语文yw 数学sx 外语wy三科成绩 并通过构造方法来确定该学生的学号和姓名。并为其传递各科的成绩值,用以创建该学生对象,另外再创建两个方法,一个用于计算该学生的三科平均成绩,一个用来输出学生的成绩等级。条件是,总成绩大于等于≥270 输出优等生,270>总成绩>240 良好,240到200为中等,200到180为及格,小于180不及格。然后输出学生平均成绩和成绩等级。

public class Student {
private String id,name;
private int yw,sx,wy;

public Student(String id,String name){
this.id=id;
this.name=name;
}

public int getYw() {
return yw;
}

public void setYw(int yw) {
this.yw = yw;
}

public int getSx() {
return sx;
}

public void setSx(int sx) {
this.sx = sx;
}

public int getWy() {
return wy;
}

public void setWy(int wy) {
this.wy = wy;
}

private int getaverage(){ //学生平均成绩
return (yw+sx+wy)/3;
}

private void getlevel(){  //等级
int n=yw+sx+wy;
if(n>=270)
System.out.println(name+"的平均成绩为:"+this.getaverage()+"等级为优等生"); 
else if(n>=240)
System.out.println(name+"的平均成绩为:"+this.getaverage()+"等级为良好"); 
else if(n>=200)
System.out.println(name+"的平均成绩为:"+this.getaverage()+"等级为中等"); 
else if(n>=180)
System.out.println(name+"的平均成绩为:"+this.getaverage()+"等级为及格"); 
else 
System.out.println(name+"的平均成绩为:"+this.getaverage()+"等级为不及格"); 

}
}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-11-03

public class Student {
    private String no;
    private String name;
    private double yw;
    private double sx;
    private double wy;
    public Student(String no, String name) {
        this.name = name;
        this.no = no;
    }
    public String getNo() {
        return no;
    }
    public void setNo(String no) {
        this.no = no;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public double getYw() {
        return yw;
    }
    public void setYw(double yw) {
        this.yw = yw;
    }
    public double getSx() {
        return sx;
    }
    public void setSx(double sx) {
        this.sx = sx;
    }
    public double getWy() {
        return wy;
    }
    public void setWy(double wy) {
        this.wy = wy;
    }
    public double getAvg() {
        return (yw + sx + wy) / 3;
    }
    public String getLevel() {
        double count = yw + sx + wy;
        String result = null;
        if (count >= 270) {
            result = "优等生";
        } else if (count >= 240) {
            result = " 良好";
        } else if (count >= 200) {
            result = " 中等";
        } else if (count >= 180) {
            result = " 及格";
        } else {
            result = " 不及格";
        }
        return result;
    }
    
    public static void main(String[] args) {
        Student stu = new Student("1", "张三");
        stu.setYw(100.0);
        stu.setSx(80.0);
        stu.setWy(90.0);
        
        System.out.println(stu.getAvg() + stu.getLevel());
    }
}

第2个回答  2015-11-03
class Student
{
private String name;

private int num;

private int yw;
private int sx;
private int wy;
public Student(int num,String name)

{
this.name=name;

this.num=num;

}

public void setYw(int yw)
{
this.yw=yw;

}
public int getYw()
{
return this.yw;
}
public void setSx(int sx)
{
this.sx=sx;
}
public int getSx()
{
return this.sx;
}
public void setWy(int wy)
{
this.wy=wy;
}
public int getWy()
{
return this.wy;
}
public static void avg()

{
int avg=(yx+sx+wy)/3;
System.out.println("avg");

}
public static void level()

{
int count =yw+sx+wy;

if(count>=270)

{System.out.println("优等生");}
else if(270>count>240)

{System.out.println("良好");}

else if(240>count>200)

{System.out.println("中等");}
else if(200>count>180)

{System.out.println("及格");}
else if(count<180)

{System.out.println("不及格");}
}
public static void main(String args)
{
Student s = new Student(1,"旺财");

s.setYw(150);
s.setSx(100);
s.setWy(10);
avg();
level();
}
}

应该是这样吧 ,总感觉少了点什么。。