Jess
June 23rd, 2013, 11:39 AM
StudentClient.java
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
} //ends program
Student.java
/* Jessica Chen
* Saturday 6/22/13
* Java 1.7.0_21 and NetBeans 7.3
* Determines type of student based on age
*/
public class Student
{
private String name;
private int age;
public Student(String newName, int newAge){
setName(newName);
setAge(newAge);
}
//Mutator method to set name
public void setName(String newName){
name = newName;
}
//Accessor method to get name
public String getName(){
return name;
}
//Mutator method to check validity of data and set age
public void setAge(int newAge) {
if (newAge > 0){
age = newAge;
} else {
System.out.println("Age cannot be negative.");
}
}
//Accessor method to get age
public int getAge() {
return age;
}
//method to determine school level
public String typeOfStudent (int age){
if (age >= 0 && age <= 4){
return "preschool";
}
else if (age == 5){
return "kindergarten";
}
else if (age >= 6 && age <= 10){
return "elementary school";
}
else if (age >= 11 && age <= 13){
return "middle school";
}
else if (age >=14 && age <= 17){
return "high school";
}
else if (age >= 18){
return "college";
}
else{
return "invalid";
}
}
//method to return name and age
public String fullString() {
return "Name: " + name + "\nAge: " + age;
}
} //end Student class
There's something not right about the Student.java code, but I don't know what. The StudentClient.java file is not supposed to be changed. What needs to be fixed?
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
} //ends program
Student.java
/* Jessica Chen
* Saturday 6/22/13
* Java 1.7.0_21 and NetBeans 7.3
* Determines type of student based on age
*/
public class Student
{
private String name;
private int age;
public Student(String newName, int newAge){
setName(newName);
setAge(newAge);
}
//Mutator method to set name
public void setName(String newName){
name = newName;
}
//Accessor method to get name
public String getName(){
return name;
}
//Mutator method to check validity of data and set age
public void setAge(int newAge) {
if (newAge > 0){
age = newAge;
} else {
System.out.println("Age cannot be negative.");
}
}
//Accessor method to get age
public int getAge() {
return age;
}
//method to determine school level
public String typeOfStudent (int age){
if (age >= 0 && age <= 4){
return "preschool";
}
else if (age == 5){
return "kindergarten";
}
else if (age >= 6 && age <= 10){
return "elementary school";
}
else if (age >= 11 && age <= 13){
return "middle school";
}
else if (age >=14 && age <= 17){
return "high school";
}
else if (age >= 18){
return "college";
}
else{
return "invalid";
}
}
//method to return name and age
public String fullString() {
return "Name: " + name + "\nAge: " + age;
}
} //end Student class
There's something not right about the Student.java code, but I don't know what. The StudentClient.java file is not supposed to be changed. What needs to be fixed?