SlideShare a Scribd company logo
1 of 3
Download to read offline
can you help me to solve this. Design a Person class similar to the Coin class defined in this
chapter. Then design and implement a driver class called SelectPerson whose main method
creates two Person objects, then randomly selects a gender in both to see in which object a
female gender is selected two times in a row. Consider the possibility that they might tie. Print
the results of each selection and then print the object name which comes up first with the female
gender being selected twice, consecutively
Solution
public class SelectPerson{
public static void main(String []args){
//create two person objects
Person p1=new Person();
Person p2=new Person();
//delcare variable to set intiial values
int count1=0,count2=0,counter=0;
//loop until two consequetive femailes aren't listed
while(count1<2 && count2<2)
{
counter++;
p1.setGender();
p2.setGender();
//display selection of eahc round
System.out.println("*******Round "+counter+"*****");
System.out.println("Object1 = Gender :"+p1);
System.out.println("Object2 = Gender :"+p2);
//check for female occurance
if(p1.isFemale())
{
count1++;
}
if(p2.isFemale())
{
count2++;
}
}
//display the results
if(count1==count2)
System.out.println("Tie");
else
if(count1==2)
System.out.println("p1");
else if(count2==2)
System.out.println("p2");
}
}
//definitin of Person class
class Person
{
//variable to hold gender
private int gender;
//dynamiclaly set gender
public void setGender()
{
gender=(int)(Math.random()*2);
}
//check if gender is female
public boolean isFemale()
{
return (gender==1);
}
//return gender of person object
public String toString()
{
String genderName;
if(gender==0)
genderName="Male";
else
genderName="Female";
return genderName;
}
}

More Related Content

Similar to can you help me to solve this. Design a Person class similar to the .pdf

JAVA A double-ended queue is a list that allows the addition and.pdf
JAVA A double-ended queue is a list that allows the addition and.pdfJAVA A double-ended queue is a list that allows the addition and.pdf
JAVA A double-ended queue is a list that allows the addition and.pdf
amrishinda
 
project2.classpathproject2.project project2 .docx
project2.classpathproject2.project  project2 .docxproject2.classpathproject2.project  project2 .docx
project2.classpathproject2.project project2 .docx
briancrawford30935
 
Lab02kdfshdfgajhdfgajhdfgajhdfgjhadgfasjhdgfjhasdgfjh.pdf
Lab02kdfshdfgajhdfgajhdfgajhdfgjhadgfasjhdgfjhasdgfjh.pdfLab02kdfshdfgajhdfgajhdfgajhdfgjhadgfasjhdgfjhasdgfjh.pdf
Lab02kdfshdfgajhdfgajhdfgajhdfgjhadgfasjhdgfjhasdgfjh.pdf
QalandarBux2
 
1. Section1.- Populating the list of persons on the person listing f.pdf
1. Section1.- Populating the list of persons on the person listing f.pdf1. Section1.- Populating the list of persons on the person listing f.pdf
1. Section1.- Populating the list of persons on the person listing f.pdf
aniljain719651
 
1. Section1.- Populating the list of persons on the person listing.pdf
1. Section1.- Populating the list of persons on the person listing.pdf1. Section1.- Populating the list of persons on the person listing.pdf
1. Section1.- Populating the list of persons on the person listing.pdf
aniljain719651
 
