Answer to Question #288115 in Java | JSP | JSF for John

Question #288115

1. Create a folder named LastName_FirstName on your local drive. (ex. Reyes_Mark)



2. Using NetBeans, create a Java project named Greeting. Set the project location to your own folder.



3. Import Scanner and PriorityQueue from the java.util package.



4. Create one (1) PriorityQueue object named nicknames.



5. The output shall do the following:



5.1. Ask the user to input the nicknames of four (4) of his/her classmates.



5.2. Ask the user to press H to say “Hi” to each of them.



5.3. Display Hi and the classmate’s nickname (Ex. Hi Nika!) whenever the user presses H, and



Done saying hi when the queue gets empty.




1
Expert's answer
2022-01-17T08:25:10-0500
import java.util.Scanner;
import java.util.PriorityQueue;

class Greeting {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        PriorityQueue<String> nicknames = new PriorityQueue<>();

        System.out.println("Enter four names of your classmates: ");
        for (int i = 0; i < 4; i++) {
            nicknames.add(scanner.nextLine());
        }

        System.out.println("Enter 'H' to say 'Hi' each of them!");
        while (!nicknames.isEmpty()) {
            scanner.nextLine();
            System.out.printf("Hi %s!\n", nicknames.poll());
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog