Paste: a

Author: a
Mode: java
Date: Sat, 16 Jan 2010 14:22:37
Plain Text |
import java.util.*;

class Lesson {
    String n;
    public int w;
    public int g;

    public Lesson(String un, int uw, int ug) {
        n = un;
        w = uw;
        g = ug;
    }
}

class Lessons {
    ArrayList<Lesson> lessons = new ArrayList<Lesson>();
    
    public void add(String n, int w, int g) {
        Lesson lesson = new Lesson(n, w , g);
        lessons.add(lesson);
    }
    
    public float getAverage() {
        float sum = 0;
        float w = 0;
        for(Lesson l: lessons) {
            sum += l.g*l.w;
            w += l.w;
        }
        return (sum/w);
    }
}

class acal {
    public static void main(String[] args) {
        acal demo = new acal();
        
        
        Lessons l = new Lessons();
        l.add("riazi", 4, 12);
        l.add("adabi", 3, 15);
        l.add("zaban", 2, 16);
        l.add("tarbi", 1, 17);
        l.add("maref", 3, 13);
        l.add("osool", 4, 16);
        System.out.println(l.getAverage());
    }
}

New Annotation

Summary:
Author:
Mode:
Body: