Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
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());
    }

}


C#
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;
        }


C#
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:
C#
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.
Posted
Updated 25-Oct-16 2:25am
v4
Comments
[no name] 25-Oct-16 8:12am    
What is returned from that function when the for loop doesn't do anything? It's exactly what the error message is telling you. Why did you feel the need to post so much code that has nothing to do with your problem?

Come on!!!
Can't you read error messages and trace?
Quote:
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...
Quote:
at javaapplication19.Student.getGPA(Student.java:52)

This one tells you where you missed the return...
Now looking into getGPA...
Java
public double getGPA() {
  // ...
  for (int i = 0; i < number; i++) {
    // ...         
    return GPA;
  }
}

Now, who told you it will enter the for loop?
 
Share this answer
 
Can you bring return GPA; statement out side the for loop and try.
 
Share this answer
 
Comments
Member 12702056 25-Oct-16 8:27am    
thank you a lot,i tried,but now problem with "k" variable, i don't know how can i solve it?
Richard MacCutchan 25-Oct-16 8:55am    
Because there is no k variable initialised anywhere. You should go back to your study notes and look more closely at classes and object. It would also help you to use meaningful variable names rather than single letters.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900