Click here to Skip to main content
14,163,348 members

Please, help me.i can't find what is error in my program in NETBEANS IDE

Member 12702056 asked:

Open original thread
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)



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.
Tags: Java, JavaSE6, netbeans, JavaSE

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).



Advertise | Privacy | Cookies | Terms of Service
Web01 | 2.8.190518.1 | Last Updated 26 Mar 2009
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100