Student Class
A school district decided to write a program to help keep track of various parts of the school.
It has been decided to store relevant information about Students in a Student class. Each Student will have an array of Strings to store the names of his or her teachers.
private instance variables
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
public class Student { public String name; private int age private double gpa; private //insert array declaration; public Student(){} // default constructor boolean setTeacher (String name, int index){ //missing code } public void setGpa(double to){ //missing code } public double getGPA() // returns gpa } |
Part 1
* Construct the Java statement to declare the array called
teachersNames to store the String names of the student’s teachers
Part 2
- write a default constructor
- construct a method called
addTeacher( String name) that adds
String name to the
teachersNames array
- to do this let’s create a private method private String[] addStr( String[] input, String val) that adds value to the end of the array and returns it. [redact]Solution[/redact]
- construct hasTeacher(String name) that returns true if name is in the teachersName array
- construct a method removeTeacher(String name) that removes the String name from the teachersNames array.
- construct a method the line of code needed in the setGpa(double to) method of the Student Class.
- construct a method boolean setTeacher (String name, int index) . This method should return true if index is valid in the array and false if index >= teachersName.length