158 lines
3.2 KiB
Java
158 lines
3.2 KiB
Java
/**
|
|
* CS1322: Programming Assignment #0 - Fall 2002
|
|
*
|
|
* <PRE>
|
|
* Pet.java
|
|
* Class Pet - A Class designed to learn how to work with
|
|
* methods and javadoc.
|
|
*
|
|
* Revisions: 1.0 Aug. 26, 2002
|
|
* Created the Pet class
|
|
*
|
|
* 1.1 Aug. 26, 2002
|
|
* Finished, Compiled, Tested
|
|
* </PRE>
|
|
*
|
|
* Collaboration Statement:
|
|
* I worked on the homework assignment alone, using only
|
|
* course materials.
|
|
*
|
|
* @author <A HREF="mailto:gtg184g@mail.gatech.edu">Jose Manuel Caban</A>
|
|
* @version Version 1.1, Aug. 26, 2002
|
|
*/
|
|
|
|
public class Pet {
|
|
|
|
////////////////
|
|
//name methods//
|
|
////////////////
|
|
private String name;
|
|
|
|
/**
|
|
* Get the value of name
|
|
*
|
|
* <br><br>
|
|
* @return value of name
|
|
*/
|
|
public String getName()
|
|
{
|
|
return name;
|
|
}
|
|
|
|
/**
|
|
* Set the value of name
|
|
*
|
|
* <br><br>
|
|
* @param n value to assign to name
|
|
*/
|
|
public void setName(String n)
|
|
{
|
|
name = n;
|
|
}
|
|
|
|
///////////////
|
|
//age methods//
|
|
///////////////
|
|
private int age;
|
|
|
|
/**
|
|
* Get the value of age.
|
|
*
|
|
* <br><br>
|
|
* @return value of age.
|
|
*/
|
|
public int getAge() {
|
|
return age;
|
|
}
|
|
|
|
/**
|
|
* Set the value of age.
|
|
*
|
|
* <br><br>
|
|
* @param v Value to assign to age.
|
|
*/
|
|
public void setAge(int v) {
|
|
this.age = v;
|
|
}
|
|
|
|
|
|
//////////////////////
|
|
//animalType methods//
|
|
//////////////////////
|
|
private String animalType;
|
|
|
|
/**
|
|
* Get the value of animalType.
|
|
*
|
|
* <br><br>
|
|
* @return value of animalType.
|
|
*/
|
|
public String getAnimalType() {
|
|
return animalType;
|
|
}
|
|
|
|
/**
|
|
* Set the value of animalType.
|
|
*
|
|
* <br><br>
|
|
* @param v Value to assign to animalType.
|
|
*/
|
|
public void setAnimalType(String v) {
|
|
this.animalType = v;
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////
|
|
|
|
|
|
/**
|
|
* Change standard string to output to be used for this specific program
|
|
*
|
|
* <br><br>
|
|
* @return phrase as string
|
|
*/
|
|
public String toString()
|
|
{
|
|
return "My name is "+ getName() + "\n" +
|
|
"I am a "+getAnimalType()+" that is "+getAge()+" year"+((age>1)?"s ":" ")+
|
|
"old.";
|
|
}//added the plurality after seeing someone say it was fixed in the autograder
|
|
//so no points off!!!! yay!
|
|
|
|
|
|
/**
|
|
* Debugging main for class Pet.
|
|
*
|
|
* <br><br>
|
|
* @param args IGNORED
|
|
*/
|
|
|
|
|
|
public static void main(String[] args) {
|
|
Pet fluffy = new Pet();
|
|
Pet fido = new Pet();
|
|
Pet mrBubbles = new Pet();
|
|
|
|
//Fluffy declarations (that sounds rather humorous doesn't it?)
|
|
fluffy.setName("Fluffy");
|
|
fluffy.setAge(3);
|
|
fluffy.setAnimalType("Cat");
|
|
|
|
//Fido declarations
|
|
fido.setName("Fido");
|
|
fido.setAge(5);
|
|
fido.setAnimalType("Dog");
|
|
|
|
//mrBubbles declaration
|
|
mrBubbles.setName("Mr. Bubbles");
|
|
mrBubbles.setAge(1); //give him another week
|
|
mrBubbles.setAnimalType("Fish");
|
|
|
|
//print to screen
|
|
System.out.println(fluffy);
|
|
System.out.println(fido);
|
|
System.out.println(mrBubbles);
|
|
|
|
}// end of main(String[] args)
|
|
|
|
}// end of class Pet
|