Imagine that you want to keep track of your pet fish Each fi
Imagine that you want to keep track of your pet fish. Each fish is a certain kind and has a two-part name. For example, your clownfish is named Nemo Finding. You want to see whether any two given fish are the same kind. You also want to know how many fish you have. Design, implement, and demonstrate a class Fish that meets the previous requirements. Include UML diagram that gives only the class names and the associations between them. Document each method with comments in javadoc format. Implement a class called Name to represent a fish’s pet name. Some of your methods and constructors must have object parameter of type class. /** SAMPLE OUTPUT: Test toString(): Nemo Finding (clownfish) Test getName(), getType(), and getNumberOfFish(): My name is Nemo Finding; I am a clownfish fish. There are 3 fish in the tank. Test isSameType(): Nemo Finding (clownfish) and Bozo Iron (clownfish) are the same type of fish. Nemo Finding (clownfish) and Patrick Star (starfish) are different types of fish. Press any key to continue . . .
Solution
package snippet;
public class Fish {
String name;
String type;
static int counter=0;
Fish(String n,String t)
{
name=n;
type=t;
counter++;
}
String getName()
{
return name;
}
String getType()
{
return type;
}
int getNumberOfFish()
{
return counter;
}
boolean isSameType(Fish f)
{
if(type.equals(f.type))
return true;
return false;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Fish f1=new Fish(\"Nemo Finding\",\"clownfish\");
Fish f2=new Fish(\"Bozo Iron\",\"clownfish\");
Fish f3=new Fish(\"Patrick Star\",\"starfish\");
System.out.println(\"My name is \"+f1.getName());
System.out.println(\"I am \"+f1.getType());
System.out.println(\"There are \"+counter+\" fish in tanks\");
if(f1.isSameType(f2))
{
System.out.println(\"Nemo Finding (clownfish) and Bozo Iron (clownfish) are the same type of fish. \");
}
else
{
System.out.println(\"Nemo Finding (clownfish) and Bozo Iron (clownfish) are not the same type of fish. \");
}
if(f1.isSameType(f3))
{
System.out.println(\"Nemo Finding (clownfish) and Patrick Star (starfish) are same types of fish. \");
}
else
{
System.out.println(\"Nemo Finding (clownfish) and Patrick Star (starfish) are different types of fish.\");
}
}
}
=========================================
Output:
My name is Nemo Finding
I am clownfish
There are 3 fish in tanks
Nemo Finding (clownfish) and Bozo Iron (clownfish) are the same type of fish.
Nemo Finding (clownfish) and Patrick Star (starfish) are different types of fish.

