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

I\'ve been out of class for a few months now due to a very nasty neck infection,

ID: 3810070 • Letter: I

Question

I've been out of class for a few months now due to a very nasty neck infection, and my professor has slammed me with a few assignments, I've managed to complete 5 out of 6 assignments but I cannot figure out how to complete the last assignment. Here are all of the resources she has provided.

Description

LAB06, Student Test Grades: An Array of Student Class objects                                   Points: 25

OBJECTIVE

To demonstrate creating an array of Student objects

To demonstrate how to subscript an array of objects

To demonstrate using a file look-up

REQUIRED

A report of your work, in a flat pocket folder, in the following order:

1.   Grade form                                                            Lab06GradeForm.doc

2.   This program description                                      Lab06Description.doc

3.   The source listing of the Student class                 Student.java

4.   Problem Analysis                                                  Lab06ProblemAnalysis.doc

5.   The listing of the source program                         Lab06.java

6.   Listing of the input file                                         Lab06StudentFile.txt

7.   Listing of the student name file                            Lab06Names.txt

8.   Listing of the expected results (already created) Lab06ExpectedResults.xlsx

9.   Listing of the output file                                       Lab06Report.txt

SPECIFICATIONS

Start with Lab05 and rename it as Lab06

Create an array of Student class objects

1.   Instead of creating one instance of the Student class, create an array of Student class objects. Create the array as you would for any data type, but use Student objects, 16 elements

      EXAMPLE:          Student [ ] arrayStudent = new Student [16];

2.   Within the loop, input data from the data file into variables

3.   Create a single instance of the Student class, using the constructor

4.   Place the single instance of the Student class into the array of Student objects

      This completes loading the array with Student objects

Retrieve data from the array of objects (this is to prepare for Labs 07 and 08)

5.   Use a for/loop to go through the array of objects and print the report

      Within the loop, create a single instance of the Student class and move the object out of the array into the single instance

6.   Use the class method to calculate the total, adjusted total and average

7.   Do the following in the application program:

      For each student, look up their name from the student name file, using the student id.

      Do a sequential search from the file (not an array). Use a value returning method.

      The method will open and close the file for each student look-up.

      The method header needs    throws FileNotFoundException

      Declare the student name file in the method

      Read the student id and student name, then compare student id to the search id

      Once the name is found (or “name not found”), close the file and return the name

8.   Print the report (almost exactly as in Lab05 except add the student name)

PROGRAMMING STYLE

I find it clearer to use single variables instead of subscripted variables, whenever possible.

When reading the input student file, first place data into a variable

Then create a single object.

Then place the object into the array of objects.

When retrieving data from the array of objects, return each object into a single object

Methods: should have ONE exit point.

For a value-returning method, this means one return statement

INPUT

File:           Student file                       Lab06StudentFile.txt

Record:     Student record

Field                            Data Type

Student id#                 4 numbers (ex. 1234)

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

INPUT

File:           Student name file              Lab06Names.txt

Record:     Student name record

Field                            Data Type

Student id#                 4 numbers (ex. 1234)

Student name              String

OUTPUT

File:           Grade Report file              Lab06Report.txt

Record:    

Student Grade Report

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

xxxx   xxxxxxxxxxxxxxx xxx xxx xxx xxx   xxx xxx xxx xxx xxx xxx          xxxx           xxxx           xxx

xxxx   xxxxxxxxxxxxxxx xxx xxx xxx xxx   xxx xxx xxx xxx xxx xxx          xxxx           xxxx           xxx

xxxx   xxxxxxxxxxxxxxx xxx xxx xxx xxx   xxx xxx xxx xxx xxx xxx          xxxx           xxxx           xxx

Total students = xx

Lab06Names.txt

1217 Carson, Joseph
1221 Korb, Barbara
1222 Schafer, Anne
1223 Kramer, Susan
1224 Smith, Lindy
1225 Caruso, Anthony
1226 Sokalski, Mark
1227 Nickerson, Philip
1228 Wydner, Peter
1256 Anderson, Beth
1277 Meyers, Henry
1343 Vickers, Jerry
1555 Collins, Richard
1602 Zimmer, Nancy
1856 Stanson, Luke
1976 Richman, Julie
1987 Lydon, Arthur
1989 Kelley, Nico
1991 Graham, Gary
1993 Parsons, Michael

Lab06StudentFile.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

Here is a PasteBin link to my Lab05, which works pretty dang well.

