I'm having a problem with constructor. I get an error an error "invalid method declaration; return type required" on line 75 ..here is line 75 TypeOfStudent(int minAge, int maxAge, String name) ..and I've posted my whole code below
import java.util.*;
public class Student
{
private String name;
private int age;
public Student(String newName, int newAge)
{
setName (newName);
setAge(newAge);
}
public void setName (String newName)
{
name = newName;
}
public String getName ()
{
return name;
}
public void setAge (int newAge)
{
if (newAge > 0)
age = newAge;
else
System.out.println ("Age cannot be zero or less.");
}
public int getAge ()
{
return age;
}
public String fullString ()
{
return ("\nName of Student:" + name+ "\nAge of Student:" +age+ "Years.");
}
public String TypeOfStudent()
{
for(TypeOfStudent t : TypeOfStudent.values())
{
if(age >= t.getMinAge() && age <= t.getMaxAge())
return t.getName();
}
}
public enum TypeOfStudent
{PRESCHOOL(0, 4), KINDERGARTEN(5, 5), ELEMENTARY_SCHOOL(6, 10), MIDDLE_SCHOOL(11, 13), HIGH_SCHOOL(14, 17), COLLEGE(18, 99)}
private final int minAge, maxAge;
private final String name;
TypeOfStudent(int minAge, int maxAge, String name)
{
this.minAge = minAge;
this.maxAge = maxAge;
this.name = name;
}
public int getMinAge()
{
return minAge;
}
public int getMaxAge()
{
return maxAge;
}
public String getName()
{
return name;
}
}
}
public class StudentClient
{
public static void main( String [] args )
{
Student student1 = new Student("Bob", 15);
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.typeOfStudent());
System.out.println("\n" + student2.fullString());
System.out.println("Type of Student: " + student2.typeOfStudent());
student1.setName("Ted");
student1.setAge(35);
System.out.println("\n" + student1.fullString());
System.out.println("Type of Student: " + student1.typeOfStudent());
} //ends main
}