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 a mechanical gear and how does it work to create more power?
Neko [114]
Its a gear that is not turned manually and it can spin faster and longer than a manual gear.
5 0
3 years ago
A ____ is text and graphics that print at the top of each page
Volgvan
It would probably be the header.
3 0
3 years ago
In excel what happens when rename a sheet from sheet1 to inventory​
makvit [3.9K]

Answer:

Explanation:

The sheet name at the footer of the screen gets changed from sheet1 to inventory.

4 0
3 years ago
Write a class Example() such that it has a method that gives the difference between the size of strings when the '-' (subtractio
Mariulka [41]

Answer:

class Example:

def __init__(self, val):

self.val = val

def __gt__(self, other):

return self.val > other.val

def __sub__(self,other):

return abs(len(self.val) - len(other.val))

def main():

obj1 = Example('this is a string')

obj2 = Example('this is another one')

print(obj1 > obj2)

print(obj1 - obj2)

main()

\color{red}\underline{Output:}

3 0
3 years ago
A person upgrades their computer's processor. The processor is responsible for 80% of the system's computing effort. What is the
Ivan

Answer:A clock speed of 3.5 GHz to 4.0 GHz is generally considered a good clock speed for gaming but it's more important to have good single thread performance. This means that your CPU does a good job understanding and completing single tasks. This is not to be confused with having a single core processor

Explanation:

4 0
3 years ago
Other questions:
  • What is the Difference between CUI and GUI
    14·2 answers
  • What is the purpose of an internet protocol address (ip address)?
    5·1 answer
  • Does anyone know the code for codeHS 5.4.7 teenagers?
    8·1 answer
  • A(n) ________ moves over the spinning platters to retrieve data from the hard disk.
    6·1 answer
  • Write a while loop that prints
    13·1 answer
  • Which element appears within the top margin of the document but does not form the part of the body of the text?
    15·1 answer
  • Write a program that takes a first name as the input, and outputs a welcome message to that name.
    9·1 answer
  • Lee has changed the style of his table to make the header row stand out. Next, he wants to center the text in the header row and
    11·2 answers
  • Numerous engineering and scientific applications require finding solutions to a set of equations. Ex: 8x + 7y = 38 and 3x - 5y =
    15·1 answer
  • Which software package allows developers to deploy applications using the exact same environment in which they were developed?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!