Lab05StudentClass.java -> https://pastebin.com/4cSsqJUe

Student.java -> https://pastebin.com/Me729ndW

Explanation / Answer

Student.java

public class Student
{

   private int inStudentId;
   private int [] inStudentGrades = new int[10];
//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 < inStudentGrades.length; c++)
         this.inStudentGrades[c] = inStudentGrades[c];
   }//end method


   public void setStudentId(int inStudentId)
   {
      this.inStudentId = inStudentId;
   }
   public int[] getStudentGradeArray() {
        return inStudentGrades ;
    }
    public int getStudentID() {
        return inStudentId ;
    }
   public double getTotal()
   {
      // Declarations
      double total = 0;
   
      for (int i = 0; i < inStudentGrades.length; i++)
      {
         total += inStudentGrades[i];
      } // End of For Loop
   
      return total;
   } // End of getTotal Method

   public double getAdjustedTotal()
   {
      // Declarations
      int lowestScore = getLowestScore();
      int highestScore = getHighestScore();
      double total = getTotal();
   
      total = total + highestScore;
   
      return total;
   } // End of getAdjustedTotal Method

   public double getAdjustedAverage()
   {
      // Declarations
      double total = 0;
      total = getAdjustedTotal();
   
      return (total / inStudentGrades.length);
   } // End of getAdjustedTotal Method


   public int getHighestScore()
   {
      // Declarations
      int highestScore = inStudentGrades[0];
   
      for (int i = 1; i < inStudentGrades.length; i++)
      {
         if (inStudentGrades[i] > highestScore)
         {
            highestScore = inStudentGrades[i];
         }
      } // End of For Loop
   
      return highestScore;
   } // End of getHighestScore Method

   public int getLowestScore()
   {
      // Declarations
      int lowestScore = inStudentGrades[0];
   
      for (int i = 1; i < inStudentGrades.length; i++)
      {
         if (inStudentGrades[i] < lowestScore)
         {
            lowestScore = inStudentGrades[i];
         }
      } // End of For Loop
   
      return lowestScore;
   } // End of getLowestScore Method

} // End of Student Class

Lab06StudentClass.java

// Imports
import java.util.*;
import java.io.*;

public class Lab06StudentClass
{
   public static void main(String [] args) throws FileNotFoundException,IOException
   {

      // Declarations
      Student [ ] arrayStudent = new Student [16]; // To hold the data from Lab05StudentFile.txt
      int grades[] = new int [10];      // To hold the student grades
      int id;
      int g[] = new int[16];
      float total;
      float adTotal;
      float adAvg;
   
      // Create a new file reader
      Scanner fileIn = new Scanner(new FileReader("Lab06StudentFile.txt"));
   
      // Create a new print writer
     PrintWriter fileOut = new PrintWriter("Lab05Report.txt");
   
   
      // While Loop to read and process data from Lab05StudentFile.txt
      while (fileIn.hasNext())
      {
         for(int i = 0; i < 16; i++)
         {
            Student student = new Student();
            int sid = Integer.valueOf(fileIn.nextInt());
            student.setStudentId(sid);   // Store data from Lab05StudentFile.txt in studentID
            for(int j = 0; j < 10; j++)
            {
                grades[j] = fileIn.nextInt();    // Read the grades from input file
            }
            student.setStudentGradeArray(grades);   // Store array of grades in student object
            arrayStudent[i] = student;

         }
      }
      // writing to report file -- starts
      File i = new File("Lab05Report.txt");//name of txt file
      Writer output = new BufferedWriter(new FileWriter(i));
  
      output.write("Student Grade Report");
      output.write(System.getProperty("line.separator"));
      output.write("Student # |-------------------------------Test Scores-------------------------------|       Total Adj. Total     Average");
      output.write(System.getProperty("line.separator"));
    
      for (Student s: arrayStudent){
           id = s.getStudentID();
           g = s.getStudentGradeArray();
           total = s.getTotal();
           adTotal = s.getAdjustedTotal();
            adAvg = s.getAdjustedAverage();
          
           output.write(id +" ");
             output.write(g +" ");
             output.write(total.intValue() +" ");
             output.write(adTotal.intValue() +" ");
             output.write(adAvg.intValue() +" ");
            output.write(System.getProperty("line.separator"));
        
      }
     // writing to report file -- ends
   } // End of Main Method

} // End of Public Class

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