lab7
This commit is contained in:
BIN
labs/lab7/Dog.class
Normal file
BIN
labs/lab7/Dog.class
Normal file
Binary file not shown.
33
labs/lab7/Dog.java
Normal file
33
labs/lab7/Dog.java
Normal file
@ -0,0 +1,33 @@
|
||||
// ****************************************************************
|
||||
// Dog.java
|
||||
//
|
||||
// A class that holds a dog's name and can make it speak.
|
||||
//
|
||||
// ****************************************************************
|
||||
public abstract class Dog
|
||||
{
|
||||
protected String name;
|
||||
// ------------------------------------------------------------
|
||||
// Constructor -- store name
|
||||
// ------------------------------------------------------------
|
||||
public Dog(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
// ------------------------------------------------------------
|
||||
// Returns the dog's name
|
||||
// ------------------------------------------------------------
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
// ------------------------------------------------------------
|
||||
// Returns a string with the dog's comments
|
||||
// ------------------------------------------------------------
|
||||
public String speak()
|
||||
{
|
||||
return "Woof";
|
||||
}
|
||||
|
||||
public abstract int avgBreedWeight();
|
||||
}
|
20
labs/lab7/DogTest.java
Normal file
20
labs/lab7/DogTest.java
Normal file
@ -0,0 +1,20 @@
|
||||
// ****************************************************************
|
||||
// DogTest.java
|
||||
//
|
||||
// A simple test class that creates a Dog and makes it speak.
|
||||
//
|
||||
// ****************************************************************
|
||||
public class DogTest
|
||||
{
|
||||
public static void main(String[] args)
|
||||
{
|
||||
Dog dog = new Yorkshire("Spike");
|
||||
System.out.println(dog.getName() + " says " + dog.speak());
|
||||
|
||||
Dog Ydog = new Yorkshire("NotSpike");
|
||||
System.out.println(Ydog.getName() + " says " + Ydog.speak());
|
||||
|
||||
Dog Ldog = new Labrador("NotSpike","Black");
|
||||
System.out.println(Ldog.getName() + " says " + Ldog.speak() + " and weights: " + Ldog.avgBreedWeight());
|
||||
}
|
||||
}
|
BIN
labs/lab7/Labrador.class
Normal file
BIN
labs/lab7/Labrador.class
Normal file
Binary file not shown.
33
labs/lab7/Labrador.java
Normal file
33
labs/lab7/Labrador.java
Normal file
@ -0,0 +1,33 @@
|
||||
// ****************************************************************
|
||||
// Labrador.java
|
||||
//
|
||||
// A class derived from Dog that holds information about
|
||||
// a labrador retriever. Overrides Dog speak method and includes
|
||||
// information about avg weight for this breed.
|
||||
//
|
||||
// ****************************************************************
|
||||
public class Labrador extends Dog
|
||||
{
|
||||
private String color; //black, yellow, or chocolate?
|
||||
private int breedWeight = 75;
|
||||
|
||||
public Labrador(String name, String color)
|
||||
{
|
||||
super(name);
|
||||
this.color = color;
|
||||
}
|
||||
// ------------------------------------------------------------
|
||||
// Big bark -- overrides speak method in Dog
|
||||
// ------------------------------------------------------------
|
||||
public String speak()
|
||||
{
|
||||
return "WOOF";
|
||||
}
|
||||
// ------------------------------------------------------------
|
||||
// Returns weight
|
||||
// ------------------------------------------------------------
|
||||
public int avgBreedWeight()
|
||||
{
|
||||
return breedWeight;
|
||||
}
|
||||
}
|
BIN
labs/lab7/Yorkshire.class
Normal file
BIN
labs/lab7/Yorkshire.class
Normal file
Binary file not shown.
26
labs/lab7/Yorkshire.java
Normal file
26
labs/lab7/Yorkshire.java
Normal file
@ -0,0 +1,26 @@
|
||||
// ****************************************************************
|
||||
// Yorkshire.java
|
||||
//
|
||||
// A class derived from Dog that holds information about
|
||||
// a Yorkshire terrier. Overrides Dog speak method.
|
||||
//
|
||||
// ****************************************************************
|
||||
public class Yorkshire extends Dog
|
||||
{
|
||||
private final int breedweight = 15;
|
||||
public Yorkshire(String name)
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
// ------------------------------------------------------------
|
||||
// Small bark -- overrides speak method in Dog
|
||||
// ------------------------------------------------------------
|
||||
public String speak()
|
||||
{
|
||||
return "woof";
|
||||
}
|
||||
|
||||
public int avgBreedWeight() {
|
||||
return breedweight;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user