Test (Tuesday) - Classes & Objects - Attributes (the variables) - Methods (the verbs) - Inheritance (extends, super) Super hard Classes Question Example ======================= == EXAMPLE 1 =================== Make a Student and Staff Make a common class: Human class Human { //Common things for both Staff & Students go here int age, x, y; String fName, lName; int vacation; Human (String f, String l, int a){ this.age = a; this.fName = f; this.lName = l; this.x = 0; this.y = 0; this.vacation = 0; //Suspension system } void walk (int a, int b){ this.x = a; this.y = b; } } class Staff extends Human{ float salary; int forksStolen; Staff (int age, String first, String last, float sal){ super(first, last, age); this.salary = sal; this.forksStolen = 0; } boolean cP(String fN, String lN){ //suspend student fName, lName for(int i=0; i < population; i ++){ if(population[i].fName == fN && population[i].lName == lN){ population [i].vacation = 5 + rand(5); break; } } boolean result = true; if(random(100) > 60) result = false; return result; } } class Student extends Human{ float average; int[] marks; Student (String first, String last, int age){ super(first, last, age); this.marks = new int[8]; this.average = -1; } boolean HasFuture(){ boolean res = false; if(random(100) > 50) res = true; return res; } void crashCar(){ Guzy.vacation += 10 + rand(15); this.vacation += 30; } } Staff Guzy = new Staff("Mr", "GGGGG", 36); Guzy.cP("Steve", "jobs"); Student[] population = new Student[2100]; population[0] = new Student("Steve", "jobs", "900"); population[1] = new Student("Steve", "JobS", "901"); population[2] = new Student("Steve", "joBs", "902"); Syed = new Student("Syed", "???", -1); Syed.crashCar(); Syed.crashCar() population[1].crashCar(); ======================= == EXAMPLE 2 =================== Good cop vs Bad cop class Cop { float salary; boolean hasGun; Hat myHat; //Assuming we had a Hat class String name; int dayToRetirement; Cop (String n, float sal){ this.name = n; this.salary = sal; this.hasGun = true; this.myHat = new Hat(); this.daysToRetirement = 5; } boolean eatDonuts(){ return true; } void tempFate(){ print("I've only got " + this.daysToRetirement + " to retirement"); print("Can't wait to go home to my wife and kids"); } } class GoodCop extends Cop { boolean smile; GoodCop (String nm, float dollars){ super(nm, dollars); this.smile = true; } void showMercy(){ print("have some water?"); } } class BadCop extends Cop { int attitude; boolean looseCannon; GoodCop partner; BadCop (String name, float sal, int att){ super(name, sal); this.attitude = att; thsi.looseCannon = true; // this.partner = new GoodCop("Alex Murphy", 0); this.partner = dept[floor(random(dept.length))]; } void talkSense(){ if(random(100) > 80) this.looseCannon = false; } } BadCop riggs = new BadCop("Riggs", 20000); riggs.talkSense(); riggs.partner.showMercy(); riggs.tempFate(); GoodCops [] dept = new GoodCop [20]; Thinkie Task (Monday) - 3 quick thinkie style questions, but not so thinkie as Algorithms (sorting) - I will take best mark and ignore the other. Things I include in the midterm mark -> test + thinkie task -> Review, Ball bouce, PEW PEW, anything other show me