Created
November 25, 2016 10:45
-
-
Save NatKarmios/4f79e813b5fa00f01c48b2c69f1a9c10 to your computer and use it in GitHub Desktop.
Mid-Term Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.karmios.nat.computingwork.paper1.fundamentals_of_data_structures.mid_term_test.oop; | |
@SuppressWarnings({"WeakerAccess", "unused"}) | |
public class Course { | |
private String name; | |
private Teacher teacher; | |
public Course(String name, Teacher teacher) { | |
this.name = name; | |
this.teacher = teacher; | |
} | |
public String getName() { | |
return name; | |
} | |
public void setName(String name) { | |
this.name = name; | |
} | |
public Teacher getTeacher() { | |
return teacher; | |
} | |
public void setTeacher(Teacher teacher) { | |
this.teacher = teacher; | |
} | |
@Override | |
public String toString() { | |
return String.format("Name: %s; Teacher: (%s); ", getName(), getTeacher().toString()); | |
} | |
public void printCourse() { | |
System.out.println(this); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.karmios.nat.computingwork.paper1.fundamentals_of_data_structures.mid_term_test.oop; | |
@SuppressWarnings("unused") | |
public class Main { | |
public static void main(String[] args) { | |
Student student1 = new Student(); | |
Student student2 = new Student("Benjamin", 17, "12T", "Computer Science"); | |
student2.printStudent(); | |
student2.printPerson(); | |
Teacher teacher1 = new Teacher("Mr. Bate", 30, "07984738923", "Mathematics"); | |
Teacher teacher2 = new Teacher(); | |
teacher2.printPerson(); | |
Course course = new Course("Computer Science", teacher1); | |
course.printCourse(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.karmios.nat.computingwork.paper1.fundamentals_of_data_structures.mid_term_test.oop; | |
@SuppressWarnings("WeakerAccess") | |
public abstract class Person { | |
private String name = "John"; | |
private int age = 18; | |
public Person(String name, int age) { | |
this.name = name; | |
this.age = age; | |
} | |
public Person() { | |
} | |
public String getName() { | |
return name; | |
} | |
public void setName(String name) { | |
this.name = name; | |
} | |
public int getAge() { | |
return age; | |
} | |
public void setAge(int age) { | |
this.age = age; | |
} | |
@Override | |
public String toString() { | |
return String.format("Name: %s; Age: %s; ", getName(), getAge()); | |
} | |
public void printPerson() { | |
System.out.println(this); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.karmios.nat.computingwork.paper1.fundamentals_of_data_structures.mid_term_test.oop; | |
@SuppressWarnings({"WeakerAccess", "unused"}) | |
public class Student extends Person { | |
private String form; | |
private String favouriteSubject; | |
public Student(){} | |
public Student(String name, int age, String form, String favouriteSubject) { | |
super(name, age); | |
this.form = form; | |
this.favouriteSubject = favouriteSubject; | |
} | |
public Student(String form, String favouriteSubject) { | |
this.form = form; | |
this.favouriteSubject = favouriteSubject; | |
} | |
public String getForm() { | |
return form; | |
} | |
public void setForm(String form) { | |
this.form = form; | |
} | |
public String getFavouriteSubject() { | |
return favouriteSubject; | |
} | |
public void setFavouriteSubject(String favouriteSubject) { | |
this.favouriteSubject = favouriteSubject; | |
} | |
@Override | |
public String toString() { | |
return super.toString() + String.format("Form: %s; Favourite Subject: %s;", getForm(), getFavouriteSubject()); | |
} | |
public void printStudent() { | |
System.out.println(this); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.karmios.nat.computingwork.paper1.fundamentals_of_data_structures.mid_term_test.oop; | |
@SuppressWarnings({"WeakerAccess", "unused"}) | |
public class Teacher extends Person { | |
private String contactNumber; | |
private String department; | |
public Teacher() {} | |
public Teacher(String name, int age, String contactNumber, String department) { | |
super(name, age); | |
this.contactNumber = contactNumber; | |
this.department = department; | |
} | |
public Teacher(String contactNumber, String department) { | |
this.contactNumber = contactNumber; | |
this.department = department; | |
} | |
public String getContactNumber() { | |
return contactNumber; | |
} | |
public void setContactNumber(String contactNumber) { | |
this.contactNumber = contactNumber; | |
} | |
public String getDepartment() { | |
return department; | |
} | |
public void setDepartment(String department) { | |
this.department = department; | |
} | |
@Override | |
public String toString() { | |
return super.toString() + | |
String.format("Contact Number: %s; Department: %s; ", getContactNumber(), getDepartment()); | |
} | |
public void printTeacher() { | |
System.out.println(this); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.karmios.nat.computingwork.paper1.fundamentals_of_data_structures.mid_term_test.recursion; | |
@SuppressWarnings({"WeakerAccess", "unused"}) | |
public class Power { | |
public static int power(int base, int pow) { | |
return pow == 1 ? base : base*power(base, pow-1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment