Presentation is loading. Please wait.

Presentation is loading. Please wait.

5/2/2015ITK 1791 Shape {abstract} - ShapeName: String # setShapeName(newShapeName: String): void + getShapeName(): String + getSurfaceArea(): double +

Similar presentations


Presentation on theme: "5/2/2015ITK 1791 Shape {abstract} - ShapeName: String # setShapeName(newShapeName: String): void + getShapeName(): String + getSurfaceArea(): double +"— Presentation transcript:

1 5/2/2015ITK 1791 Shape {abstract} - ShapeName: String # setShapeName(newShapeName: String): void + getShapeName(): String + getSurfaceArea(): double + getPerimeter(): double Rectangle - length: double - height: double + setLength(newLength: double): void + getLength(): double + setHeight(newHeight: double): void + getHeight(): double Circle - radius: double + setRadius(newRadius: double): void + getRadius(): double There are some details that are not as important to the concepts (classes)

2 5/2/2015ITK 1792 interface Object Shape CircleRectangle RectanglePrismCylinder {abstract} ThreeD {interface} + setDepth(double): void + getDepth(): double + getVolume(): double implements

3 5/2/2015ITK 2753 public abstract class Animal { private int weight; public Animal(int lb) { // constructor; weight = lb; } public abstract String is_a(); // What animal is this; public abstract String eats(); // the food it eats; public abstract String sounds(); // the sound it makes; public int Weight() { // return the weight; return weight; } Animal

4 5/2/2015ITK 2754 public abstract class WildAnimal extends Animal { private String fHabit; private String NativePlace=null; public WildAnimal(String feedingHabit, int weight) { super(weight); this.fHabit = feedingHabit; } public String feedingHabit() { return fHabit;} public void lives_in(String NativePlace) { this.NativePlace = NativePlace; } public String lives_in() { return NativePlace;} } WildAnimal

5 5/2/2015ITK 2755 public abstract class DomesticAnimal extends Animal{ private String purpose, my_name=null; public DomesticAnimal(String purpose, int weight) { super(weight); this.purpose = purpose; } public String name() { return my_name; } public void name(String name) { my_name = name; } public String is_for() { return purpose; } } DomesticAnimal

6 5/2/2015ITK 2756 public class Elephant extends WildAnimal{ public Elephant(int weight) { super("herbivorous", weight); } public String is_a() { return "elephant"; } public String eats() { return "banana"; } public String sounds() { return "enheeen"; } Elephant

7 5/2/2015ITK 2757 public abstract class BigCat extends WildAnimal{ public BigCat(int weight) { super("carnivorous", weight); } BigCat public class Tiger extends BigCat{ public Tiger(int weight) { super(weight); } public String is_a() { return "tiger"; } public String sounds() { return "Grrr! Grrr! "; } public String eats() { return "meat"; } } Tiger

8 5/2/2015ITK 2758 public class Lion extends BigCat{ public Lion(int weight) { super(weight); } public String is_a() { return "lion"; } public String sounds() { return "Roarn! Roand!"; } public String eats() { return "meat"; } Lion

9 5/2/2015ITK 2759 public class Cow extends DomesticAnimal { public Cow (int weight) { super("milk",weight); } public String is_a() { return "cow"; } public String sounds() { return "Mooo! Mooo!"; } public String eats() { return "grass"; } Cow

10 5/2/2015ITK 27510 public interface Pet { public String address(); public String likes(); } Pet public class Dog extends DomesticAnimal implements Pet { private String my_address; public Dog (String name, int weight) { super("pleasure",weight); this.name(name); } public String is_a() { return "dog"; } public String sounds() { return "Woof! Woof!"; } public String likes() { return "bone"; } public String eats() { return likes(); } public String address() { return my_address; } public String address(String add) { return my_address = add; } } Dog

11 5/2/2015ITK 27511 public class Cat extends DomesticAnimal implements Pet { private String my_address; public Cat (String name, int weight) { super("pleasure",weight); this.name(name); } public String is_a() { return "cat"; } public String sounds() { return "Meow! Meow!"; } public String likes() { return "fish"; } public String eats() { return likes(); } public String address() { return my_address; } public String address(String add) { return my_address = add;} } Cat

12 5/2/2015ITK 27512 public static void aboutThisDomesticAnimal(DomesticAnimal x) { System.out.println(" Variable x is a " + x.is_a() +"."); System.out.println(x.name() + " is a " + x.Weight()+" ponds "+ x.is_a() + " for " + x.is_for() + "." ); } public static void aboutThisWildAnimal(WildAnimal x) { System.out.println(" Variable x is a " + x.is_a() +"."); System.out.println("This " + x.is_a() + " weights " + x.Weight() + " pounds."); System.out.println("The " + x.is_a() + " is a " + x.feedingHabit()+" animal from " + x.lives_in()+"."); }

13 5/2/2015ITK 27513 Animal animal[]; Dog lucky; Cat mimi; Cow daisy; Tiger T; Lion L; Elephant E; animal = new Animal[6]; animal[0] = lucky = new Dog("Lucky", 25); lucky.address("Bloomington"); animal[1] = mimi = new Cat("Mimi", 15); mimi.address("Normal"); animal[2] = daisy = new Cow(500); daisy.name("Daisy"); animal[3] = T = new Tiger(300); T.lives_in("Asia"); animal[4] = L = new Lion(400); L.lives_in("Africa"); animal[5] = E = new Elephant(1200); E.lives_in("Africa");

14 5/2/2015ITK 27514 for (int i=0; i<animal.length;i++) { System.out.print("\n"+i+": "); if (animal[i] instanceof DomesticAnimal) { aboutThisDomesticAnimal((DomesticAnimal) animal[i]); } if (animal[i] instanceof WildAnimal) { aboutThisWildAnimal((WildAnimal) animal[i]); }

15 5/2/2015ITK 27515 public interface Bird { String color(); } Bird public class Cardinal extends WildAnimal implements Bird{ public Cardinal(int weight) { super("herbivorous", weight); } public String is_a() { return "cardinal"; } public String eats() { return "worms"; } public String sounds() { return "Gee! Gee! Gee!"; } public String color() { return "red"; } Cardinal

16 5/2/2015ITK 27516 public class Canary extends DomesticAnimal implements Pet, Bird { private String my_address; public Canary (String name, int weight) { super("pleasure",weight); this.name(name); } public String color() { return "yellow"; } public String is_a() { return "canary"; } public String sounds() { return "Chu! Chu! Chu!"; } public String likes() { return "seeds"; } public String eats() { return likes(); } public String address() { return my_address; } public String address(String add) { return my_address = add; } Canary


Download ppt "5/2/2015ITK 1791 Shape {abstract} - ShapeName: String # setShapeName(newShapeName: String): void + getShapeName(): String + getSurfaceArea(): double +"

Similar presentations


Ads by Google