Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write in java the driver class including (main method) implementing three classe

ID: 3600504 • Letter: W

Question

Write in java the driver class including (main method) implementing three classes below.

Don't build the three classes below IF there is no need to. I just want the driver class with main method

a.Type 1 is a singly-linked list, no tail reference, non-circular, containing Integers.

b.Type 2 is a doubly-linked list with a tail reference, non-circular, containing Doubles.

c.Type 3 is a singly-linked circular list, your choice of a tail reference or not, (whichever will favor the operations) containing Strings. State in your cover letter whether you are using a tail reference and why you decided to go that way (it should be related to its usefulness for the operations).

The driver class (containing the main method) will handle user input. It will have three variables (objects), one for each list type.

Input will be from a user. You may assume a perfect user (i.e., you don’t need to handle any errors). They will make menu choices (ints) and enter list data.

Output will be the current list (possibly changed by an operation) and, sometimes, messages (the result of an operation; for example, checking whether the list is sorted, or an error if they ask to insert in a non-ordered list).

The program will allow a user to, first, choose which of the three types of list to use, then, second, what operation they wish to run on one of those lists. Use simple text output for displaying the menus and getting user input.

Also here is the general list operations. All lists will provide the following operations:

a.build the list (allow any list size) from user input, in the order the data is entered

b.print the list, showing the head (and possibly tail); all will look like they are singly linked, but will be annotated with the appropriate words:

            singly-linked, non-circular, tail:  

head > 17 > 23 >19 < tail   (singly-linked)

            doubly-linked, non-circular, no tail:   

head > 17 > 23 > 19 (doubly-linked)

            singly-linked, circularly-linked, no tail:

                        head > cat > dog > puppy (singly-linked, circular)

            empty lists:

                        head > null

                        head > null < tail

Explanation / Answer

import java.util.Scanner;

public class LinkedListDriver {

public static void main(String args[]) {

//scanner to read user input

Scanner sc = new Scanner(System.in);

// another scanner to read user integer input

Scanner sc1 = new Scanner(System.in);

//reading linked list preferable

System.out.println("Choose one of them...");

System.out.println(" 1. single linked list 2. double linked list 3.single linked circular list");

int listChoice = sc1.nextInt();

if(listChoice == 1) {

//creating single linked list

SingleLinkedList obj = new SingleLinkedList();

// reading integers from user

while(true){

System.out.print("Enter integer (-1 to stop): ");

int num = sc1.nextInt();

if(num == -1) {

break;

}

obj.push(num);

}

obj.printList();

}

else if(listChoice == 2) {

//creating double linked list

DoubleLinkedList obj = new DoubleLinkedList();

// reading doubles from user

while(true){

System.out.print("Enter double (-1 to stop): ");

double num = sc1.nextDouble();

if(num == -1) {

break;

}

obj.push(num);

}

obj.printList();

}

else {

//creating double linked list

//reading tail choice

System.out.println("Do you want to add tail to list: (true or false): ");

String tailRequired = sc.nextLine();

boolean tail = false;

if(tailRequired.equals("true"){

tail = true;

}

SingleCircularLinkedList obj = new SingleCircularLinkedList(tail);

// reading strings from user

while(true){

System.out.print("Enter string (-1 to stop): ");

String val = sc.nextLine();

if(val.equals("-1")){

break;

}

obj.push(val);

}

obj.printList();

}

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote