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

Java Write a class for Student grade data and write a program to create an objec

ID: 3862031 • Letter: J

Question

Java

Write a class for Student grade data

and write a program to create an object from this class and use it to produce a report

Write a class for Student grade data:

1.   The class will have the following fields:

      Student id

      An array of ten test grades

2.   Create void “set” methods to store values in Student id and the array

3.   Create a value-returning “get” method to retrieve values from the fields, one for each field

4.   Create a constructor with arguments for Student id and the array (use set methods)

5.   Create a noArg constructor (use set methods, consider what the default values should be)

6.   Create a method to calculate the total of test grades

7.   Create a method to calculate the adjusted total, dropping the lowest test score and replace it with the highest test score (highest test counts twice, drop lowest test)                                                        see Lab05Logic

8.   Create a method to calculate the average of the ten test grades based upon the adjusted total and round to the nearest integer

Create Lab05

9.   Input data from the Lab05StudentFile.txt

10. Create an object from the Student class and use the constructor to place values into the object

11. Use the class method to calculate the total

12. Use the class method to calculate the adjusted total

13. Use the class method to calculate the average

14. Use data from the object and write the report to an output file

15. Accumulate and print the number of students

.    

INPUT

File:          Student file                        Lab05StudentFile.txt

Record:     Student record

Field                           Data Type

Student id#                  4 numbers (ex. 1234)

Ten test scores            integers (valid numbers are 0 -100)

OUTPUT

File:          Grade Report file              Lab05Report.txt

Record:    

Student Grade Report

ID#           /-----------------------TEST Scores--------------------------/    Total Adj Total   Avg        

xxxx           xxx    xxx    xxx    xxx    xxx    xxx    xxx    xxx    xxx    xxx       xxxx        xxxx        xxx

xxxx           xxx    xxx    xxx    xxx    xxx    xxx    xxx    xxx    xxx    xxx       xxxx        xxxx        xxx

xxxx           xxx    xxx    xxx    xxx    xxx    xxx    xxx    xxx    xxx    xxx       xxxx        xxxx        xxx

Total students = xx

input file

1221 100 100 100 100 100 100 100 100 100 100
1222 87 87 87 87 87 87 87 87 87 87
1223 80 80 80 80 80 80 80 80 80 80
1224 77 77 77 77 77 77 77 77 77 77
1225 70 70 70 70 70 70 70 70 70 70
1226 67 67 67 67 67 67 67 67 67 67
1227 60 60 60 60 60 60 60 60 60 60
1228 57 57 57 57 57 57 57 57 57 57
1343 90 85 80 65 75 95 85 75 80 94
1555 70 70 70 60 65 90 85 80 80 80
1856 60 0 45 68 89 67 60 50 75 80
1967 90 85 87 88 70 90 92 87 88 67
1987 68 68 68 68 68 68 68 68 68 100
1989 59 59 59 59 59 59 59 59 59 75
1991 100 90 75 85 90 88 79 88 91 90
1993 91 90 75 85 90 88 79 88 91 90

stuent class

//class constructor
   public Student(int inStudentId, int [ ] inStudentGrades)
   {//begin method
   setStudentId (inStudentId);
   setStudentGradeArray(inStudentGrades);
   }//end method


//class default constructor    public Student()
   {//begin method
   int tempArray [ ] = {0,0,0,0,0,0,0,0,0,0};
   setStudentId (0);
   setStudentGradeArray(tempArray);
   }//end method


   public void setStudentGradeArray (int [ ] inStudentGrades)
   {//begin method
   for (int c = 0; c<10; c++)
      studentGrades [c] = inStudentGrades [c];
   }//end method

Explanation / Answer

Input File: (Lab05StudentFile.txt)

1221 100 100 100 100 100 100 100 100 100 100
1222 87 87 87 87 87 87 87 87 87 87
1223 80 80 80 80 80 80 80 80 80 80
1224 77 77 77 77 77 77 77 77 77 77
1225 70 70 70 70 70 70 70 70 70 70
1226 67 67 67 67 67 67 67 67 67 67
1227 60 60 60 60 60 60 60 60 60 60
1228 57 57 57 57 57 57 57 57 57 57
1343 90 85 80 65 75 95 85 75 80 94
1555 70 70 70 60 65 90 85 80 80 80
1856 60 0 45 68 89 67 60 50 75 80
1967 90 85 87 88 70 90 92 87 88 67
1987 68 68 68 68 68 68 68 68 68 100
1989 59 59 59 59 59 59 59 59 59 75
1991 100 90 75 85 90 88 79 88 91 90
1993 91 90 75 85 90 88 79 88 91 90

