Write three classes: Student.java, StudentList.java and Course.java with using the concept of linked list.
import java.util.HashMap;
import java.util.Objects;
public class StudentList {
private HashMap<Student, CourseList> studentList;
public StudentList() {
this.studentList = new HashMap<>();
}
public void add(Student student, Course course) {
if (this.studentList.containsKey(student)) {
CourseList courseListOfStudent = studentList.get(student);
courseListOfStudent.add(course);
return;
}
CourseList courseList = new CourseList();
courseList.add(course);
studentList.put(student, courseList);
}
public void display() {
for (Student student : studentList.keySet()) {
System.out.println("Student Name ::" + student);
studentList.get(student).courseList();
System.out.println();
}
}
public static void main(String[] args) {
StudentList studentList = new StudentList();
studentList.add(new Student("srinu"),new Course("MATHS"));
studentList.add(new Student("srinu"),new Course("Physics"));
studentList.add(new Student("srinu"),new Course("IT"));
studentList.add(new Student("ram"),new Course("MATHS"));
studentList.add(new Student("ram"),new Course("Chemistry"));
studentList.add(new Student("John"),new Course("IT"));
studentList.display();
}
}
class Course {
private final String courseName;
public Course(String courseName) {
this.courseName = courseName;
}
@Override
public String toString() {
return courseName;
}
}
class Student {
private final String name;
public Student(String name) {
this.name = name;
}
@Override
public String toString() {
return name;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Student student = (Student) o;
return Objects.equals(name, student.name);
}
@Override
public int hashCode() {
return Objects.hash(name);
}
}
class CourseList {
private Node head;
public CourseList() {
this.head = null;
}
public void add(Course course) {
if (head == null) {
head = new Node(course);
return;
}
Node temp = new Node(course);
temp.next = head;
head = temp;
}
public void courseList() {
System.out.printf("Course List:: ");
Node temp = head;
while (temp != null) {
System.out.printf("%s ", temp.getCourse());
temp = temp.next;
}
System.out.println();
}
}
class Node {
private Course course;
Node next;
public Node(Course course) {
this.course = course;
this.next = null;
}
public Course getCourse() {
return course;
}
}
|
![]() |
Write three classes: Student.java, StudentList.java and Course.java with using the concept of linked list.
Using a class template, write a linked list with 5 nodes and print the linked list. Then make a second linked list with the values from the first linked list and reverse the values and print. (C++)
Can someone write an example of a Linked list code that simply adds items to the head and to the tail of the list in PYTHON while using classes.
Using the concept of singly linked list, show all the pointer updates required for the following Operation (show steps hy using starting 6 chancters of your full name): head 10.pico, Bormes R
each A polynomial may be represented as a linked list where each node contains the coefficient and exponent of a term of the polynomial. The polynomial 4X-3X-5 would be represented as the linked list. as the linked list the polnomial eql -5 0 Write a program system that reads two polynomials, stores them as linked lists, adds them together, and prints the result as a polynomial. The result should be a third linked list. Hint: Travers both polynomials. If a...
C# please Write method to search a node in linked list using ID recursively, Write method to search a node in linked list using NAME recursively
write a java program implementing stacks using arrays. (not with linked list)
Write a Java class myLinkedList to simulate a singly linked list using arrays as the underlying structure. Include the following methods: 1. insert an element within the linked list.(this should also work for the front and the rear of the list) 2. Remove an element from the linked list 3. Display (print) the elements of the linked list in order. 4. A method to check if the list is "empty". Test your solution using a linked list that initially has...
Using Python Create a simple linked list by defining a struct (in C/C++) or a class (in Python3). For example, in C/C++: struct singly_linked_list { int data; singly_linked_list *next; }; (Make sure you understand the concept of pointers - or lack thereof - in Python.) Write a function to determine if there is a cycle in the singly linked list. Return 1 if there is a cycle in the list, 0 if no cycle. This is a very common interview...
Write a C++ program to manage a list of inventory items using a linked list. Operations should include adding a new inventory item at the end of the list, adding a new inventory item at the beginning of the list, removing an inventory item from the beginning of the list, removing an inventory item from the end of the list, removing an inventory item by name, and display the current list of inventory items. Allow the user an option to...
Explain the concept of Linked hash table and Write a program in C# where you implement the concept of linked hash table