/** * Teacher t1 = new Teacher("Sarah", "Clark", 35, "female", "Hello, class!"); * * @author (your name) * @version (a version number or a date) */ public class Teacher { private String firstName; private String lastName; private String age; private String gender; private String greeting; private Course course; private Student aStudent; public Teacher(String firstName, String lastName,Course course,Student stu) { this.firstName = firstName; this.lastName = lastName; this.course = course; aStudent = stu; } // draw teacher(s) public void draw() { StdDraw.picture(-1,-1.5,"school_teachers.png",2,1); } // getter/accessor methods public String getName() { return firstName+ " " + lastName; } public String getAge() { return age; } public String getGender() { return gender; } public String getGreeting() { return greeting; } public String toString() { String output = ""; output += "Teacher name: " + firstName + " " + lastName + "\nCourse Taught: " + course + "\nStudent: " + aStudent ; return output; } }
/** * Cistomized driver to test all the different parts of my class MySchoolTest * * @RA & mrs.e * @1.8 3/13/18 & 5/10/19 */ public class MySchoolTest { public static void main(String [] args) { //StdDraw.setXscale(-2.03,2.03); //StdDraw.setYscale(-2.03,2.03); StdDraw.setXscale(-2,2); StdDraw.setYscale(-2,2); //create an object of student //then create 3 objects of course //afterwards we add the 3 objects of course to the student Student konoa = new Student("Konoa", "Smith", "15", "female", "1234"); konoa.draw(); Course c1 = new Course("Biology", "5", "102"); Course c2 = new Course("precalculus", "4", "136"); Course c3 = new Course("APUSH", "7", "117"); // create an object of Teacher Teacher mrBill = new Teacher("Jasmine", "Flores", "28", "MYOB", "Namaste", c1); // print a teacher System.out.println("\n" + mrBill); mrBill.draw(); // print a course information System.out.println("Print a course "); System.out.println(c1); // add all courses to an array Course [] courses = { c1,c2,c3}; // assign all courses to a student konoa.setCourses(courses); c1.draw(); //print a student info and courses System.out.println("\n" + konoa); /** * I omitted the school object for easier understanding * of few interacting ADT objects */ } } /* * Teacher name: Jasmine Flores * Course Taught: * Class name: Biology * Room Number: 102 * Period: 5 * * Print a course * Class name: Biology * Room Number: 102 * Period: 5 * Student name: Konoa Smith * Courses: * Class name: Biology * Room Number: 102 * Period: 5 * Class name: precalculus * Room Number: 136 * Period: 4 * Class name: APUSH * Room Number: 117 * Period: 7 * */