1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
pantera1 [17]
3 years ago
13

[Java] Using the comparable interface

Computers and Technology
1 answer:
nadezda [96]3 years ago
7 0

Answer:

Check the explanation

Explanation:

public class Person implements Comparable<Person> {

   private String name;

   public Person(String name) {

       this.name = name;

   }

   public String getName() {

       return name;

   }

   public void setName(String name) {

       this. name = name;

   }

   Override

   public int compareTo(Person o) {

       return name.compareTo(o.name);

   }

}

Person 1 ester..) aua .

import java.util.Scanner;

public class PersonTester {

   public static void main(String[] args) {

       Scanner in = new Scanner(System.in);

       Person[] people = new Person[10];

       for (int i = 0; i < people.length; i++) {

           System.out.print("Enter name of person " + (i+1) + ": ");

           people[i] = new Person(in.nextLine());

       }

       Person first = people[0], last = people[0];

       for (int i = 0; i < people.length; i++) {

           if (people[i].compareTo(first) < 0) first = people[i];

           if (people[i].compareTo(last) > 0) last = people[i];

       }

       System.out.println("First person is " + first.getName());

       System.out.println("Last person is " + last.getName());

       in.close();

   }

}

You might be interested in
What is the main advantage of using DHCP? A. Allows you to manually set IP addresses B. Allows usage of static IP addresses C. L
Marat540 [252]

Answer: DHCP (dynamic host configuration protocol)  is a protocol which automatically processes the configuring devices on IP networks.It allows them to to use network services like: NTP and any communication proto cal based on UDP or TCP. DHCP assigns an IP adress and other network configuration parameters to each device on a network so they can communicate with  other IP networks. it is a part of DDI solution.

 

Explanation:

7 0
4 years ago
Which devices are managed through device management?
mr_godi [17]
Android<span>, </span>iOS<span>, Windows and </span>Blackberry<span> devices.</span>
3 0
4 years ago
What is one advantage of inserting a page number field in your document instead of inserting the actual page number?
Tanzania [10]

It is faster and saves time

3 0
3 years ago
List 90 examples of word
Bingel [31]
Word can be a word or a pdf or what
4 0
2 years ago
g If a class named Student has a data member named gpa , and one of its member functions has a parameter also named gpa , how ca
victus00 [196]

Answer:

By using the this keyword

Explanation:

The this keyword in java is used for pointing the current object or current variable .The this keyword is removing the ambiguity among the characteristics of the class as well as the variables with the similar name.

In the given question if the class student has member variable gpa also we have a method having the argument gpa with the help of this keyword we can refer the gpa variable inside the method .

Following are the implementation of the given question

public class Main // main class

{

 int gpa; // variable declaration

 public Main(int gpa) // constructor

 {

   this.gpa = gpa; // this keyword

 }

 public static void main(String[] args) // Main method

 {

   Main m= new Main(55); // creating object of class

   System.out.println("The Value of gpa is : " + m.gpa); // display value

 }

}

Output:

The Value of gpa is :55

5 0
4 years ago
Other questions:
  • Type of media that uses laser technology to store data and programs is
    6·1 answer
  • A virus or worm can have a payload that installs a(n) __________ door or trap-door component in a system, which allows the attac
    14·2 answers
  • The partners of a small architectural firm are constantly busy with evolving client requirements. To meet the needs of their cli
    11·1 answer
  • A virus enters a computer or network _____.
    13·1 answer
  • What is the most common concern with using variable frequency drives?
    6·1 answer
  • In c++
    12·1 answer
  • Which kind of results will appear using the search query "Frosty the Snowman" in quotation marks?
    6·1 answer
  • Wow, in this century, technology have been the most valuable. What is the worst of using the hi-tech phones
    13·2 answers
  • Lester has to create an app that can support offline data and rich media content such as audio and video. In which programming l
    15·1 answer
  • Common separators or delimiters used when converting a table to text include _______________________ , paragraph marks, or comma
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!