Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Shavit Borisov
- // CW
- import java.util.Scanner;
- public class ClassGrades {
- public static void main(String[] args)
- {
- Scanner in = new Scanner (System.in);
- Grades obj = new Grades();
- System.out.print("How many students are there in your class? ");
- int classSize = in.nextInt();
- obj.classSize(classSize);
- for(int i = 0; i < classSize; i++)
- {
- System.out.printf("Enter the math grade for student number %d: ", i + 1);
- int currentMath = in.nextInt();
- System.out.printf("Enter the hebrew grade for student number %d: ", i + 1);
- int currentHebrew = in.nextInt();
- obj.setGrade(i, currentMath, currentHebrew);
- }
- System.out.printf("The average grade for math is %.2f\n", obj.mathAvg());
- System.out.printf("The average grade for hebrew is %.2f\n", obj.hebrewAvg());
- in.close();
- }
- }
- // Next class
- public class Grades
- {
- private int size = 20; // Default value
- public void classSize(int size)
- {
- this.size = size;
- }
- private int[] math = new int[size];
- private int[] hebrew = new int[size];
- public void setGrade (int id, int math, int hebrew)
- {
- this.math[id] = math;
- this.hebrew[id] = hebrew;
- }
- public double mathAvg()
- {
- double sum = 0;
- for(int i = 0; i < size; i++)
- {
- sum += math[i];
- }
- sum /= size;
- return sum;
- }
- public double hebrewAvg()
- {
- double sum = 0;
- for(int i = 0; i < size; i++)
- {
- sum += hebrew[i];
- }
- sum /= size;
- return sum;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement