week 6 discussion
play

Week 6 Discussion Wednesday, 11/6/19 Reminders PSA4 Submission due - PowerPoint PPT Presentation

Week 6 Discussion Wednesday, 11/6/19 Reminders PSA4 Submission due Tuesday, November 12 11:59pm For students that are missing discussion participation and you clicked in, we will handle it all at once at the end of the quarter. Extra credit:


  1. Week 6 Discussion Wednesday, 11/6/19

  2. Reminders PSA4 Submission due Tuesday, November 12 11:59pm For students that are missing discussion participation and you clicked in, we will handle it all at once at the end of the quarter. Extra credit: Beating the raccoon, but fix your code first!

  3. Today’s agenda Inheritance Review ● Overview of the PA ● Game mechanics ● Critters you have to make ● Inheritance Practice ●

  4. PSA4 Overview ● ● Critter ●

  5. Overriding ● eat() getColor() getAttack() Critter ● Critter Critter ● Critter

  6. Critter World X: 0, Y: 0 ● ● ●

  7. Meet the Methods

  8. Movement

  9. Movement ● Critter getMove ● Critter North South West East Center ●

  10. Eating

  11. Eating ● Critter ● Critter ● Critter

  12. Fighting

  13. Fighting ● ● ● Critter ROAR POUNCE SCRATCH ● ROAR SCRATCH SCRATCH POUNCE POUNCE ROAR ○ ● ● FORFEIT FORFEIT

  14. Mating

  15. Mating ● ● Critter ● ●

  16. Scoring ● ● Critter Critter Critter

  17. Meet the Critter s

  18. Critter.java ● ● ●

  19. Starfish extends Critter ● ● ● FORFEIT

  20. Turtle extends Critter ● WEST ● eat() Critter ● ROAR FORFEIT ○

  21. Feline extends Critter ● ○ ● eat ○ ● POUNCE

  22. Lion extends Feline ● Overrides Feline getAttack() ● ● eat ○

  23. Leopard extends Feline ● Lion ● Leopard ○ ● confidence ●

  24. Ocelot extends Leopard ● override getColor() generateAttack() ● Override generateAttack() ● getAttack()

  25. Elephant extends Critter ● goalX goalY ○ Elephant ● getMove() ○ Elephant Elephant ● Elephant getMove()

  26. buffBehavior() & debuff() ● Critter Critter Critter ● buffBehavior() Critter ● debuff() Critter ●

  27. Lion's Buff Effect ● Lion ●

  28. Leopard's Buff Effect ● Leopard ●

  29. Ocelot's Buff Effect ● Leopard ●

  30. Starfish's Buff Effect ● ● ● …

  31. Starfish's Teleportation ● void teleport(Point currentLocation, Critter[][] arena) ○ Starfish ■ ○ Starfish null

  32. More Inheritance Practice Problems

  33. public class Vehicle { public class Motorcycle extends Vehicle { String name; @Override int year; public void startEngine() { public void startEngine() { System.out.println("ZOOM"); System.out.println("Engine"); } } } public String getName() { return name; } public static void main(String[] args) { } Vehicle v = new Vehicle(); v.startEngine(); public class Car extends Vehicle { Vehicle c = new Car(); @Override public void startEngine() { c.startEngine(); System.out.println("VROOM"); Motorcycle m = new Motorcycle(); } m.startEngine(); } } // What is the output?

  34. public class Vehicle { public class Motorcycle extends Vehicle { String name; @Override int year; public void startEngine() { public void startEngine() { System.out.println("ZOOM"); System.out.println("Engine"); } } } public String getName() { return name; } public static void main(String[] args) { } Vehicle v = new Vehicle(); v.startEngine(); public class Car extends Vehicle { Vehicle c = new Car(); @Override public void startEngine() { c.startEngine(); System.out.println("VROOM"); Motorcycle m = new Motorcycle(); } m.startEngine(); } } // What is the output? Engine VROOM ZOOM

  35. Inheritance Practice 2 What gets printed? public class Vehicle { public void startEngine() { A: System.out.println("Starting Engine"); Starting Engine } } B: Car 0 public class Car extends Vehicle { public void startEngine(int x) { C: System.out.println("Car " + x); compiler error } } public static void main(String[] args) { Vehicle c = new Car(); c.startEngine(); }

  36. Inheritance Practice 2 This gets printed. public class Vehicle { public void startEngine() { A: System.out.println("Starting Engine"); Starting Engine } } B: Car 0 public class Car extends Vehicle { public void startEngine(int x) { C: System.out.println("Car " + x); compiler error } } public static void main(String[] args) { Vehicle c = new Car(); c.startEngine(); }

  37. Inheritance Practice 3 What gets printed? public class Vehicle { public void startEngine() { A: System.out.println("Starting Engine"); Starting Engine } } B: Car 1 public class Car extends Vehicle { public void startEngine(int x) { C: System.out.println("Car " + x); compiler error } } public static void main(String[] args) { Vehicle c = new Car(); c.startEngine(1); }

  38. Inheritance Practice 3 This gets printed. public class Vehicle { public void startEngine() { A: System.out.println("Starting Engine"); Starting Engine } } B: Car 1 public class Car extends Vehicle { public void startEngine(int x) { C: System.out.println("Car " + x); compiler error } } public static void main(String[] args) { Vehicle c = new Car(); c.startEngine(1); }

  39. Inheritance Practice 4 What gets printed? public class Vehicle { public void startEngine() { A: System.out.println("Starting Engine"); Starting Engine } } B: Car 1 public class Car extends Vehicle { public void startEngine(int x) { C: System.out.println("Car " + x); compiler error } } public static void main(String[] args) { Car c = new Car(); c.startEngine(1); }

  40. Inheritance Practice 4 This gets printed. public class Vehicle { public void startEngine() { A: System.out.println("Starting Engine"); Starting Engine } } B: Car 1 public class Car extends Vehicle { public void startEngine(int x) { C: System.out.println("Car " + x); compiler error } } public static void main(String[] args) { Car c = new Car(); c.startEngine(1); }

  41. // Inheritance Constructor Example 1 public class Dog { public String name; public Dog() { name = "Dog"; } } public class Husky extends Dog { public Husky() { name = "Husky"; } } // in main() Dog sydney = new Husky(); System.out.println( sydney.name);

  42. // Inheritance Constructor Example 1 public class Dog { public String name; public Dog() { name = "Dog"; } } public class Husky extends Dog { public Husky() { name = "Husky"; } } // in main() Dog sydney = new Husky(); System.out.println( sydney.name); Answer: Husky

  43. // Inheritance Constructor Example 2 public class Dog { public String name; public Dog() { name = "Dog"; } } public class Husky extends Dog { public Husky() { // do nothing } } // in main Dog sydney = new Husky(); Husky cindy = new Husky(); System.out.println( sydney.name + " " + cindy.name);

  44. // Inheritance Constructor Example 2 public class Dog { public String name; public Dog() { name = "Dog"; } } public class Husky extends Dog { public Husky() { // do nothing call super() by default } } // in main Dog sydney = new Husky(); Husky cindy = new Husky(); System.out.println( sydney.name + " " + cindy.name); Answer: Dog Dog

  45. // Inheritance Constructor Example 3 public class Dog { public class Husky extends Dog { public String name; public Husky() { public Dog() { // do nothing name = "Dog"; } } public Husky(String name) { public Dog(String name) { // do nothing this.name = name; } } } } // in main Dog sydney = new Husky(); Husky cindy = new Husky("husky"); System.out.println( sydney.name + " " + cindy.name);

  46. // Inheritance Constructor Example 3 public class Dog { public class Husky extends Dog { public String name; public Husky() { public Dog() { // do nothing name = "Dog"; } } public Husky(String name) { public Dog(String name) { // do nothing this.name = name; } } } } // in main Dog sydney = new Husky(); Husky cindy = new Husky("husky"); System.out.println( sydney.name + " " + cindy.name); Answer: Dog Dog

  47. // Inheritance Constructor Example 4 public class Dog { public class Husky extends Dog { public String name; public Husky() { public Dog() { // do nothing name = "Dog"; } } public Husky(String name) { public Dog(String name) { super(name); this.name = name; } } } } // in main Dog sydney = new Husky(); Husky cindy = new Husky("Husky"); System.out.println( sydney.name + " " + cindy.name);

  48. // Inheritance Constructor Example 4 public class Dog { public class Husky extends Dog { public String name; public Husky() { public Dog() { // do nothing name = "Dog"; } } public Husky(String name) { public Dog(String name) { super(name); this.name = name; // super() not called } } } } // in main Dog sydney = new Husky(); Husky cindy = new Husky("Husky"); System.out.println( sydney.name + " " + cindy.name); Answer: Dog Husky

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend