Answer to Question #289199 in Java | JSP | JSF for Jak

Question #289199

Implement an application (a system) of any abstract data type (stack, queue,


tree, graph, hashing) using Java as programming


language. Some of the examples are the following:


• Dictionary implementation using AVL Tree


• Log-book for Task Monitoring


• Queuing System for Clinics

1
Expert's answer
2022-01-21T01:45:44-0500
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Queue<String> queue = new LinkedList<>();
        Scanner in = new Scanner(System.in);
        while (true) {
            System.out.println("1. Add a patient to the queue.");
            System.out.println("2. Remove a patient from the queue.");
            System.out.println("0. Exit.");
            switch (in.nextLine()) {
                case "1":
                    System.out.println("Enter the patient's name: ");
                    queue.offer(in.nextLine());
                    break;
                case "2":
                    if (queue.isEmpty()) {
                        System.out.println("The queue is empty.");
                    } else {
                        System.out.println("Patient: " + queue.poll());
                    }
                    break;
                case "0":
                    System.exit(0);
            }
        }
    }
}

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