Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

you are required to write an object oriented program that interactively reads 6

ID: 3937962 • Letter: Y

Question

you are required to write an object oriented program that interactively reads 6 students' records into one dimensional array and calculate their average GPA. you are required to write an object oriented program that interactively reads 6 students' records into one dimensional array and calculate their average GPA. you are required to write an object oriented program that interactively reads 6 students' records into one dimensional array and calculate their average GPA. you are required to write an object oriented program that interactively reads 6 students' records into one dimensional array and calculate their average GPA.

Explanation / Answer


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)