Question

team, create a Java program that adds or removes entries from a linked list based on user input. You can use the index of the entry as the key to identify the record for addition or deletion. The program can be as simple as you like but must add an entry to the list based on the user input and also must delete the proper item in the list based on the index entered by the user Display your list contents after each operation. Note: Please choose one of the following themes for your program Students/Classroom Sports Scores/Teams Passengers/Travel

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.LinkedList;

import java.util.Scanner;

public class StudentsList {

public static void main(String[] args) {

LinkedList<String> student = new LinkedList<>();

while(true){

System.out.println("1.Add Student to the List\n2.Remove Student from the list\n3.Display the list\n4.Exit");

Scanner sc=new Scanner(System.in);

System.out.print("Enter Your Choice :");

int choice=sc.nextInt();

switch(choice){

case 1:

//to adding in the list

System.out.println();

System.out.print("Enter Student ID to add in the list :");

String id=sc.next();

student.add(id);

System.out.println();

break;

case 2:

//to removie from the list

System.out.println();

System.out.println("Enter Student ID to remove from the list:");

id=sc.next();

student.remove(id);

System.out.println();

break;

case 3:

//to display the list

if(student.size()==0) System.out.println("\nList is Empty\n");

else{

System.out.println("\nStudent ID List");

for(String i:student) System.out.println(i);

System.out.println();

}

break;

case 4:

//to exit from the loop

System.out.println();

System.out.println("Thank You");

System.exit(0);

break;

default:

//other than this

System.out.println("Enter correct choice");

break;

}

}

}

}

1.Add Student to the List 2. Remove Student from the list 3.Display the list 4.Exit Enter Your Choice :1 Enter Student ID to add in the list n110046 1.Add Student to the List 2. Remove Student from the list 3.Display the list 4.Exit Enter Your Choice :1 Enter Student ID to add in the list :n110045 1.Add Student to the List 2. Remove Student from the list 3.Display the list 4.Exit Enter Your Choice :3 Student ID List n110046 n110045

Add a comment
Know the answer?
Add Answer to:
team, create a Java program that adds or removes entries from a linked list based on...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a java program implementing the Linked list. It should be on an small office who...

    Write a java program implementing the Linked list. It should be on an small office who has 5 employees. The program ask the user for ID, First name, Last name and what field the work in(eg: accounting, programmer, HR etc). Each employee (with all the information of that paticular employee) should be placed in one node in the program. The program should repeat and ask the user for all 5 employees information. Also when you display the Linked list it...

  • JAVA please Java problem that has to be in doubly linked list. It is game problem...

    JAVA please Java problem that has to be in doubly linked list. It is game problem that I have to keep of the players' scores. this should have a Java blueprint class named player   It should have two fields, the name and score and include the constructors, toString() method, and getters and setters. Scores must be kept in ascending order (smallest at the front ) in a doubly linked list. It has menu as well: Load original data Print the...

  • *Use Java to create this program* For this assignment, you will be building a Favorite Songs...

    *Use Java to create this program* For this assignment, you will be building a Favorite Songs application. The application should have a list with the items displayed, a textbox for adding new items to the list, and four buttons: Add, Remove, Load, and Save. The Add button takes the contents of the text field (textbox) and adds the item in it to the list. Your code must trim the whitespace in front of or at the end of the input...

  • Implement an application based on a singly linked list that maintains a list of the top...

    Implement an application based on a singly linked list that maintains a list of the top five performers in a video game. An entry on the list consists of a name and a score (you can make this into a blueprint class if you like), and the list must be maintained in descending order of scores. Here is an example of such a list when it only has three elements. ​Spike​120 ​Whiz​105 ​G-man​ 99 Use a class based on singly...

  • In JAVA, please. THANK YOU In this project you will create a generic linked list using...

    In JAVA, please. THANK YOU In this project you will create a generic linked list using Java Generics. Description: Create a generic class called GenLinkedList. GenLinkedList will use nodes that store a value of the generic type to store its contents. It should have the following methods. The methods should all operate on the object making the call (none are static). Perform checking of the parameters and throw exceptions where appropriate. The linked list should be singly-linked. It should not...

  • n JAVA, students will create a linked list structure that will be used to support a...

    n JAVA, students will create a linked list structure that will be used to support a role playing game. The linked list will represent the main character inventory. The setting is a main character archeologist that is traveling around the jungle in search of an ancient tomb. The user can add items in inventory by priority as they travel around (pickup, buy, find), drop items when their bag is full, and use items (eat, spend, use), view their inventory as...

  • Create a Java program application that creates an ArrayList that holds String objects. It needs to...

    Create a Java program application that creates an ArrayList that holds String objects. It needs to prompt the user to enter the names of friends, which are then put into the ArrayList; allow the user to keep adding names until they enter "q" to quit. After input is complete, display a numbered list of all friends in the list and prompt the user to enter the number of the friend they wish to delete. After deleting that entry, output the...

  • VISUAL BASIC- create a program for managing a "To Do" list. The program will need to...

    VISUAL BASIC- create a program for managing a "To Do" list. The program will need to read and update a text file named ToDoList.txt. The record structure of the file must be: 1) sort order, 2) task name and 3) desired completion date. When the program starts, it should read the contents file into a structure. The information should then be displayed in a data grid view. The data should be initially sorted by the sort order value. Afterwards, the...

  • Write a program that first gets a list of integers from the input and adds them...

    Write a program that first gets a list of integers from the input and adds them to an array. The input begins with an integer indicating the number of integers that follow (Your program should work for any size of the array). Then, get the last value from the input, and output all integers less than or equal to that value by iterating through the array. Ex: If the input is: Enter the number of integers: 5 Enter integer 1:...

  • Create a java program that reads an input file named Friends.txt containing a list 4 names...

    Create a java program that reads an input file named Friends.txt containing a list 4 names (create this file using Notepad) and builds an ArrayList with them. Use sout<tab> to display a menu asking the user what they want to do:   1. Add a new name   2. Change a name 3. Delete a name 4. Print the list   or 5. Quit    When the user selects Quit your app creates a new friends.txt output file. Use methods: main( ) shouldn’t do...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT