请帮助我。我无法在NETBEANS IDE中查找程序中的错误 [英] Please, help me.i can't find what is error in my program in NETBEANS IDE

查看:123
本文介绍了请帮助我。我无法在NETBEANS IDE中查找程序中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public class JavaApplication19 {

    public static void main(String[] args) {
        Lesson A = new Lesson();
        Lesson B = new Lesson();
        Lesson C = new Lesson();
        Lesson D = new Lesson("CMS 202", "Applied Linear Algebra", 3, 94);
        A.setCode("CMS 205");
        B.setCode("CMS 220");
        C.setCode("GERM 201");
        A.setName("Object Oriented Programming");
        B.setName("Web Programming 1");
        C.setName("German Language 1");
        A.setNote(99);
        B.setNote(97);
        C.setNote(95);
        A.setCredit(3);
        B.setCredit(3);
        C.setCredit(3);
        Student s = new Student("Nazli Elizade");
       System.out.println("Nazli's GPA is" + s.getGPA());
             System.out.println("Nazli's GPA is" +s.getTotalcredit());
    }

}







package javaapplication19;


public class Student {

    private String name;
    private Lesson listLesson[];
    private int size = 20;
    private int number = 0;

    public Student(String name) {
        this.name = name;
        listLesson = new Lesson[size];
    }

    public void addLesson(Lesson l) {
        if (number == size)
        {
            Lesson ListNew[] = new Lesson[size + 1];
            for (int i = 0; i < size; i++) {
                ListNew[i] = listLesson[i];
            }
            listLesson = ListNew;
            size++;
        }

    }

    public double getTotalcredit() {
        double t1;
        double total = 0;
        for (int i = 0; i < number; i++) {
            if (k.getNote() > 60) {
                t1 = k.getNote() * k.getCredit();
                total += t1;
            }

        }
        return total;
    }

    public double getGPA() {
        double GPA = 0.0;
        double t1;
        double total = 0.0;
        double totalcredit=1;
        for (int i = 0; i < number; i++) {
            if (k.getNote() > 60) {
                t1 = k.getNote() * k.getCredit();
                totalcredit += k.getCredit();
                total += t1;
            }
            GPA = total / (totalcredit-1);
            return GPA;
        }







public class Lesson {

    private String code;
    private String name;
    private double note;
    private int credit;

    public Lesson() {
        this.code = null;
        this.name = null;
        this.note = 0.0;
        this.credit = 0;
    }

    public Lesson(String c, String n, double note, int cre) {
        this.code = c;
        this.name = n;
        this.note = note;
        this.credit = cre;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getNote() {
        return note;
    }

    public void setNote(double note) {
        this.note = note;
    }

    public int getCredit() {
        return credit;
    }

    public void setCredit(int credit) {
        this.credit = credit;
    }

    public String toString() {
        return ("code=" + code + " " + "name=" + name + " " + "note=" + note + " " + "credit=" + credit);
    }

}





我尝试过:



这个程序没有任何错误,但是当我运行它时,会出现错误,它是这样的:



What I have tried:

There is no any error in this program,but when i run it ,error appears and it is like this:

Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - missing return statement
	at javaapplication19.Student.getGPA(Student.java:52)
	at javaapplication19.JavaApplication19.main(JavaApplication19.java:32)
C:\Users\User\AppData\Local\NetBeans\Cache\8.1\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 1 second)







当我点击wh时在这个错误点,我达到了获得GPA功能。但是,请帮助我,我的程序有什么问题?

i想通过这个程序获得学生的GPA。

我已经搜索过了,但是我无法解决它。




When i click what this error points,i am reached to getGPA function.but please,help me what is problem in my program?
i wan to get student's GPA with this program.
I have searched about it,but i can't solve it.

推荐答案

来吧!!!

你不能阅读错误信息和跟踪?

Come on!!!
Can't you read error messages and trace?
Quote:

线程main中的异常java.lang.RuntimeException:无法编译的源代码 - 缺失return语句

Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - missing return statement



这意味着你有一个不返回值的方法,但应该......所以无法编译...


It means you have a method somewhere that does not return a value, but should...So it can not be compiled...

引用:

at javaapplication19.Student.getGPA(Student.java:52)

at javaapplication19.Student.getGPA(Student.java:52)



这个告诉你错过了返回的地方...

现在看看getGPA ......


This one tells you where you missed the return...
Now looking into getGPA...

public double getGPA() {
  // ...
  for (int i = 0; i < number; i++) {
    // ...         
    return GPA;
  }
}



现在,谁告诉你它会进入for循环?


Now, who told you it will enter the for loop?


你能来吗?带回归GPA;声明在for循环旁边并尝试。
Can you bring return GPA; statement out side the for loop and try.


这篇关于请帮助我。我无法在NETBEANS IDE中查找程序中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