first commit
This commit is contained in:
23
Lecture Notes/src/Week2/Animals/Animal.java
Normal file
23
Lecture Notes/src/Week2/Animals/Animal.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package Week2.Animals;
|
||||
|
||||
public class Animal {
|
||||
|
||||
protected String name;
|
||||
|
||||
public Animal(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String speak() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "I am an animal called " + name;
|
||||
}
|
||||
}
|
||||
17
Lecture Notes/src/Week2/Animals/Cat.java
Normal file
17
Lecture Notes/src/Week2/Animals/Cat.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package Week2.Animals;
|
||||
|
||||
public class Cat extends Animal{
|
||||
public Cat(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String speak() {
|
||||
return "meow!";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "I am a cat and my name is " + name;
|
||||
}
|
||||
}
|
||||
17
Lecture Notes/src/Week2/Animals/Dog.java
Normal file
17
Lecture Notes/src/Week2/Animals/Dog.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package Week2.Animals;
|
||||
|
||||
public class Dog extends Animal{
|
||||
public Dog (String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String speak() {
|
||||
return "woof!";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString();
|
||||
}
|
||||
}
|
||||
BIN
Lecture Notes/src/Week2/InClassExercise1.zip
Normal file
BIN
Lecture Notes/src/Week2/InClassExercise1.zip
Normal file
Binary file not shown.
18
Lecture Notes/src/Week2/InClassExercise1/Course.java
Normal file
18
Lecture Notes/src/Week2/InClassExercise1/Course.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package Week2.InClassExercise1;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Course {
|
||||
private ArrayList<Section> sections = new ArrayList<>();
|
||||
private String prefix;
|
||||
private int courseNumber;
|
||||
|
||||
public void display() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
8
Lecture Notes/src/Week2/InClassExercise1/Person.java
Normal file
8
Lecture Notes/src/Week2/InClassExercise1/Person.java
Normal file
@@ -0,0 +1,8 @@
|
||||
package Week2.InClassExercise1;
|
||||
|
||||
|
||||
public class Person {
|
||||
|
||||
private String name;
|
||||
|
||||
}
|
||||
17
Lecture Notes/src/Week2/InClassExercise1/Section.java
Normal file
17
Lecture Notes/src/Week2/InClassExercise1/Section.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package Week2.InClassExercise1;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Section {
|
||||
|
||||
private ArrayList<Person> students = new ArrayList<>();
|
||||
private String classroom;
|
||||
|
||||
public int numStudents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void display() {
|
||||
|
||||
}
|
||||
}
|
||||
16
Lecture Notes/src/Week2/InClassExercise1/Student.java
Normal file
16
Lecture Notes/src/Week2/InClassExercise1/Student.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package Week2.InClassExercise1;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Student {
|
||||
|
||||
private ArrayList<Integer> quizzes = new ArrayList<>();
|
||||
|
||||
public double quizAverage() {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
public void display(){
|
||||
|
||||
}
|
||||
}
|
||||
10
Lecture Notes/src/Week2/InClassExercise1/Teacher.java
Normal file
10
Lecture Notes/src/Week2/InClassExercise1/Teacher.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package Week2.InClassExercise1;
|
||||
|
||||
public class Teacher extends Person {
|
||||
|
||||
public double salary;
|
||||
|
||||
public double calculateTaxes() {
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
14
Lecture Notes/src/Week2/InheritanceDriver.java
Normal file
14
Lecture Notes/src/Week2/InheritanceDriver.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package Week2;
|
||||
|
||||
import Week2.Animals.Animal;
|
||||
import Week2.Animals.Cat;
|
||||
|
||||
public class InheritanceDriver {
|
||||
public static void main(String[] args) {
|
||||
Animal a = new Animal("Fred");
|
||||
System.out.println(a);
|
||||
|
||||
Cat c = new Cat("Fluffy");
|
||||
System.out.println(c);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user