qq_37053884 2016-12-15 11:39 采纳率: 100%
浏览 883
已采纳

java一个小题目,题目在图片里,答案我写出来了一半,感觉错误很多,盲区很多,求大神指正

答案:
import javax.swing.JOptionPane;

public class Student {
private static String name;
private static String id;
private float chinese;
private float math;
private float english;
public Student(String name, String id){
this.name="张三";
this.id=id;
}
public float average(){
float avg=(chinese+math+english)/3;
if(avg>90.0){
System.out.println("属于三好学生");
}
else{
System.out.println("不属于三好学生");
}
return avg;
}
public float score(){
return(chinese+math+english);
}
public boolean goodstudent(){
float avg=average();
return avg>90.0;

}
public String setName(){
    return this.name=name;
}
public String getName(){
    return name;
}
public void steId(String id){
    this.id=id;
}
//public float getChinese(){
//  return chinese;
//}
public void setChinese(float chinese){
    this.chinese=chinese;
}
public float getMath(){
    return math;
}
public void setMath(float math){
    this.math=math;
}
public float getEnglish(){
    return english;
}
public void setEnglish(float english){
    this.english=english;
}
//public String totring(){
//  return"当前学生信息为:[姓名="+name+",学号="+id+",语文成绩="+chinese+",数学成绩="+math+",英语成绩="+english+"]";

// }

public static void main(String[]args){
// StudentDemo a=new StudentDemo();
//StudentDemo b=new StudentDemo();

String chinese = JOptionPane.showInputDialog(null,"考试成绩","语文",1);
String math = JOptionPane.showInputDialog(null,"考试成绩","数学",1);
String english= JOptionPane.showInputDialog(null,"考试成绩","英语",1);
double a=Integer.parseInt(chinese);
double b=Integer.parseInt(math);
double c=Integer.parseInt(english);
double score=a+b+c;
Student s=new Student(name,id);

System.out.println("姓名: wang");
System.out.println("语文成绩 "+chinese);
System.out.println("数学成绩 "+math);
System.out.println("英语成绩 "+english);
//System.out.println("姓名: "+a.getName());
//System.out.println("学号: "+b.getId());

System.out.println("总成绩: "+score);
//System.out.println("平均成绩:"+s.score());

if(a+b+c>=270)
{
    System.out.print("该同学是三好学生");

}
}

}

}图片

  • 写回答

2条回答 默认 最新

  • 代码的灵魂是bug! 2016-12-15 15:25
    关注

    这是我写的,但不是通过对话框输入成绩,你可以参考参考,若觉得可以,请采纳^_^
    Student类:

    public class Student {
        private String name;
        private String id;
        private float chinese;
        private float math;
        private float english;
        public Student() {
            super();
            this.name="张三";
            this.id="111111";
        }
    
        public Student(String name, String id) {
            super();
            this.name = name;
            this.id = id;
        }
        //总成绩
        public float score(float chinese,float math,float english){
            return chinese+math+english;
        }
        //平均成绩
        public float average(float chinese,float math,float english){
            float avg=(chinese+math+english)/3;
            return avg;
        }
        //三好学生
        public void goodstudent(float chinese,float math,float english){
            float good=average(chinese, math, english);
            if(good>90.0){
                System.out.println("你是三好学生");
            }else{
                System.out.println("你还不是三好学生哦");
            }
        }
    
        public String getName() {
            return name;
        }
    
        public void setName(String name) {
            this.name = name;
        }
    
        public String getId() {
            return id;
        }
    
        public void setId(String id) {
            this.id = id;
        }
    
        public float getChinese() {
            return chinese;
        }
        public void setChinese(float chinese) {
            this.chinese = chinese;
        }
        public float getMath() {
            return math;
        }
        public void setMath(float math) {
            this.math = math;
        }
        public float getEnglish() {
            return english;
        }
        public void setEnglish(float english) {
            this.english = english;
        }
    
    }
    
    

    studentDemo类:

     import java.util.Scanner;
    
    public class studentDemo {
    
        /**
         * @param args
         */
        public static void main(String[] args) {
            Scanner s = new Scanner(System.in);
    
            Student student = new Student("李四", "222222");
            float yuwen, shuxue, yingyu;
    
            System.out.println("请输入你的三科成绩,以空格隔开:");
            yuwen = s.nextInt();
            shuxue = s.nextInt();
            yingyu = s.nextInt();
            for (int i = 0; i < 3; i++) {
                if ((yuwen > 0 && yuwen <= 100) && (shuxue > 0 && shuxue <= 100)
                        && (yingyu > 0 && yingyu <= 100)) {
                    System.out.println("你的姓名是:" + student.getName() + "\t" + "学号是:"
                            + student.getId());
                    System.out.println("你的三科成绩是:");
                    System.out.println("语文:" + yuwen +"分"+ "\t" + "数学:" + shuxue +"分"+ "\t"
                            + "英语:" + yingyu+"分");
                    System.out.println("你的总成绩是:"
                            + student.score(yuwen, shuxue, yingyu)+"分");
                    System.out.println("你的平均成绩是:"
                            + student.average(yuwen, shuxue, yingyu)+"分");
                    student.goodstudent(yuwen, shuxue, yingyu);
                    break;
                }
            }
        }
    }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 易语言把MYSQL数据库中的数据添加至组合框
  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况