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条)

报告相同问题?

悬赏问题

  • ¥60 用r语言进行数据分析
  • ¥20 关于游戏c++语言代码问题
  • ¥15 如何制作永久二维码,最好是微信也可以扫开的。(相关搜索:管理系统)
  • ¥15 delphi indy cookie 有效期
  • ¥15 labelme打不开怎么办
  • ¥35 按照图片上的两个任务要求,用keil5写出运行代码,并在proteus上仿真成功,🙏
  • ¥15 免费的电脑视频剪辑类软件如何盈利
  • ¥30 MPI读入tif文件并将文件路径分配给各进程时遇到问题
  • ¥15 pycharm中导入模块出错
  • ¥20 Ros2 moveit2 Windows环境配置,有偿,价格可商议。