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]
2 years ago
13

[Java] Using the comparable interface

Computers and Technology
1 answer:
nadezda [96]2 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
You have to write a program that will read a number followed by a series of bit operations from a file and perform the given ope
tatuchka [14]

The program what will read a number followed by a series of bit operations from file and perform the given operations sequentially on the number is given below.

<h3>What is an operation in computer science?</h3>

An operation, in mathematics and computer programming, is an action that is carried out to accomplish a given task.

There are five basic types of computer operations:

  • Inputting,
  • processing,
  • outputting,
  • storing, and
  • controlling.

<h3>What is the requested program above?</h3>

#include <stdio.h>

#include <fcntl.h>

int main(int argc, char *argv[])

{

  int number, n, v, temp;

  char line[25], fun[10];

  FILE *f = fopen(argv[1], "r");

 

  fgets(line, 24, f);

  sscanf(line, "%d", &number);   //reading the number

  while( fgets(line, 24, f) )

   {

      sscanf(line, "%s %d %d", fun, &n, &v); //reading the commands

      switch(fun[0])           //checking which command to run

      {

          case 'g':    temp = 1;

                      temp = temp<<n;   //shifting for getting that bit

                      printf("%d\n",(number&temp)&&1);

                      break;

          case 's':   temp = 1;

                      temp = temp<<n;   //shifting for setting that bit

                      if(!v)

                      {

                          temp = ~temp;

                          number = number & temp;

                      }

                      else

                      {

                          number = number | temp;

                      }

                      printf("%d\n",number);

                      break;

          case 'c':   temp = 1;

                      temp = temp<<n;   //shifting for complimenting that bit

                      number = number ^ temp;   //xor to complement that bit

                      printf("%d\n",number);

                      break;

          default:printf("not defined");

      }

  }

  return 0;

}

Execution and Output:

terminal-> $ gcc -o first first.c

terminal-> $ ./first file1.txt

1

4

6

Learn more about programs at;
brainly.com/question/16397886
#SPJ1

8 0
1 year ago
When the _____ logical operator is used to combine keywords, a search engine will retrieve all results containing either keyword
DanielleElmas [232]
OR! Because one OR the other (or both, as this is not an exclusive or) needs to be present in the search result.
8 0
3 years ago
Read 2 more answers
How do I change the year I was born on this website? I made a mistake and now I can't fix it. Can somebody please help me?
Eddi Din [679]

Answer:

you can go to settings and try to fix it or contact the people of this website

Explanation:

8 0
3 years ago
30 POINTS FOT THE ANSWER FAST
sasho [114]

The industry I chose is the fashion industry and how web design has made an impact on that industry are:

  • It often impact the visual style of cloths.
  • It has helped in making of nice and good cloth design.
  • It aid in design and visual effect of its product.

<h3>What is the impact of web design?</h3>

Web design is known to be a key  parts of Internet marketing strategy as it helps in digital customer experience in a lot of ways.

The skill needed are:

  • Visual design
  • The use of Design software.
  • HTML.
  • JavaScript, etc.

Therefore, The industry I chose is the fashion industry and how web design has made an impact on that industry are:

  • It often impact the visual style of cloths.
  • It has helped in making of nice and good cloth design.
  • It aid in design and visual effect of its product.

Learn more about  fashion industry  from

brainly.com/question/27318787

#SPJ1

4 0
2 years ago
I think i have a virus on my computer what am i supposed to do
patriot [66]

Answer:

call like a phone or computer company and ask wjat thry can do

4 0
3 years ago
Other questions:
  • Libby wrote an email to her friend. She pressed Shift and the number key 2 together to enter the email address. Which symbol did
    7·2 answers
  • Will somebody help me???? ANYBODY?? PLZZZZZZZZZZZZ
    8·1 answer
  • Maria is comparing her history project's second-place award to her classmate's first-place award. She starts planning how to win
    6·2 answers
  • Which of the following attacks seeks to introduce erroneous or malicious entries into a server's hostname-to-IP address cache or
    5·1 answer
  • Peter works on a huge database of numerical figures in a worksheet ranging from cell A1 to cell I50. He has to print the workshe
    15·2 answers
  • What is the main difference between a search engine and a web browser?
    6·2 answers
  • Your network has four Hyper-V hosts, which are running three domain controllers and about 10 member servers. Three of the member
    10·1 answer
  • Explain where the “heart” of the station is and what can be found there? I will mark brainlyest! This is for the ISS (Internatio
    15·2 answers
  • When patel’s advertising co. decided to upgrade its computer network, many people were involved in the decision. In b2b buying s
    8·1 answer
  • What component of a change management program includes final testing that the software functions properly
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!