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

Project must have a class named Student and these additional requirements: -Must

ID: 3570285 • Letter: P

Question

Project must have a class named Student and these additional requirements:

-Must have at least 2 constructors, with one being a no-arg constructor

-Must have studentID, firstName, lastName, gradeLevel, and gender fields

-Every class field has an accessor and mutator method

-Must have a displayStudentInfo method

Project must have a class named Gradebook and these additional requirements:

-Must have at least 2 constructors, with one being a no-arg constructor

-Must allow user to determine how many students to store in memory

-Must allow user to determine how many scores to store in memory

-Every class field has an accessor and mutator method

-Must have displayGradebook, displayGradebookReport, calcAverage, determineGrade methods

-All scores are displayed to one decimal place with % sign -Grades are assigned as follows: >=90-100 A, >=80-90 B, >=70-80 C, >=60-70 D, >=0-60 F Project must have a class named FinalProject that contains a main method.

Additionally, -Must have a studentCountValidation method (only return 1 10)

-Must have a scoreCountValidation method (only return 1 20)

This what I have so far:

public class Student
{
   // Fields
   private int studentID;
   private String firstName;
   private String lastName;
   private char gender;
   private int gradeLevel;

   // Methods
   // Constructors
   // No-arg constructor
   public Student()
   {
       studentID = 0;
       firstName = "John";
   lastName = "Doe";
   gender = 'M';
   gradeLevel = 13;
   }

   // Arg constructor
   public Student(int sID, String first, String last, char gen, int gLev)
   {
       studentID = sID;
       firstName = first;
   lastName = last;
   gradeLevel = gLev;
       gender = gen;
   }

   // Methods
   //Setters
   public void setStudentID(int sID)
   {
       studentID = sID;
   }// End setStudentID

   public void setFirstName(String first)
   {
       firstName = first;
   }// End setFirstName

   public void setLastName(String last)
   {
       lastName = last;
   }// End setLastName

   public void setGender(char gen)
   {
       gender = gen;
   }// End setGender

   public void setGradeLevel(int gLev)
   {
       gradeLevel = gLev;
   }// End setGradeLevel

   //Getters
   public int getStudentID(int sID)
   {
       return studentID = sID;
   }// End getStudentID

   public String getFirstName(String first)
   {
       return firstName = first;
   }// End getFirstName

   public String getLastName(String last)
   {
       return lastName = last;
   }// End getLastName

   public char getGender(char gen)
   {
       return gender = gen;
   }// End getGender

   public int getGradeLevel(int gLev)
   {
       return gradeLevel = gLev;
   }// End getGradeLevel

   public void displayStudentInfo()
   {
   System.out.print("StudentID | Name | Gender | Grade ");
       System.out.println(" --------------------------------------------");
       System.out.printf("%03d | %s %s | %c | %d", studentID, firstName, lastName, gender, gradeLevel);
   }// End displayStudentInfo

}// End Student Class

Explanation / Answer

Complete Program:

File: Student.java

// Student class implementation
public class Student
{
   // fields
   private int studentID;
   private String firstName;
   private String lastName;
   private char gender;
   private int gradeLevel;

   // no-args constructor implementation
   public Student()
   {
       studentID = 0;
       firstName = "John";
       lastName = "Doe";
       gender = 'M';
       gradeLevel = 13;
   } // end of no-args constructor

   // args constructor implementation
   public Student(int sID, String first, String last, char gen, int gLev)
   {
       studentID = sID;
       firstName = first;
       lastName = last;
       gradeLevel = gLev;
       gender = gen;
   } // end of args constructor

   public void setStudentID(int sID)
   {
       studentID = sID;
   }

   public void setFirstName(String first)
   {
       firstName = first;
   }

   public void setLastName(String last)
   {
       lastName = last;
   }

   public void setGender(char gen)
   {
       gender = gen;
   }

   public void setGradeLevel(int gLev)
   {
       gradeLevel = gLev;
   }

   public int getStudentID()
   {
       return studentID;
   }

   public String getFirstName()
   {
       return firstName;
   }

   public String getLastName()
   {
       return lastName;
   }

   public char getGender()
   {
       return gender;
   }

   public int getGradeLevel()
   {
       return gradeLevel;
   }

   public void displayStudentInfo()
   {
       System.out.printf("%-9s | %-15s | %-6s | %-6s ", "StudentID", "Name", "Gender", "Grade");
       System.out.println("---------------------------------------------");
       System.out.printf("%03d%6s | %-15s | %-6c | %-6d ", studentID, "", (firstName + " " + lastName), gender, gradeLevel);
   }
} // end of Student class


File: Gradebook.java

// Gradebook class implementation
import java.util.Scanner;
public class Gradebook
{
   // fields
   private Student[] students;
   private double[][] scores;
  
   // no-args constructor implementation
   public Gradebook()
   {
       students = new Student[1];      
       scores = new double[1][3];
      
       students[0] = new Student();
   } // end of no-args constructor
  
   // args constructor implementation
   public Gradebook(int numberOfStudents, int numberOfScores)
   {
       students = new Student[numberOfStudents];
       scores = new double[numberOfStudents][numberOfScores];
      
       for(int i = 0; i < students.length; i++)
           students[i] = new Student();
   } // end of args constructor
      
