OOD – My School: Multi – ADT application – Start Small
/**
* Course: ADT for students' courses.
* MySchool Application
* The Course ADT:
* Overload constructor so subject, teacher and period are the input
* arguments.
*
* @RA & mrs.e
* @1.8 3/13/2018 & 5/10/19
*/
public class Course
{
private String name;
private String period;
private String roomNumber;
public Course(String name, String period, String roomNumber)
{
this.name = name;
this.period=period;
this.roomNumber = roomNumber;
}
/**
* parm name - this is the name of the course
*/
public String getName()
{
return name + " ";
}
// draw course(s)
public void draw()
{
StdDraw.picture(1.5, -1.5, "school_courses.png",1.5,1.5);
}
/**
* this is the period of the class
*/
public String getPeriod()
{
return period + " ";
}
/**
* this is the room no of the class
*/
public String getRoomNumber()
{
return roomNumber + " ";
}
public String toString()
{
String output = "Class name: " + name + "\nRoom Number: "
+ roomNumber + "\nPeriod: " + period;
return output;
}
}
/**
* This is an ADT to represent an abstraction of a student
* Student s1 = new Student("Bob", "Smith", 15, "male", 1234);//constructor
* @Rida Ahmed & mrs.e
* @1.8 3/13/2018 & 5/10/19
*/
public class Student
{
private String firstName;
private String lastName;
private String age;
private String gender;
private String id;
private Course [] myCourses = new Course [3]; //ADT as an instance field
// constructor
public Student (String firstName,String lastName,String age,String gender,String id)
{
this.firstName = firstName;
this.lastName = lastName;
this.age = age;
this.gender = gender;
this.id = id; // on hold, not being used
}
// draw method
public void draw()
{
StdDraw.picture(0.4, 0.5, "school_happykids.png",3.7,2);
}
// getter methods
public String getName ()
{
return firstName + " " + lastName;
}
public String getPersonalInfo ()
{
return age + ", " + gender + ", " + id;
}
// setter methods
public void setCourses(Course [] courses)
{
for(int i = 0; i < courses.length; i++){
myCourses[i]=courses[i];
}
}
public void setACourse (Course aCourse){
//interesting
}
// overridden method
public String toString()
{
String output = "";
output += "Student name: " + firstName + " " + lastName + "\nCourses: " ;
for (int i = 0; i < myCourses.length ; i++)
{
output += "\n\n" + myCourses[i];
}
return output;
}
}
/**
* Customized driver to test all the different parts of my class MySchoolTest: student(s)
*
* @RA & mrs.e
* @1.8 3/13/18 & 5/10/19
*/
public class MySchoolTest
{
public static void main(String [] args)
{
// set canvas scales
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");
Course c1 = new Course("Biology", "5", "102");
Course c2 = new Course("precalculus", "4", "136");
Course c3 = new Course("APUSH", "7", "117");
// 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);
//print a student info and courses
System.out.println("\n" + konoa);
// draw a student and friends
konoa.draw()
}
}
/*
* 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
*
*/
/**
* Customized driver to test all the different parts of my class MySchoolTest: course(s)
*
* @RA & mrs.e
* @1.8 3/13/18 & 5/10/19
*/
public class MySchoolTest
{
public static void main(String [] args)
{
// set canvas scales
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");
Course c1 = new Course("Biology", "5", "102");
Course c2 = new Course("precalculus", "4", "136");
Course c3 = new Course("APUSH", "7", "117");
// 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();
}
}