SlideShare a Scribd company logo
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.pdf
badshetoms
 
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
badshetoms
 
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
badshetoms
 
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
badshetoms
 
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
badshetoms
 
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
badshetoms
 
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
badshetoms
 
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
badshetoms
 
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
badshetoms
 
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
badshetoms
 
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
badshetoms
 
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
badshetoms
 
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
badshetoms
 
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
badshetoms
 
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
badshetoms
 
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
badshetoms
 
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
badshetoms
 
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
badshetoms
 
Java Language.....pdf
Java Language.....pdfJava Language.....pdf
Java Language.....pdf
badshetoms
 
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
badshetoms
 

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

Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
IreneSebastianRueco1
 
Smart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICTSmart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICT
simonomuemu
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
Celine George
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5
sayalidalavi006
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 

Recently uploaded (20)

Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
 
Smart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICTSmart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICT
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 

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.