You are not setting any values for those variables(name, ID, interes.pdf
You are not setting any values for those variables(name, ID, interes.pdfYou are not setting any values for those variables(name, ID, interes.pdf
You are not setting any values for those variables(name, ID, interes.pdf
deepakangel
 

Similar to can you help me to solve this. Design a Person class similar to the .pdf (20)

Review Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfReview Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdf
 
Defining classes-and-objects-1.0
Defining classes-and-objects-1.0Defining classes-and-objects-1.0
Defining classes-and-objects-1.0
 
Building .NET-based Applications with C#
Building .NET-based Applications with C#Building .NET-based Applications with C#
Building .NET-based Applications with C#
 
Week 9 IUB c#
Week 9 IUB c#Week 9 IUB c#
Week 9 IUB c#
 
Ad java prac sol set
Ad java prac sol setAd java prac sol set
Ad java prac sol set
 
JAVA A double-ended queue is a list that allows the addition and.pdf
JAVA A double-ended queue is a list that allows the addition and.pdfJAVA A double-ended queue is a list that allows the addition and.pdf
JAVA A double-ended queue is a list that allows the addition and.pdf
 
project2.classpathproject2.project project2 .docx
project2.classpathproject2.project  project2 .docxproject2.classpathproject2.project  project2 .docx
project2.classpathproject2.project project2 .docx
 
Lab02kdfshdfgajhdfgajhdfgajhdfgjhadgfasjhdgfjhasdgfjh.pdf
Lab02kdfshdfgajhdfgajhdfgajhdfgjhadgfasjhdgfjhasdgfjh.pdfLab02kdfshdfgajhdfgajhdfgajhdfgjhadgfasjhdgfjhasdgfjh.pdf
Lab02kdfshdfgajhdfgajhdfgajhdfgjhadgfasjhdgfjhasdgfjh.pdf
 
1. Section1.- Populating the list of persons on the person listing f.pdf
1. Section1.- Populating the list of persons on the person listing f.pdf1. Section1.- Populating the list of persons on the person listing f.pdf
1. Section1.- Populating the list of persons on the person listing f.pdf
 
1. Section1.- Populating the list of persons on the person listing.pdf
1. Section1.- Populating the list of persons on the person listing.pdf1. Section1.- Populating the list of persons on the person listing.pdf
1. Section1.- Populating the list of persons on the person listing.pdf
 
Final ds record
Final ds recordFinal ds record
Final ds record
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java Programming
 
Class notes(week 3) on class objects and methods
Class notes(week 3) on class objects and methodsClass notes(week 3) on class objects and methods
Class notes(week 3) on class objects and methods
 
JAVA Question : Programming Assignment
JAVA Question : Programming AssignmentJAVA Question : Programming Assignment
JAVA Question : Programming Assignment
 
Chap2 class,objects
Chap2 class,objectsChap2 class,objects
Chap2 class,objects
 
You are not setting any values for those variables(name, ID, interes.pdf
You are not setting any values for those variables(name, ID, interes.pdfYou are not setting any values for those variables(name, ID, interes.pdf
You are not setting any values for those variables(name, ID, interes.pdf
 
OOPs & Inheritance Notes
OOPs & Inheritance NotesOOPs & Inheritance Notes
OOPs & Inheritance Notes
 
Class notes(week 3) on class objects and methods
Class notes(week 3) on class objects and methodsClass notes(week 3) on class objects and methods
Class notes(week 3) on class objects and methods
 
c#(loops,arrays)
c#(loops,arrays)c#(loops,arrays)
c#(loops,arrays)
 
Oop lecture9 13
Oop lecture9 13Oop lecture9 13
Oop lecture9 13
 

More from michardsonkhaicarr37

h. What are epigenetic changes How may these contribute to the deve.pdf
h. What are epigenetic changes How may these contribute to the deve.pdfh. What are epigenetic changes How may these contribute to the deve.pdf
h. What are epigenetic changes How may these contribute to the deve.pdf
michardsonkhaicarr37
 
in this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfin this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdf
michardsonkhaicarr37
 
How does alcohol affect IPSP and Potassium Why do the ions move.pdf
How does alcohol affect IPSP and Potassium Why do the ions move.pdfHow does alcohol affect IPSP and Potassium Why do the ions move.pdf
How does alcohol affect IPSP and Potassium Why do the ions move.pdf
michardsonkhaicarr37
 
Describe the concept of web accessibility.Thank-you!Solution.pdf
Describe the concept of web accessibility.Thank-you!Solution.pdfDescribe the concept of web accessibility.Thank-you!Solution.pdf
Describe the concept of web accessibility.Thank-you!Solution.pdf
michardsonkhaicarr37
 
Cephalothorax, 6 pairs of jointed appendages. Aquatic, but comes to s.pdf
Cephalothorax, 6 pairs of jointed appendages. Aquatic, but comes to s.pdfCephalothorax, 6 pairs of jointed appendages. Aquatic, but comes to s.pdf
Cephalothorax, 6 pairs of jointed appendages. Aquatic, but comes to s.pdf
michardsonkhaicarr37
 
After reading the codes of ethics posted to the USAOnline site please.pdf
After reading the codes of ethics posted to the USAOnline site please.pdfAfter reading the codes of ethics posted to the USAOnline site please.pdf
After reading the codes of ethics posted to the USAOnline site please.pdf
michardsonkhaicarr37
 
A perfect left-sided binary tree is a binary tree where every intern.pdf
A perfect left-sided binary tree is a binary tree where every intern.pdfA perfect left-sided binary tree is a binary tree where every intern.pdf
A perfect left-sided binary tree is a binary tree where every intern.pdf
michardsonkhaicarr37
 
Which of the following is FALSE regarding phylogenetic inference met.pdf
Which of the following is FALSE regarding phylogenetic inference met.pdfWhich of the following is FALSE regarding phylogenetic inference met.pdf
Which of the following is FALSE regarding phylogenetic inference met.pdf
michardsonkhaicarr37
 
what are some barriers a company might need to overcome when enterin.pdf
what are some barriers a company might need to overcome when enterin.pdfwhat are some barriers a company might need to overcome when enterin.pdf
what are some barriers a company might need to overcome when enterin.pdf
michardsonkhaicarr37
 

More from michardsonkhaicarr37 (20)

h. What are epigenetic changes How may these contribute to the deve.pdf
h. What are epigenetic changes How may these contribute to the deve.pdfh. What are epigenetic changes How may these contribute to the deve.pdf
h. What are epigenetic changes How may these contribute to the deve.pdf
 
in this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfin this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdf
 
How does alcohol affect IPSP and Potassium Why do the ions move.pdf
How does alcohol affect IPSP and Potassium Why do the ions move.pdfHow does alcohol affect IPSP and Potassium Why do the ions move.pdf
How does alcohol affect IPSP and Potassium Why do the ions move.pdf
 
How has the social change driven the development of new information t.pdf
How has the social change driven the development of new information t.pdfHow has the social change driven the development of new information t.pdf
How has the social change driven the development of new information t.pdf
 
Describe the concept of web accessibility.Thank-you!Solution.pdf
Describe the concept of web accessibility.Thank-you!Solution.pdfDescribe the concept of web accessibility.Thank-you!Solution.pdf
Describe the concept of web accessibility.Thank-you!Solution.pdf
 
Good new technologies are a bit like good new roads Their social ben.pdf
Good new technologies are a bit like good new roads Their social ben.pdfGood new technologies are a bit like good new roads Their social ben.pdf
Good new technologies are a bit like good new roads Their social ben.pdf
 
Cephalothorax, 6 pairs of jointed appendages. Aquatic, but comes to s.pdf
Cephalothorax, 6 pairs of jointed appendages. Aquatic, but comes to s.pdfCephalothorax, 6 pairs of jointed appendages. Aquatic, but comes to s.pdf
Cephalothorax, 6 pairs of jointed appendages. Aquatic, but comes to s.pdf
 
After reading the codes of ethics posted to the USAOnline site please.pdf
After reading the codes of ethics posted to the USAOnline site please.pdfAfter reading the codes of ethics posted to the USAOnline site please.pdf
After reading the codes of ethics posted to the USAOnline site please.pdf
 
A small boy is lost coming down Mount Washington. The leader of the .pdf
A small boy is lost coming down Mount Washington. The leader of the .pdfA small boy is lost coming down Mount Washington. The leader of the .pdf
A small boy is lost coming down Mount Washington. The leader of the .pdf
 
Address how cooperative binding contributes to SSB function during D.pdf
Address how cooperative binding contributes to SSB function during D.pdfAddress how cooperative binding contributes to SSB function during D.pdf
Address how cooperative binding contributes to SSB function during D.pdf
 
A perfect left-sided binary tree is a binary tree where every intern.pdf
A perfect left-sided binary tree is a binary tree where every intern.pdfA perfect left-sided binary tree is a binary tree where every intern.pdf
A perfect left-sided binary tree is a binary tree where every intern.pdf
 
Assembly Code Pep8 Question Write a Pep8 subroutine that is equiva.pdf
Assembly Code Pep8 Question Write a Pep8 subroutine that is equiva.pdfAssembly Code Pep8 Question Write a Pep8 subroutine that is equiva.pdf
Assembly Code Pep8 Question Write a Pep8 subroutine that is equiva.pdf
 
why might bacteria need to alter gene expression when their environm.pdf
why might bacteria need to alter gene expression when their environm.pdfwhy might bacteria need to alter gene expression when their environm.pdf
why might bacteria need to alter gene expression when their environm.pdf
 
Which of the three principles from the Belmont Report were violated .pdf
Which of the three principles from the Belmont Report were violated .pdfWhich of the three principles from the Belmont Report were violated .pdf
Which of the three principles from the Belmont Report were violated .pdf
 
Where is the cell body of the neuron that directly causes SA node ce.pdf
Where is the cell body of the neuron that directly causes SA node ce.pdfWhere is the cell body of the neuron that directly causes SA node ce.pdf
Where is the cell body of the neuron that directly causes SA node ce.pdf
 
Which of the following is FALSE regarding phylogenetic inference met.pdf
Which of the following is FALSE regarding phylogenetic inference met.pdfWhich of the following is FALSE regarding phylogenetic inference met.pdf
Which of the following is FALSE regarding phylogenetic inference met.pdf
 
What is the critical F value for a sample of four observations in th.pdf
What is the critical F value for a sample of four observations in th.pdfWhat is the critical F value for a sample of four observations in th.pdf
What is the critical F value for a sample of four observations in th.pdf
 
what is the main function and sub-functions of a penSolutions.pdf
what is the main function and sub-functions of a penSolutions.pdfwhat is the main function and sub-functions of a penSolutions.pdf
what is the main function and sub-functions of a penSolutions.pdf
 
what are some barriers a company might need to overcome when enterin.pdf
what are some barriers a company might need to overcome when enterin.pdfwhat are some barriers a company might need to overcome when enterin.pdf
what are some barriers a company might need to overcome when enterin.pdf
 
True or False1 The highest abundance of microbial life in soils .pdf
True or False1 The highest abundance of microbial life in soils .pdfTrue or False1 The highest abundance of microbial life in soils .pdf
True or False1 The highest abundance of microbial life in soils .pdf
 

Recently uploaded

會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
中 央社
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
AnaAcapella
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
CaitlinCummins3
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
EADTU
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
中 央社
 

Recently uploaded (20)

Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
The Liver & Gallbladder (Anatomy & Physiology).pptx
The Liver &  Gallbladder (Anatomy & Physiology).pptxThe Liver &  Gallbladder (Anatomy & Physiology).pptx
The Liver & Gallbladder (Anatomy & Physiology).pptx
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 

can you help me to solve this. Design a Person class similar to the .pdf

  • 1. can you help me to solve this. Design a Person class similar to the Coin class defined in this chapter. Then design and implement a driver class called SelectPerson whose main method creates two Person objects, then randomly selects a gender in both to see in which object a female gender is selected two times in a row. Consider the possibility that they might tie. Print the results of each selection and then print the object name which comes up first with the female gender being selected twice, consecutively Solution public class SelectPerson{ public static void main(String []args){ //create two person objects Person p1=new Person(); Person p2=new Person(); //delcare variable to set intiial values int count1=0,count2=0,counter=0; //loop until two consequetive femailes aren't listed while(count1<2 && count2<2) { counter++; p1.setGender(); p2.setGender(); //display selection of eahc round System.out.println("*******Round "+counter+"*****"); System.out.println("Object1 = Gender :"+p1); System.out.println("Object2 = Gender :"+p2); //check for female occurance if(p1.isFemale()) { count1++; } if(p2.isFemale()) { count2++;
  • 2. } } //display the results if(count1==count2) System.out.println("Tie"); else if(count1==2) System.out.println("p1"); else if(count2==2) System.out.println("p2"); } } //definitin of Person class class Person { //variable to hold gender private int gender; //dynamiclaly set gender public void setGender() { gender=(int)(Math.random()*2); } //check if gender is female public boolean isFemale() { return (gender==1); } //return gender of person object public String toString() { String genderName; if(gender==0) genderName="Male";