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

Create an application that can use Singly Linked List with java The Candidate da

ID: 3738827 • Letter: C

Question

Create an application that can use Singly Linked List with java

The Candidate data will keep the save information

For Singly Linked List and do the following tasks, until users want to exit

-INSERT: Allow users to insert Candidate or Candidate with experience until users want to stop. For each Candidate or Candidate with experience: display message to ask users to enter all the information that needs to create an object then insert it to the Singly Linked List. When users finish inserting all nodes, display all the Singly Linked list to verify all are inserted

-FETCH: allow users to enter the id to look for the Candidate or Candidate with experience. If the Linked List is empty, display the message: “There is no node in the Singly Linked List” If the Candidate cannot be found, display the message: “ID 12345 cannot be found” where 12345 is the target key to look for the Candidate If the it is found, display the information of the Candidate or Candidate experience

-UPDATE: allow users to enter the id of the Candidate that they want to update Ask for new information, it could be address or salary; then set the new change to the node Update the new node to the Singly Linked List then fetch it to verify the change If the Linked List is empty, display the message: “There is no node in the Singly Linked List” If the Candidate cannot be found, display the message: “ID 12345 cannot be found” where 12345 is the target key to look for the Candidate

-DELETE: allow users to enter the id of the Candidate that they want to delete Delete the Candidate with the id. Fetch with the same id to verify the Candidate is deleted If the Linked List is empty, display the message: “There is no node in the Singly Linked List” If the Candidate cannot be found, display the message: “ID 12345 cannot be found” where 12345 is the target key to look for the Candidate

-SHOW ALL: show all nodes in the linked list

Explanation / Answer

import java.io.*;

import java.util.Scanner;

class linkedlist {

int CandidateId;

int salary;

String name;

linkedlist next;

linkedlist(int value,int salary,String name) {

this.CandidateId = value;

this.salary=salary;

this.name=name;

}

void display() {

System.out.println(CandidateId+" "+salary+" "+name);

}

}

class linked {

public linkedlist fstnode, lastnode;

linked() {

fstnode = null;

lastnode = null;

}

/* Insert node or create linked list */

void insertnode(int value,int salary,String name) {

linkedlist node = new linkedlist(value,salary,name);

node.next = null;

if(fstnode == null) {

fstnode = lastnode = node;

System.out.println("Linked list created successfully!");

}

else {

lastnode.next = node;

lastnode = node;

System.out.println("Node inserted successfully!");

}

}

/* Delete node from linked list */

void delete() {

int count = 0, number, i;

linkedlist node, node1;

Scanner input = new Scanner(System.in);

for(node = fstnode; node != null; node = node.next)

count++;

display();

node = node1 = fstnode;

System.out.println(count+" nodes available here!");

System.out.println("Enter the node number which you want to delete:");

number = Integer.parseInt(input.nextLine());

if(number != 1) {

if(number <= count) {

for(i = 2; i <= number; i++)

node = node.next;

for(i = 2; i <= number-1; i++)

node1 = node1.next;

node1.next = node.next;

node.next = null;

node = null;

}

else

System.out.println("Invalid node number! ");

}

else {

fstnode = node.next;

node = null;

}

System.out.println("Node has been deleted successfully! ");

}

/* Display linked list */

void display() {

linkedlist node = fstnode;

System.out.println("List of node:");

while(node != null) {

node.display();

node = node.next;

}

}

}

class Link {

public static void main(String args[ ]) {

linked list = new linked();

Scanner input = new Scanner(System.in);

int op = 0;

while(op != 4) {

System.out.println("1. Insert 2. Delete 3. Show All 4. Exit");

System.out.println("Enter your choice:");

op = Integer.parseInt(input.nextLine());

switch(op) {

case 1:

System.out.print("Enter the candidate id :");

int id=Integer.parseInt(input.nextLine());

System.out.print("Enter the candidate salary :");

int salary=Integer.parseInt(input.nextLine());

System.out.print("Enter the candidate name :");

String name=input.nextLine();

list.insertnode(id,salary,name);

break;

case 2:

list.delete();

break;

case 3:

list.display();

break;

case 4:

System.out.println("Bye Bye!");

System.exit(0);

break;

default:

System.out.println("Invalid choice!");

}

}

}

}

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