CodeHS Java9.2.6 Students Part 1 StudentTester.java code example
Example 1: CodeHS Java9.2.6 Students Part 1 StudentTester.java
public class StudentTester
{
public static void main(String[] args)
{
Student bill = new Student("bill", 2020);
StudentAthlete robert = new StudentAthlete("robert", 2022, "soccer", true);
}
}
Example 2: CodeHS Java9.2.6 Students Part 2 Student.java
public class Student
{
private String name;
private int classYear;
public Student(String name, int year){
this.name = name;
this.classYear = year;
}
public String getName(){
return name;
}
public int getClassYear(){
return classYear;
}
public String toString(){
return name + ", class of " + classYear;
}
}
Example 3: CodeHS Java 9.2.6 Students Part 3 StudentAthlete.java
public class StudentAthlete extends Student
{
private String sport;
private boolean eligible;
public StudentAthlete(String name, int classYear, String sport, boolean eligible){
super(name, classYear);
this.sport = sport;
this.eligible = eligible;
}
public String getSport(){
return sport;
}
public boolean isEligible(){
return eligible;
}
@Override
public String toString(){
return super.getName() + ", class of " + super.getClassYear() +
", plays " + sport;
}
}