instructions Two java files have been added to this project
instructions...
Two java files have been added to this project: StudentCreator.java and Student.java. Use the StudentCreator project located in your Data_Files to get started. The Student class should encapsulate the concept of a student, assuming that a student has the following attributes: a name and age. Include a constructor and setter and getter methods for name, age, and type of student. Add the code to the Student class that already exists. Use the StudentCreator class to test all the methods in your class. Do NOT make changes to the StudentCreator class.
? Include the proper instance variables (name, age, and type). Initialize the name variable to null, the age variable to 0, and the type variable to null. These variables should be private. The type variable will be used to store the schooling level of the student based on age.
(3 points)
? Include a constructor to set the name and age of the student when the object is created. The constructor should take in two parameters (newName and newAge) and should call setter methods for name and age. (2 points)
? Create a setName method that sets the value of the student’s name. (1 point)
? Create a getName method that returns the name of the student. (1 point)
? Create a setAge method. (1 point)
o If the age is greater than 0 (1 point), this method should:
? Set the age (1 point)
? Call the setType method (1 point)
? Create a getAge method that returns the age of the student. (1 point)
? Create a setType method that sets the type of the student based on age. This type will be the level of schooling of the student. It is just an approximation based on age. (7 points)
o Preschool (age 0 – 4)
o Kindergarten (age 5)
o Elementary School (age 6-10)
o Middle School (age 11-13)
o High School (age 14-17)
o College (age 18 & up)
? Create a getType method that returns the type of the student.
When I run the program I get
Name: Bob
Age: 17
Type of Student: null
Name: Jan
Age: 13
Type of Student: null
Name: Bob
Age: 18
The program should show...
Name: Bob
Age: 17
Type of Student: High School
Name: Jan
Age: 13
Type of Student: Middle School
Name: Bob
Age: 18
Type of Student: College
Solution
StudentCreator.java:
public class StudentCreator{
public static void main(String arg[]){
Student student1 = new Student(\"Bob\",17);
Student student2 = new Student(\"Jan\",13);
System.out.println(\"Name: \"+student1.getName());
System.out.println(\"Age: \"+student1.getAge());
System.out.println(\"Type Of Student: \"+student1.getType());
System.out.println(\"Name: \"+student2.getName());
System.out.println(\"Age: \"+student2.getAge());
System.out.println(\"Type Of Student: \"+student2.getType());
student1.setAge(18);
System.out.println(\"Name: \"+student1.getName());
System.out.println(\"Age: \"+student1.getAge());
System.out.println(\"Type Of Student: \"+student1.getType());
}
}
Student.java:
public class Student {
public String name;
public int Age;
public String Type;
public Student(String name, int Age) {
this.name = name;
this.Age = Age;
this.Type=getType(Age);
}
public static String getType(int studentAge){
if (studentAge >= 11 && studentAge<=13) {
return \"Middle School\";
} else if (studentAge>=14 && studentAge<=17){
return \"High School\";
} else if(studentAge >= 18){
return \"College\";
}else{
return \"Invalid\";
}
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return Age;
}
public void setAge(int Age) {
if(Age >0){
this.Age = Age;
this.Type=getType(Age);
}else{
System.out.println(\"Age cannot be lee than Zero\");
}
}
public String getType() {
return Type;
}
public void setType(String Type) {
this.Type = Type;
}
}
Output:
Name: Bob
Age: 17
Type Of Student: High School
Name: Jan
Age: 13
Type Of Student: Middle School
Name: Bob
Age: 18
Type Of Student: College
Hope this will hleps you.


