Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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");
        s.addLesson(A);
        s.addLesson(B);
        s.addLesson(C);
        s.addLesson(D);
       System.out.println("Nazli's GPA is" +" "+ s.getTotalcredit());
    }

}



Java
package javaapplication19;

/**
 *
 * @author User
 */
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);
    }

}



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 (listLesson[i].getNote() > 60) {
                t1 = listLesson[i].getNote() * listLesson[i].getCredit();
                total += t1;
            }

        }
        return total;
    }

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


What I have tried:

i can't find what problem is,why do i get zero for answer?
Posted
Updated 25-Oct-16 4:19am
Comments
[no name] 25-Oct-16 9:20am    
Learning to use the debugger is a valuable skill.
Member 12702056 25-Oct-16 9:24am    
i have tried,but i can't learn it,may be for understanding of it i must know more things about programming.
[no name] 25-Oct-16 9:29am    
If you can't learn to use the debugger then you might as well stop programming. You MUST be able to use the debugger to step through your code and if you are unable to learn that skill then you are going to be asking other people to do your job for you all the time.
Suvendu Shekhar Giri 25-Oct-16 9:42am    
Only share the relevant portion of your code not the complete program.
You have to findout the problematic peice of code. We'll not be able to go through huge lines of code to find out your problem.
Member 12702056 25-Oct-16 9:45am    
ok,thank you.but i think i have problem with main function.Although i setted values ,they were considered like 0.

1 solution

I did not checked all the code but you are not adding the passed lesson:
Java
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++;
    }
    // This is missing in your code:
    listLesson[number] = l;
    number++;
}
 
Share this answer
 
Comments
Member 12702056 25-Oct-16 10:59am    
Thanks a lot,almost this was only problem in my program,thank you really :)) Finally it is working :)

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