用JAVA创建一个学生类

[复制链接]
查看11 | 回复2 | 2010-3-24 22:16:37 | 显示全部楼层 |阅读模式
这个是最简单的吧,如果这个你还要问别人我觉得你还是放弃不要学了
回复

使用道具 举报

千问 | 2010-3-24 22:16:37 | 显示全部楼层
这个也问?唉,现在的学生啊
回复

使用道具 举报

千问 | 2010-3-24 22:16:37 | 显示全部楼层
//学生类public class Student{ private String stu_id; private String stu_name; private float math; private float chinese; private float computer;public void setStu_id(String stu_id){this.stu_id=stu_id; } public String getStu_id(){return stu_id; } public void setStu_name(String stu_name){this.stu_name=stu_name; } public String getStu_name(){return stu_name; } public void setMath(float math){this.math=math; } public float getMath(){return math; } public void setChinese(float chinese){this.chinese=chinese; } public float getChinese(){return chinese; } public void setComputer(float computer){this.computer=computer; } public float getComputer(){return computer; }}//主方法的类public class Start{ public static void main(String[] args){Student stu1=new Student();stu1.setStu_id("No1");stu1.setStu_name("张三");stu1.setMath(89.5f);stu1.setChinese(70f);stu1.setComputer(98f);Student stu2=new Student();stu2.setStu_id("No2");stu2.setStu_name("李四");stu2.setMath(79.5f);stu2.setChinese(90f);stu2.setComputer(68f);float stu1Sum = stu1.getMath()+stu1.getChinese()+stu1.getComputer();float stu2Sum = stu2.getMath()+stu2.getChinese()+stu2.getComputer();if(stu1Sum > stu2Sum){ System.out.println ("总分最高分为:"+stu1Sum); System.out.println ("学号:"+stu1.getStu_id()); System.out.println ("姓名:"+stu1.getStu_name()); System.out.println ("数学:"+stu1.getMath()); System.out.println ("语文:"+stu1.getChinese()); System.out.println ("计算机:"+stu1.getComputer());}else if(stu1Sum < stu2Sum){ System.out.println ("总分最高分为:"+stu2Sum); System.out.println ("学号:"+stu2.getStu_id()); System.out.println ("姓名:"+stu2.getStu_name()); System.out.println ("数学:"+stu2.getMath()); System.out.println ("语文:"+stu2.getChinese()); System.out.println ("计算机:"+stu2.getComputer());
}else{ System.out.println ("总分一样高为:"+stu1Sum); System.out.println ("学号:"+stu1.getStu_id()); System.out.println ("姓名:"+stu1.getStu_name()); System.out.println ("数学:"+stu1.getMath()); System.out.println ("语文:"+stu1.getChinese()); System.out.println ("计算机:"+stu1.getComputer()); System.out.println ("学号:"+stu2.getStu_id()); System.out.println ("姓名:"+stu2.getStu_name()); System.out.println ("数学:"+stu2.getMath()); System.out.println ("语文:"+stu2.getChinese()); System.out.println ("计算机:"+stu2.getComputer()); }
}}希望对你有帮助!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行