SlideShare a Scribd company logo
1 of 3
Download to read offline
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.

More Related Content

More from badshetoms

What is the Insertion Sort MIPS Assembly codeSolution.globl m.pdf
What is the Insertion Sort MIPS Assembly codeSolution.globl m.pdfWhat is the Insertion Sort MIPS Assembly codeSolution.globl m.pdf
What is the Insertion Sort MIPS Assembly codeSolution.globl m.pdfbadshetoms
 
9. How much would it cost to construct a building today that cost $12.pdf
9. How much would it cost to construct a building today that cost $12.pdf9. How much would it cost to construct a building today that cost $12.pdf
9. How much would it cost to construct a building today that cost $12.pdfbadshetoms
 
True or false 20. A manufacturer has a duty to warn about risks that.pdf
True or false 20. A manufacturer has a duty to warn about risks that.pdfTrue or false 20. A manufacturer has a duty to warn about risks that.pdf
True or false 20. A manufacturer has a duty to warn about risks that.pdfbadshetoms
 
to a 1911 in an effort to reduce violence against Suffragettes of NAW.pdf
to a 1911 in an effort to reduce violence against Suffragettes of NAW.pdfto a 1911 in an effort to reduce violence against Suffragettes of NAW.pdf
to a 1911 in an effort to reduce violence against Suffragettes of NAW.pdfbadshetoms
 
There are many cases of human disease where an enzyme activity is lac.pdf
There are many cases of human disease where an enzyme activity is lac.pdfThere are many cases of human disease where an enzyme activity is lac.pdf
There are many cases of human disease where an enzyme activity is lac.pdfbadshetoms
 
The United states has utilize multiple forms of liberalism through o.pdf
The United states has utilize multiple forms of liberalism through o.pdfThe United states has utilize multiple forms of liberalism through o.pdf
The United states has utilize multiple forms of liberalism through o.pdfbadshetoms
 
Calculator 26 ng Learning pose that the Fed engages in expansionary.pdf
Calculator 26 ng Learning pose that the Fed engages in expansionary.pdfCalculator 26 ng Learning pose that the Fed engages in expansionary.pdf
Calculator 26 ng Learning pose that the Fed engages in expansionary.pdfbadshetoms
 
Silver chromate is sparingly soluble in aqueous solutions. The Ksp o.pdf
Silver chromate is sparingly soluble in aqueous solutions. The Ksp o.pdfSilver chromate is sparingly soluble in aqueous solutions. The Ksp o.pdf
Silver chromate is sparingly soluble in aqueous solutions. The Ksp o.pdfbadshetoms
 
Problem 21.12 Histone genes are unusual among eukaryotic genes becaus.pdf
Problem 21.12 Histone genes are unusual among eukaryotic genes becaus.pdfProblem 21.12 Histone genes are unusual among eukaryotic genes becaus.pdf
Problem 21.12 Histone genes are unusual among eukaryotic genes becaus.pdfbadshetoms
 
Privacy and Security What types of health care data are protected u.pdf
Privacy and Security What types of health care data are protected u.pdfPrivacy and Security What types of health care data are protected u.pdf
Privacy and Security What types of health care data are protected u.pdfbadshetoms
 
1. Project risk is normally highest during the project Executing Pro.pdf
1. Project risk is normally highest during the project Executing Pro.pdf1. Project risk is normally highest during the project Executing Pro.pdf
1. Project risk is normally highest during the project Executing Pro.pdfbadshetoms
 
