Ok so this is for school - but some reason I keep getting not the desired output - I think I messed up somewhere but after looking it over a few times it just looks more and more right sooo Ima ask yall.
Its not showing the toString() in my testDrive- it will show the ' blah ' in the loop so i know the loop works :X
Code
import java.util.*;
public class Part1TestDrive {
public static void main(String[] args) {
// Part1Kinder Part1Student -- Doc names (easy copy pasta)
Part1Student student01 = new Part1Student();
student01.setName("Teddy");
student01.setID("1234");
student01.setSchool("Randolph");
student01.setTeacher("Mr. Larry");
ArrayList<Part1Student> list = new ArrayList<Part1Student>();
list.add(student01);
// Goes through items in array list - calls the toString() for the current list item
for (int i = 0; i < list.size(); i++) {
list.get(i).toString();
System.out.println("BLAH");
}
}
}
Student class
Code
import java.util.*;
public class Part1Student {
private String _Studentid;
private String _StudentName;
private String _SchoolName;
private String _Teacher;
public void setID(String Studentid) {
_Studentid = Studentid;
}
public String getID() {
return _Studentid;
}
public void setName (String StudentName) {
_StudentName = StudentName;
}
public String getName() {
return _StudentName;
}
public void setSchool (String SchoolName) {
_SchoolName = SchoolName;
}
public String getSchool() {
return _SchoolName;
}
public void setTeacher (String Teacher) {
_Teacher = Teacher;
}
public String getTeacher() {
return _Teacher;
}
public String toString() {
return "StudentID: " + _Studentid
+ "\nStudentName: " + _StudentName + "\nSchoolName: "
+ _SchoolName + "\nTeacher: " + _Teacher;
}
}
Kindergarden students subclass
Code
import java.util.*;
public class Part1Kinder extends Part1Student {
private String _showTellItem;
public void getNewField (String showTellItem) {
_showTellItem = showTellItem;
}
public String setNewField() {
return _showTellItem;
}
public String toString() {
// Part1Student ref01 = new Part1Student();
return /* ref01.toString() + */ "\nA Kindergardn Student!\nShowTellItem: "
+ _showTellItem;
}
}