vault backup: 2024-01-21 00:27:23
This commit is contained in:
59
Semester 2/Programming 2/Week 1/zoo-io-v3/Animal.java
Normal file
59
Semester 2/Programming 2/Week 1/zoo-io-v3/Animal.java
Normal file
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* class <code>Animal</code> simulates an animal and stores
|
||||
* the species and name.
|
||||
*
|
||||
* @author D Newton
|
||||
* @version Version 1, 1 November 2010
|
||||
*/
|
||||
public class Animal
|
||||
{
|
||||
// species of the animal e.g. lion, tiger
|
||||
private String species;
|
||||
// name of the animal e.g. Leo, Tommy
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* Create an animal of the specified species and with the specified name
|
||||
*
|
||||
* @param <code>species</code> a <code>String</code> specifying the
|
||||
* type of animal
|
||||
* @param <code>name</code> a <code>String</code> specifying the
|
||||
* name of animal
|
||||
*/
|
||||
public Animal(String species, String name)
|
||||
{
|
||||
this.species = species;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the species of the <code>Animal</code> object
|
||||
*
|
||||
* @return the species of animal, as a <code>String</code>
|
||||
*/
|
||||
public String getSpecies()
|
||||
{
|
||||
return species;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the <code>Animal</code> object
|
||||
*
|
||||
* @return the name of animal, as a <code>String</code>
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representing the <code>Animal</code> object. For a
|
||||
* lion with name Leo it will return the <code>String</code> "Leo, a lion"
|
||||
*
|
||||
* @return a <code>String</code> representation of the animal
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
return name + ", a " + species;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user