PLEASE HELP ME !!IT IS Due Tonight ;(!How can I make the add but.pdf
PLEASE HELP ME !!IT IS Due Tonight ;(!How can I make the add but.pdfPLEASE HELP ME !!IT IS Due Tonight ;(!How can I make the add but.pdf
PLEASE HELP ME !!IT IS Due Tonight ;(!How can I make the add but.pdfbadshetoms
 
Part AAxonemal dyneins areAxonemal dyneins areassociated with ci.pdf
Part AAxonemal dyneins areAxonemal dyneins areassociated with ci.pdfPart AAxonemal dyneins areAxonemal dyneins areassociated with ci.pdf
Part AAxonemal dyneins areAxonemal dyneins areassociated with ci.pdfbadshetoms
 
Manufacturing company that is considering Linux as a solution for so.pdf
Manufacturing company that is considering Linux as a solution for so.pdfManufacturing company that is considering Linux as a solution for so.pdf
Manufacturing company that is considering Linux as a solution for so.pdfbadshetoms
 
C programming.   For this code I only need to add a function so th.pdf
C programming.   For this code I only need to add a function so th.pdfC programming.   For this code I only need to add a function so th.pdf
C programming.   For this code I only need to add a function so th.pdfbadshetoms
 
Modern Algebra With respect to addition show that the set of Even .pdf
Modern Algebra With respect to addition show that the set of Even .pdfModern Algebra With respect to addition show that the set of Even .pdf
Modern Algebra With respect to addition show that the set of Even .pdfbadshetoms
 
Looks like the questions has been ask before but isnt answered cor.pdf
Looks like the questions has been ask before but isnt answered cor.pdfLooks like the questions has been ask before but isnt answered cor.pdf
Looks like the questions has been ask before but isnt answered cor.pdfbadshetoms
 
List and briefly describe Diversity & InclusionSolutionDiversi.pdf
List and briefly describe Diversity & InclusionSolutionDiversi.pdfList and briefly describe Diversity & InclusionSolutionDiversi.pdf
List and briefly describe Diversity & InclusionSolutionDiversi.pdfbadshetoms
 
Java Language.....pdf
Java Language.....pdfJava Language.....pdf
Java Language.....pdfbadshetoms
 
compare and contrast the matrix and the allegorySolutionThe ma.pdf
compare and contrast the matrix and the allegorySolutionThe ma.pdfcompare and contrast the matrix and the allegorySolutionThe ma.pdf
compare and contrast the matrix and the allegorySolutionThe ma.pdfbadshetoms
 

More from badshetoms (20)

What is the Insertion Sort MIPS Assembly codeSolution.globl m.pdf
What is the Insertion Sort MIPS Assembly codeSolution.globl m.pdfWhat is the Insertion Sort MIPS Assembly codeSolution.globl m.pdf
What is the Insertion Sort MIPS Assembly codeSolution.globl m.pdf
 
9. How much would it cost to construct a building today that cost $12.pdf
9. How much would it cost to construct a building today that cost $12.pdf9. How much would it cost to construct a building today that cost $12.pdf
9. How much would it cost to construct a building today that cost $12.pdf
 
True or false 20. A manufacturer has a duty to warn about risks that.pdf
True or false 20. A manufacturer has a duty to warn about risks that.pdfTrue or false 20. A manufacturer has a duty to warn about risks that.pdf
True or false 20. A manufacturer has a duty to warn about risks that.pdf
 
to a 1911 in an effort to reduce violence against Suffragettes of NAW.pdf
to a 1911 in an effort to reduce violence against Suffragettes of NAW.pdfto a 1911 in an effort to reduce violence against Suffragettes of NAW.pdf
to a 1911 in an effort to reduce violence against Suffragettes of NAW.pdf
 
There are many cases of human disease where an enzyme activity is lac.pdf
There are many cases of human disease where an enzyme activity is lac.pdfThere are many cases of human disease where an enzyme activity is lac.pdf
There are many cases of human disease where an enzyme activity is lac.pdf
 
The United states has utilize multiple forms of liberalism through o.pdf
The United states has utilize multiple forms of liberalism through o.pdfThe United states has utilize multiple forms of liberalism through o.pdf
The United states has utilize multiple forms of liberalism through o.pdf
 
Calculator 26 ng Learning pose that the Fed engages in expansionary.pdf
Calculator 26 ng Learning pose that the Fed engages in expansionary.pdfCalculator 26 ng Learning pose that the Fed engages in expansionary.pdf
Calculator 26 ng Learning pose that the Fed engages in expansionary.pdf
 
Silver chromate is sparingly soluble in aqueous solutions. The Ksp o.pdf
Silver chromate is sparingly soluble in aqueous solutions. The Ksp o.pdfSilver chromate is sparingly soluble in aqueous solutions. The Ksp o.pdf
Silver chromate is sparingly soluble in aqueous solutions. The Ksp o.pdf
 
Problem 21.12 Histone genes are unusual among eukaryotic genes becaus.pdf
Problem 21.12 Histone genes are unusual among eukaryotic genes becaus.pdfProblem 21.12 Histone genes are unusual among eukaryotic genes becaus.pdf
Problem 21.12 Histone genes are unusual among eukaryotic genes becaus.pdf
 
Privacy and Security What types of health care data are protected u.pdf
Privacy and Security What types of health care data are protected u.pdfPrivacy and Security What types of health care data are protected u.pdf
Privacy and Security What types of health care data are protected u.pdf
 
1. Project risk is normally highest during the project Executing Pro.pdf
1. Project risk is normally highest during the project Executing Pro.pdf1. Project risk is normally highest during the project Executing Pro.pdf
1. Project risk is normally highest during the project Executing Pro.pdf
 
PLEASE HELP ME !!IT IS Due Tonight ;(!How can I make the add but.pdf
PLEASE HELP ME !!IT IS Due Tonight ;(!How can I make the add but.pdfPLEASE HELP ME !!IT IS Due Tonight ;(!How can I make the add but.pdf
PLEASE HELP ME !!IT IS Due Tonight ;(!How can I make the add but.pdf
 
Part AAxonemal dyneins areAxonemal dyneins areassociated with ci.pdf
Part AAxonemal dyneins areAxonemal dyneins areassociated with ci.pdfPart AAxonemal dyneins areAxonemal dyneins areassociated with ci.pdf
Part AAxonemal dyneins areAxonemal dyneins areassociated with ci.pdf
 
Manufacturing company that is considering Linux as a solution for so.pdf
Manufacturing company that is considering Linux as a solution for so.pdfManufacturing company that is considering Linux as a solution for so.pdf
Manufacturing company that is considering Linux as a solution for so.pdf
 
C programming.   For this code I only need to add a function so th.pdf
C programming.   For this code I only need to add a function so th.pdfC programming.   For this code I only need to add a function so th.pdf
C programming.   For this code I only need to add a function so th.pdf
 
Modern Algebra With respect to addition show that the set of Even .pdf
Modern Algebra With respect to addition show that the set of Even .pdfModern Algebra With respect to addition show that the set of Even .pdf
Modern Algebra With respect to addition show that the set of Even .pdf
 
Looks like the questions has been ask before but isnt answered cor.pdf
Looks like the questions has been ask before but isnt answered cor.pdfLooks like the questions has been ask before but isnt answered cor.pdf
Looks like the questions has been ask before but isnt answered cor.pdf
 
List and briefly describe Diversity & InclusionSolutionDiversi.pdf
List and briefly describe Diversity & InclusionSolutionDiversi.pdfList and briefly describe Diversity & InclusionSolutionDiversi.pdf
List and briefly describe Diversity & InclusionSolutionDiversi.pdf
 
Java Language.....pdf
Java Language.....pdfJava Language.....pdf
Java Language.....pdf
 
compare and contrast the matrix and the allegorySolutionThe ma.pdf
compare and contrast the matrix and the allegorySolutionThe ma.pdfcompare and contrast the matrix and the allegorySolutionThe ma.pdf
compare and contrast the matrix and the allegorySolutionThe ma.pdf
 

Recently uploaded

Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 

Recently uploaded (20)

Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 

Imagine that you want to keep track of your pet fish. Each fish is a.pdf

  • 1. 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; }
  • 2. 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
  • 3. { 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.