SlideShare a Scribd company logo
1 of 2
Download to read offline
First, create a class called Person that implements the Comparable interface. Person will contain
a member variable to hold a name, a constructor that sets up the name, and three methods
(getName, compareTo, toString). getName returns the member variable, compareTo works as
defined by the Comparable interface, and toString returns the name neatly formatted. Second,
you'll compare Persons by their names. Include a main method in Person that asks the user to
input ten names and generates ten Person objects. A blank name should not be used to create an
object. Using the compareTo method, determine first and last person among them and print
them. Do not simply sort the Person data.
Solution
Person.java
import java.util.Scanner;
public class Person implements Comparable
{
private String name;
public Person(){
}
public Person(String name)
{this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String toString()
{
return "Name: " + name ;
}
public int compareTo(Person p)
{
return getName().compareTo(p.getName());
}
public static void main(String a[]){
Scanner scan = new Scanner(System.in);
Person p[] = new Person[10];
System.out.println("Enter 10 persons names: ");
for(int i=0; i

More Related Content

Similar to First, create a class called Person that implements the Comparable i.pdf

Cis407 a ilab 4 web application development devry university
Cis407 a ilab 4 web application development devry universityCis407 a ilab 4 web application development devry university
Cis407 a ilab 4 web application development devry universitylhkslkdh89009
 
Simple class and object examples in java
Simple class and object examples in javaSimple class and object examples in java
Simple class and object examples in javaHarish Gyanani
 
Building .NET-based Applications with C#
Building .NET-based Applications with C#Building .NET-based Applications with C#
Building .NET-based Applications with C#Umar Farooq
 
3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf
3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf
3. Section 3 � Complete functionality on listing screen (1.5 marks.pdfalliedscorporation
 
Dependency Injection in Spring
Dependency Injection in SpringDependency Injection in Spring
Dependency Injection in SpringASG
 
This is the official tutorial from Oracle.httpdocs.oracle.comj.pdf
This is the official tutorial from Oracle.httpdocs.oracle.comj.pdfThis is the official tutorial from Oracle.httpdocs.oracle.comj.pdf
This is the official tutorial from Oracle.httpdocs.oracle.comj.pdfjillisacebi75827
 
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdfLabprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdffreddysarabia1
 
2. Section 2. Implementing functionality in the PersonEntry. (1.5 ma.pdf
2. Section 2. Implementing functionality in the PersonEntry. (1.5 ma.pdf2. Section 2. Implementing functionality in the PersonEntry. (1.5 ma.pdf
2. Section 2. Implementing functionality in the PersonEntry. (1.5 ma.pdfallwayscollection
 
Lecture 4_Java Method-constructor_imp_keywords
Lecture   4_Java Method-constructor_imp_keywordsLecture   4_Java Method-constructor_imp_keywords
Lecture 4_Java Method-constructor_imp_keywordsmanish kumar
 
Python unit 3 m.sc cs
Python unit 3 m.sc csPython unit 3 m.sc cs
Python unit 3 m.sc csKALAISELVI P
 
define a class name Employee whose objects are records for employee..pdf
define a class name Employee whose objects are records for employee..pdfdefine a class name Employee whose objects are records for employee..pdf
define a class name Employee whose objects are records for employee..pdffashioncollection2
 
Having a problem figuring out where my errors are- The code is not run.pdf
Having a problem figuring out where my errors are- The code is not run.pdfHaving a problem figuring out where my errors are- The code is not run.pdf
Having a problem figuring out where my errors are- The code is not run.pdfNicholasflqStewartl
 
Preexisting code, please useMain.javapublic class Main { p.pdf
Preexisting code, please useMain.javapublic class Main {    p.pdfPreexisting code, please useMain.javapublic class Main {    p.pdf
Preexisting code, please useMain.javapublic class Main { p.pdfrd1742
 

Similar to First, create a class called Person that implements the Comparable i.pdf (18)

Cis407 a ilab 4 web application development devry university
Cis407 a ilab 4 web application development devry universityCis407 a ilab 4 web application development devry university
Cis407 a ilab 4 web application development devry university
 
Simple class and object examples in java
Simple class and object examples in javaSimple class and object examples in java
Simple class and object examples in java
 
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#
 
3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf
3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf
3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf
 
Dependency Injection in Spring
Dependency Injection in SpringDependency Injection in Spring
Dependency Injection in Spring
 
This is the official tutorial from Oracle.httpdocs.oracle.comj.pdf
This is the official tutorial from Oracle.httpdocs.oracle.comj.pdfThis is the official tutorial from Oracle.httpdocs.oracle.comj.pdf
This is the official tutorial from Oracle.httpdocs.oracle.comj.pdf
 
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdfLabprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
 
2. Section 2. Implementing functionality in the PersonEntry. (1.5 ma.pdf
2. Section 2. Implementing functionality in the PersonEntry. (1.5 ma.pdf2. Section 2. Implementing functionality in the PersonEntry. (1.5 ma.pdf
2. Section 2. Implementing functionality in the PersonEntry. (1.5 ma.pdf
 
Lecture 4_Java Method-constructor_imp_keywords
Lecture   4_Java Method-constructor_imp_keywordsLecture   4_Java Method-constructor_imp_keywords
Lecture 4_Java Method-constructor_imp_keywords
 
Python unit 3 m.sc cs
Python unit 3 m.sc csPython unit 3 m.sc cs
Python unit 3 m.sc cs
 
define a class name Employee whose objects are records for employee..pdf
define a class name Employee whose objects are records for employee..pdfdefine a class name Employee whose objects are records for employee..pdf
define a class name Employee whose objects are records for employee..pdf
 
Ch-2ppt.pptx
Ch-2ppt.pptxCh-2ppt.pptx
Ch-2ppt.pptx
 
Having a problem figuring out where my errors are- The code is not run.pdf
Having a problem figuring out where my errors are- The code is not run.pdfHaving a problem figuring out where my errors are- The code is not run.pdf
Having a problem figuring out where my errors are- The code is not run.pdf
 
Preexisting code, please useMain.javapublic class Main { p.pdf
Preexisting code, please useMain.javapublic class Main {    p.pdfPreexisting code, please useMain.javapublic class Main {    p.pdf
Preexisting code, please useMain.javapublic class Main { p.pdf
 
Spsl vi unit final
Spsl vi unit finalSpsl vi unit final
Spsl vi unit final
 
Spsl v unit - final
Spsl v unit - finalSpsl v unit - final
Spsl v unit - final
 
java
javajava
java
 

More from manjan6

An introduction and explanation of human factors and sociotechnical .pdf
An introduction and explanation of human factors and sociotechnical .pdfAn introduction and explanation of human factors and sociotechnical .pdf
An introduction and explanation of human factors and sociotechnical .pdfmanjan6
 
Astronomers were able to find a new planet in a far away solar system.pdf
Astronomers were able to find a new planet in a far away solar system.pdfAstronomers were able to find a new planet in a far away solar system.pdf
Astronomers were able to find a new planet in a far away solar system.pdfmanjan6
 
5. If we found AB+ blood at a crime scene and we knew one of our 5 s.pdf
5. If we found AB+ blood at a crime scene and we knew one of our 5 s.pdf5. If we found AB+ blood at a crime scene and we knew one of our 5 s.pdf
5. If we found AB+ blood at a crime scene and we knew one of our 5 s.pdfmanjan6
 
All of the following individuals are U.S. residents Kelly (27.pdf
All of the following individuals are U.S. residents Kelly (27.pdfAll of the following individuals are U.S. residents Kelly (27.pdf
All of the following individuals are U.S. residents Kelly (27.pdfmanjan6
 
Blossom Company had these transactions during the current period..pdf
Blossom Company had these transactions during the current period..pdfBlossom Company had these transactions during the current period..pdf
Blossom Company had these transactions during the current period..pdfmanjan6
 
Using the case study below, develop a written report of your market .pdf
Using the case study below, develop a written report of your market .pdfUsing the case study below, develop a written report of your market .pdf
Using the case study below, develop a written report of your market .pdfmanjan6
 
Which of the following is NOT a characteristic of a plasmid used as .pdf
Which of the following is NOT a characteristic of a plasmid used as .pdfWhich of the following is NOT a characteristic of a plasmid used as .pdf
Which of the following is NOT a characteristic of a plasmid used as .pdfmanjan6
 
What is the evolutionary significance of the amniotic egg Solut.pdf
What is the evolutionary significance of the amniotic egg  Solut.pdfWhat is the evolutionary significance of the amniotic egg  Solut.pdf
What is the evolutionary significance of the amniotic egg Solut.pdfmanjan6
 
What is the role of HTTP What types of objects are transmitted in H.pdf
What is the role of HTTP What types of objects are transmitted in H.pdfWhat is the role of HTTP What types of objects are transmitted in H.pdf
What is the role of HTTP What types of objects are transmitted in H.pdfmanjan6
 
What is the difference between a hash in perl and a hashtable in Jav.pdf
What is the difference between a hash in perl and a hashtable in Jav.pdfWhat is the difference between a hash in perl and a hashtable in Jav.pdf
What is the difference between a hash in perl and a hashtable in Jav.pdfmanjan6
 
What are the specific linkages among immune surveillance, clonal sel.pdf
What are the specific linkages among immune surveillance, clonal sel.pdfWhat are the specific linkages among immune surveillance, clonal sel.pdf
What are the specific linkages among immune surveillance, clonal sel.pdfmanjan6
 
True or False –Paraeducators provide direct or indirect instructio.pdf
True or False –Paraeducators provide direct or indirect instructio.pdfTrue or False –Paraeducators provide direct or indirect instructio.pdf
True or False –Paraeducators provide direct or indirect instructio.pdfmanjan6
 
The situation where the few who yell the loudest get heard Is ref.pdf
The situation where the few who yell the loudest get heard Is ref.pdfThe situation where the few who yell the loudest get heard Is ref.pdf
The situation where the few who yell the loudest get heard Is ref.pdfmanjan6
 
Templated Binary Tree implementing function help I need to im.pdf
Templated Binary Tree implementing function help I need to im.pdfTemplated Binary Tree implementing function help I need to im.pdf
Templated Binary Tree implementing function help I need to im.pdfmanjan6
 
State if you agree or disagree with the question and comments made b.pdf
State if you agree or disagree with the question and comments made b.pdfState if you agree or disagree with the question and comments made b.pdf
State if you agree or disagree with the question and comments made b.pdfmanjan6
 
A number of benefits that one might expect to see from using a datab.pdf
A number of benefits that one might expect to see from using a datab.pdfA number of benefits that one might expect to see from using a datab.pdf
A number of benefits that one might expect to see from using a datab.pdfmanjan6
 
QUESTION If you look at the code, youll see that we keep two list.pdf
QUESTION If you look at the code, youll see that we keep two list.pdfQUESTION If you look at the code, youll see that we keep two list.pdf
QUESTION If you look at the code, youll see that we keep two list.pdfmanjan6
 
Question 11 What is the volume of 17.0 grams of carbon dioxide gas if.pdf
Question 11 What is the volume of 17.0 grams of carbon dioxide gas if.pdfQuestion 11 What is the volume of 17.0 grams of carbon dioxide gas if.pdf
Question 11 What is the volume of 17.0 grams of carbon dioxide gas if.pdfmanjan6
 
Please help with this. program must be written in C# .. All of the g.pdf
Please help with this. program must be written in C# .. All of the g.pdfPlease help with this. program must be written in C# .. All of the g.pdf
Please help with this. program must be written in C# .. All of the g.pdfmanjan6
 
Match the enzyme activity in DNA synthesis with its function. DNA po.pdf
Match the enzyme activity in DNA synthesis with its function.  DNA po.pdfMatch the enzyme activity in DNA synthesis with its function.  DNA po.pdf
Match the enzyme activity in DNA synthesis with its function. DNA po.pdfmanjan6
 

More from manjan6 (20)

An introduction and explanation of human factors and sociotechnical .pdf
An introduction and explanation of human factors and sociotechnical .pdfAn introduction and explanation of human factors and sociotechnical .pdf
An introduction and explanation of human factors and sociotechnical .pdf
 
Astronomers were able to find a new planet in a far away solar system.pdf
Astronomers were able to find a new planet in a far away solar system.pdfAstronomers were able to find a new planet in a far away solar system.pdf
Astronomers were able to find a new planet in a far away solar system.pdf
 
5. If we found AB+ blood at a crime scene and we knew one of our 5 s.pdf
5. If we found AB+ blood at a crime scene and we knew one of our 5 s.pdf5. If we found AB+ blood at a crime scene and we knew one of our 5 s.pdf
5. If we found AB+ blood at a crime scene and we knew one of our 5 s.pdf
 
All of the following individuals are U.S. residents Kelly (27.pdf
All of the following individuals are U.S. residents Kelly (27.pdfAll of the following individuals are U.S. residents Kelly (27.pdf
All of the following individuals are U.S. residents Kelly (27.pdf
 
Blossom Company had these transactions during the current period..pdf
Blossom Company had these transactions during the current period..pdfBlossom Company had these transactions during the current period..pdf
Blossom Company had these transactions during the current period..pdf
 
Using the case study below, develop a written report of your market .pdf
Using the case study below, develop a written report of your market .pdfUsing the case study below, develop a written report of your market .pdf
Using the case study below, develop a written report of your market .pdf
 
Which of the following is NOT a characteristic of a plasmid used as .pdf
Which of the following is NOT a characteristic of a plasmid used as .pdfWhich of the following is NOT a characteristic of a plasmid used as .pdf
Which of the following is NOT a characteristic of a plasmid used as .pdf
 
What is the evolutionary significance of the amniotic egg Solut.pdf
What is the evolutionary significance of the amniotic egg  Solut.pdfWhat is the evolutionary significance of the amniotic egg  Solut.pdf
What is the evolutionary significance of the amniotic egg Solut.pdf
 
What is the role of HTTP What types of objects are transmitted in H.pdf
What is the role of HTTP What types of objects are transmitted in H.pdfWhat is the role of HTTP What types of objects are transmitted in H.pdf
What is the role of HTTP What types of objects are transmitted in H.pdf
 
What is the difference between a hash in perl and a hashtable in Jav.pdf
What is the difference between a hash in perl and a hashtable in Jav.pdfWhat is the difference between a hash in perl and a hashtable in Jav.pdf
What is the difference between a hash in perl and a hashtable in Jav.pdf
 
What are the specific linkages among immune surveillance, clonal sel.pdf
What are the specific linkages among immune surveillance, clonal sel.pdfWhat are the specific linkages among immune surveillance, clonal sel.pdf
What are the specific linkages among immune surveillance, clonal sel.pdf
 
True or False –Paraeducators provide direct or indirect instructio.pdf
True or False –Paraeducators provide direct or indirect instructio.pdfTrue or False –Paraeducators provide direct or indirect instructio.pdf
True or False –Paraeducators provide direct or indirect instructio.pdf
 
The situation where the few who yell the loudest get heard Is ref.pdf
The situation where the few who yell the loudest get heard Is ref.pdfThe situation where the few who yell the loudest get heard Is ref.pdf
The situation where the few who yell the loudest get heard Is ref.pdf
 
Templated Binary Tree implementing function help I need to im.pdf
Templated Binary Tree implementing function help I need to im.pdfTemplated Binary Tree implementing function help I need to im.pdf
Templated Binary Tree implementing function help I need to im.pdf
 
State if you agree or disagree with the question and comments made b.pdf
State if you agree or disagree with the question and comments made b.pdfState if you agree or disagree with the question and comments made b.pdf
State if you agree or disagree with the question and comments made b.pdf
 
A number of benefits that one might expect to see from using a datab.pdf
A number of benefits that one might expect to see from using a datab.pdfA number of benefits that one might expect to see from using a datab.pdf
A number of benefits that one might expect to see from using a datab.pdf
 
QUESTION If you look at the code, youll see that we keep two list.pdf
QUESTION If you look at the code, youll see that we keep two list.pdfQUESTION If you look at the code, youll see that we keep two list.pdf
QUESTION If you look at the code, youll see that we keep two list.pdf
 
Question 11 What is the volume of 17.0 grams of carbon dioxide gas if.pdf
Question 11 What is the volume of 17.0 grams of carbon dioxide gas if.pdfQuestion 11 What is the volume of 17.0 grams of carbon dioxide gas if.pdf
Question 11 What is the volume of 17.0 grams of carbon dioxide gas if.pdf
 
Please help with this. program must be written in C# .. All of the g.pdf
Please help with this. program must be written in C# .. All of the g.pdfPlease help with this. program must be written in C# .. All of the g.pdf
Please help with this. program must be written in C# .. All of the g.pdf
 
Match the enzyme activity in DNA synthesis with its function. DNA po.pdf
Match the enzyme activity in DNA synthesis with its function.  DNA po.pdfMatch the enzyme activity in DNA synthesis with its function.  DNA po.pdf
Match the enzyme activity in DNA synthesis with its function. DNA po.pdf
 

Recently uploaded

Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesShubhangi Sonawane
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 

Recently uploaded (20)

Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 

First, create a class called Person that implements the Comparable i.pdf

  • 1. First, create a class called Person that implements the Comparable interface. Person will contain a member variable to hold a name, a constructor that sets up the name, and three methods (getName, compareTo, toString). getName returns the member variable, compareTo works as defined by the Comparable interface, and toString returns the name neatly formatted. Second, you'll compare Persons by their names. Include a main method in Person that asks the user to input ten names and generates ten Person objects. A blank name should not be used to create an object. Using the compareTo method, determine first and last person among them and print them. Do not simply sort the Person data. Solution Person.java import java.util.Scanner; public class Person implements Comparable { private String name; public Person(){ } public Person(String name) {this.name = name; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String toString() {
  • 2. return "Name: " + name ; } public int compareTo(Person p) { return getName().compareTo(p.getName()); } public static void main(String a[]){ Scanner scan = new Scanner(System.in); Person p[] = new Person[10]; System.out.println("Enter 10 persons names: "); for(int i=0; i