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

Implement the following class in interface and implementation files. A separate

ID: 3782311 • Letter: I

Question

Implement the following class in interface and implementation files. A separate file (the main project file) shall have the main function that exercises this class. Create a class named Student that has three member variables: name - string that stores the name of the student numClasses - integer that tracks how many courses the student is currently enrolled in, this number must be between 1 and 100 ClassList - an array of strings of size 100 used to store the names of the classes that the student is enrolled in Write the appropriate constructor(s), mutator and accessor functions for the class along with the following: a function that inputs all values from the user. including the list of class names a function that outputs the name and list of all courses a function that resets the number of classes to 0 and the classList to an empty list

Explanation / Answer

// Student.java

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Student {
   public Student(String name, int numClasses) {
       this.name = name;
       this.numClasses = numClasses;
   }

   public Student() {}
   String name;
   int numClasses;
   List<String> classList = new ArrayList<String>(100);
  

   public void input()
   {
       Scanner sc = new Scanner(System.in);
       System.out.print("Enter your name: ");
       this.name = sc.nextLine();
      
       System.out.print("Enter number of classes: ");
       this.numClasses = sc.nextInt();
      
       sc.nextLine();
       for(int i = 0; i < this.numClasses; i++)
       {
           String className;
           System.out.print("Enter class(" + (i + 1) + ") name: ");
           className = sc.nextLine();
           this.classList.add(className);
       }
   }
  
   public void reset()
   {
       this.numClasses = 0;
       this.classList = null;
       this.classList = new ArrayList<>(100);
   }
  
  
   public void output()
   {
       System.out.println("Student name: "+ getName());
      
       List<String> classes = getClassList();
       for(String className : classes)
       {
           System.out.println("Class name is " + className);
       }
   }
   public String getName() {
       return name;
   }
   public void setName(String name) {
       this.name = name;
   }
   public int getNumClasses() {
       return numClasses;
   }
   public void setNumClasses(int numClasses) {
       this.numClasses = numClasses;
   }
   public List<String> getClassList() {
       return classList;
   }
   public void setClassList(List<String> classList) {
       this.classList = classList;
   }
  
  
}

// StduentTest.java to test code


public class StudentTest {
   public static void main(String[] args)
   {
       Student student = new Student();
      
       System.out.println("Starting student input method");
       student.input();
      
       System.out.println("Outputing student details");
       student.output();
      
       System.out.println("Reseting student detail");
       student.reset();
      
       System.out.println("Outputing student details after reset");
       student.output();
   }
}

/*

Sample run

Starting student input method
Enter your name: StudentA
Enter number of classes: 5
Enter class(1) name: CourseA
Enter class(2) name: CourseB
Enter class(3) name: CourseC
Enter class(4) name: CourseD
Enter class(5) name: CourseE
Outputing student details
Student name: StudentA
Class name is CourseA
Class name is CourseB
Class name is CourseC
Class name is CourseD
Class name is CourseE
Reseting student detail
Outputing student details after reset
Student name: StudentA

*/