   public void readStudentRecords(Scanner input)
   {      
       for(int i = 0; i < students.length; i++)
       {          
           System.out.print(" Enter StudentID: ");
           int sID = input.nextInt();
          
           System.out.print("Enter first name: ");
           String first = input.next();
          
           System.out.print("Enter last name: ");
           String last = input.next();
          
           System.out.print("Enter gender: ");
           char gen = input.next().charAt(0);
          
           System.out.print("Enter grade level: ");
           int gLev = input.nextInt();  
          
           students[i] = new Student(sID, first, last, gen, gLev);
       }
   }
  
   public void readStudentScores(Scanner input)
   {
       for(int i = 0; i < students.length; i++)
       {
           for(int j = 0; j < scores[0].length; j++)
           {
               System.out.print("Enter student " + (i + 1) + ", Score " + (j + 1) + ": ");
               scores[i][j] = input.nextDouble();
           }
           System.out.println();
       }
   }
  
   public double calcAverage(int index)
   {
       double total = 0;
      
       for(int i = 0; i < scores[index].length; i++)
           total += scores[index][i];
      
       return total / scores[index].length;
   }
  
   public char determineGrade(int index)
   {
       double average = calcAverage(index);
      
       if(average >= 90)
           return 'A';
       else if(average >= 80)
           return 'B';
       else if(average >= 70)
           return 'C';
       else if(average >= 60)
           return 'D';
       else
           return 'F';
   }
  
   public void displayGradebook()
   {
       System.out.printf("%-9s |", "StudentID");
       for(int j = 1; j <= scores[0].length; j++)
           System.out.printf(" %-6s |", ("Proj " + j));
       System.out.printf(" %-6s | %-5s ", " Avg", "Grade");
      
       for(int k = 0; k < (scores[0].length + 3) * 9; k++)
           System.out.print("-");
       System.out.println();
      
       for(int i = 0; i < students.length; i++)
       {
           System.out.printf("%03d%6s |", students[i].getStudentID(), "");
           for(int j = 0; j < scores[0].length; j++)
               System.out.printf(" %5.1f%1s |", scores[i][j], "%");
           System.out.printf(" %5.1f%1s | %-6c ", calcAverage(i), "%", determineGrade(i));
       }
       System.out.println();
   }
  
   public void displayGradebookReport()
   {
       System.out.printf("%-15s%2s", "Student ", " |");
       for(int j = 1; j <= scores[0].length; j++)
           System.out.printf(" %-6s |", ("Proj " + j));
       System.out.printf(" %-6s | %-5s ", " Avg", "Grade");
       for(int k = 0; k < (scores[0].length + 3) * 10; k++)
           System.out.print("-");
       System.out.println();
       for(int i = 0; i < students.length; i++)
       {
           System.out.printf("%-15s |", (students[i].getFirstName() + " " + students[i].getLastName()));
           for(int j = 0; j < scores[0].length; j++)
               System.out.printf(" %5.1f%1s |", scores[i][j], "%");
           System.out.printf(" %5.1f%1s | %-6c ", calcAverage(i), "%", determineGrade(i));
       }
       System.out.println();
   }
  
   public void displayStudentRecords()
   {
       System.out.printf("%-9s | %-15s | %-6s | %-6s ", "StudentID", "Name", "Gender", "Grade");
       System.out.println("---------------------------------------------");
       for(int i = 0; i < students.length; i++)
           System.out.printf("%03d%6s | %-15s | %-6c | %-6d ", students[i].getStudentID(), "", (students[i].getFirstName() + " " + students[i].getLastName()), students[i].getGender(), students[i].getGradeLevel());
       System.out.println();
   }
} // end of Gradebook class

File: FinalProject.java

// FinalProject class implementation
import java.util.Scanner;
public class FinalProject
{
   private static Scanner input = new Scanner(System.in);

   public static void main(String[] args)
   {
       System.out.println(" Student Data and Gradebook Program ");
      
       Student s1 = new Student();
      
       System.out.println("New Student Data Record: ");
       s1.displayStudentInfo();
      
       Gradebook g1 = new Gradebook();
      
       System.out.println("New Student Gradebook: ");
       g1.displayGradebook();
      
       System.out.println("Initializing Student Gradebook. . . ");
      
       int numberOfStudents = studentCountValidation();
       int numberOfProjects = scoreCountValidation();
      
       Gradebook g2 = new Gradebook(numberOfStudents, numberOfProjects);
      
       System.out.println(" New Student Gradebook: ");
       g2.displayGradebook();
      
       System.out.println("Enter student records. . . ");
       g2.readStudentRecords(input);
      
       System.out.println(" Student Records: ");
       g2.displayStudentRecords();
      
       System.out.println("Enter student scores. . . ");
       g2.readStudentScores(input);;
      
       System.out.println("Student Gradebook: ");
       g2.displayGradebook();
      
       System.out.println("Gradebook Report: ");
       g2.displayGradebookReport();      
   }

   private static int studentCountValidation()
   {
       System.out.print("Enter number of students: ");
       int numberOfStudents = input.nextInt();
      
       while(numberOfStudents < 1 || numberOfStudents > 10)
       {
           System.out.println("Invalid entry! Please enter a value between 1 and 10.");
          
           System.out.print(" Enter number of students: ");
           numberOfStudents = input.nextInt();
       }
      
       return numberOfStudents;
   }

   private static int scoreCountValidation()
   {
       System.out.print(" Enter number of projects: ");
       int numberOfProjects = input.nextInt();
      
       while(numberOfProjects < 1 || numberOfProjects > 20)
       {
           System.out.println("Invalid entry! Please enter a value between 1 and 20.");
          
           System.out.print(" Enter number of projects: ");
           numberOfProjects = input.nextInt();
       }
      
       return numberOfProjects;
   }
} // end of FinalProject class