Program:

//Student.java

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;

public class Student {
// Properties
String id;
Integer grades[] = new Integer[10];
  
//Constructor
public Student(String id,Integer grades[]){
this.id = id;
this.grades = grades;
}
  
//Calculating Grades
public Integer calculateGrades(){
int sum=0;
for(int k=0;k<grades.length;k++){
sum = sum +grades[k];
}
  
return sum;
}
  
// Calculating adjusted grades
public StringBuffer adjGrades(){
//Finding Max Values
int maxValue = grades[0];
for(int i=1;i < grades.length;i++){
if(grades[i] > maxValue){
maxValue = grades[i];
}
}
  
// Finding Min Value
int minValue = grades[0];
for(int i=1;i<grades.length;i++){
if(grades[i] < minValue){
minValue = grades[i];
}
}
  
//Swapping LowestGrades with Highest Grades by dropping
for(int i=0;i<grades.length;i++){
if(grades[i]==minValue){
grades[i]=maxValue;
}
}
  
//Finding Adjusted total for changed grades
int ajTotal=0;
for(int k=0;k<grades.length;k++){
ajTotal = ajTotal +grades[k];
}
// Passing ID, Grades array and adjusted total
return this.averageGrades(id,grades,ajTotal);
}
  
// Finding average total and returns StringBuffer
public StringBuffer averageGrades(String sId, Integer grades[],Integer ajTotal) {
//Finding average total
int avgGrades = ajTotal/grades.length;
StringBuffer sb = new StringBuffer();
sb.append(sId+" ");
//Appending ID, Grades, Adjusted Total and Avg Total to StringBuffer
for(int i=0;i<grades.length;i++){
sb.append(grades[i]+" ");
}
sb.append(ajTotal+" ");
sb.append(avgGrades);
return sb;
}
  
//Setters and Getters
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public Integer[] getGrades() {
return grades;
}
public void setGrades(Integer[] grades) {
this.grades = grades;
}
  
  
//main Method
public static void main(String args[]){
try{
//FileReading
FileReader fr = new FileReader("D:\Lab05StudentFile.txt");
BufferedReader br = new BufferedReader(fr);
//File Writing
FileWriter fw = new FileWriter("D:\Lab05Report.txt");;
BufferedWriter bw = new BufferedWriter(fw);;
bw.write("Student Grade Report");
bw.newLine();
bw.write("ID********TEST Grades******Adjusted Average******Total Average");
bw.newLine();
Integer marks[];
String line;
Student st;
int count=0;
//Reading line by line from input file
while((line=br.readLine())!=null){
//Splitting line into string array
String lin[] = line.split(" ");
marks = new Integer[10];
// Adding to array using loop
for(int i=0;i<lin.length;i++){
if(i==lin.length-1)
break;
marks[i] = new Integer(lin[i+1]);
}
//Creating student object
st = new Student(lin[0], marks);
//st.calculateGrades();
//Retrieving all data from method adjGrades
StringBuffer sb = st.adjGrades();
bw.write(sb.toString());
bw.newLine();
count++; // Total Students
}
bw.write("Total Students:-"+count);
System.out.println("Grade Report Generated ...");
bw.close();fw.close();br.close();fr.close();
}catch(Exception e){
e.printStackTrace();   
}
}
  
}

Output File (Lab05Report.txt):

Student Grade Report
ID********TEST Grades******Adjusted Average******Total Average
1221 100 100 100 100 100 100 100 100 100 100 1000 100
1222 87 87 87 87 87 87 87 87 87 87 870 87
1223 80 80 80 80 80 80 80 80 80 80 800 80
1224 77 77 77 77 77 77 77 77 77 77 770 77
1225 70 70 70 70 70 70 70 70 70 70 700 70
1226 67 67 67 67 67 67 67 67 67 67 670 67
1227 60 60 60 60 60 60 60 60 60 60 600 60
1228 57 57 57 57 57 57 57 57 57 57 570 57
1343 90 85 80 95 75 95 85 75 80 94 854 85
1555 70 70 70 90 65 90 85 80 80 80 780 78
1856 60 89 45 68 89 67 60 50 75 80 683 68
1967 90 85 87 88 70 90 92 87 88 92 869 86
1987 100 100 100 100 100 100 100 100 100 100 1000 100
1989 75 75 75 75 75 75 75 75 75 75 750 75
1991 100 90 100 85 90 88 79 88 91 90 901 90
1993 91 90 91 85 90 88 79 88 91 90 883 88
Total Students:-16

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote