you are required to write an object oriented program that in
Solution
import java.util.Scanner;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
public class Records {
private double[] records;
public Records()
{
records = new double[6];
}
public void readStudentRecords()
{
Scanner input = new Scanner(System.in);
for(int i=0;i<6;i++)
{
System.out.println(\"Enter the record for Student \"+(i+1)+\" : \");
records[i] = input.nextDouble();
}
}
public double calculateAverage()
{
double sum = 0;
for(int i=0;i<records.length;i++)
sum = sum+records[i];
return sum/6.0;
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
public class RecordsTester {
public static void main(String[] args)
{
Records r = new Records();
r.readStudentRecords();
System.out.println(\"Student average is : \"+r.calculateAverage());
}
}
OUTPUT:
run:
Enter the record for Student 1 :
90
Enter the record for Student 2 :
80
Enter the record for Student 3 :
70
Enter the record for Student 4 :
87
Enter the record for Student 5 :
98
Enter the record for Student 6 :
100
Student average is : 87.5
BUILD SUCCESSFUL (total time: 14 seconds)

