Question

In: Computer Science

Problem 3: Modify StudentLinkedList class by adding the following methods:  printStudentList: print by calling and...

Problem 3:

Modify StudentLinkedList class by adding the following methods:

  •  printStudentList: print by calling and printing “toString” of every object in the linkedList. Every student object to be printed in a separate line.

  •  deleteStudentByID(long id): delete student object from the list whose ID is matching with the passed parameter.

  •  sortListByID(): sort the linkedlist according to students IDs.

  •  findMarksAverage(): find the average of all marks for all students in the list.

  •  findMinMark(int markIndex): find the student with the minimum mark in a specific index:

Quizzes

Midterm Exam

Final Exam

please solve it as clear and simple as you can - java netbeans

Solutions

Expert Solution

import java.util.Comparator;
import java.util.LinkedList;

public class StudentLinkedList {
        
        public static void printStudentList(LinkedList<Student> ll) {
                for(int i=0; i<ll.size(); i++) {
                        System.out.println(ll.get(i));
                }
                System.out.println();
        }
        
        public static void deleteStudentByID(LinkedList<Student> ll, long id) {
                for(int i=0; i<ll.size(); i++) {
                        if(ll.get(i).getID() == id) {
                                ll.remove(i);
                                System.out.println("Deleted successfully.");
                                return;
                        }
                }
                
                System.out.println("Unable to find the student with id " + id);
        }
        
        public static void sortListByID(LinkedList<Student> ll) {
                ll.sort(new Comparator<Student>() {

                        @Override
                        public int compare(Student o1, Student o2) {
                                return (int) (o1.getID() - o2.getID());
                        }
                });
        }
        
        public static double findMarksAverage(LinkedList<Student> ll) {
                double totalMarks = 0;
                for(int i=0; i<ll.size(); i++) {
                        int marks[] = ll.get(i).getMarks();
                        totalMarks += marks[0] + marks[1] + marks[2];
                }
                return totalMarks/ll.size();
        }
        
        public static double findMinMark(LinkedList<Student> ll, int markIndex) {
                int minMark = 100;

                for(int i=0; i<ll.size(); i++) {
                        int marks[] = ll.get(i).getMarks();
                        
                        if(marks[markIndex] < minMark) {
                                minMark = markIndex;
                                minMark = marks[markIndex];
                        }
                }
                
                return minMark;
        }
        
        public static void main(String[] args) {
                LinkedList<Student> linkedlist = new LinkedList<>();
                linkedlist.add(new Student("Ahmed Ali", 20111021, 18, 38, 38));
                linkedlist.add(new Student("Sami Kamal", 20121021, 17, 39, 35));
                linkedlist.add(new Student("Salem Salim", 20131021, 20, 40, 40));
                linkedlist.add(new Student("Rami Mohammed", 20111031, 15, 35, 30));
                linkedlist.add(new Student("Kim Joe", 20121024, 12, 32, 32));
                linkedlist.addFirst(new Student("Hadi Ali", 20111025, 19, 38, 39));
                linkedlist.addLast(new Student("Waleed Salim", 20131025, 10, 30, 30));
                linkedlist.set(0, new Student("Khalid Ali", 20111027, 15, 30, 30));
                linkedlist.removeFirst();
                linkedlist.removeLast();
                linkedlist.add(0, new Student("John Don", 20131025, 11, 31, 31));
                linkedlist.remove(2);
                
                printStudentList(linkedlist);
                deleteStudentByID(linkedlist, 20121024);
                printStudentList(linkedlist);
                
                sortListByID(linkedlist);
                printStudentList(linkedlist);
                
                System.out.println("Average marks by all: " + findMarksAverage(linkedlist));
                System.out.println("Min Quizzes marks by student: " + findMinMark(linkedlist, 0));
                System.out.println("Min Midterm marks by student: " + findMinMark(linkedlist, 0));
                System.out.println("Min Final exam marks by student: " + findMinMark(linkedlist, 0));
        }
}

class Student {
        private String name;
        private Long ID;
        private int[] marks = new int[3];

        public Student(String name, long ID, int quizzes, int mid, int fin) {
                this.name = name;
                this.ID = ID;
                marks[0] = quizzes;
                marks[1] = mid;
                marks[2] = fin;
        }

        public String getName() {
                return name;
        }

        public Long getID() {
                return ID;
        }

        public int[] getMarks() {
                return marks;
        }

        @Override
        public String toString() {
                String temp = "student: " + "name = " + name + ", ID = " + ID + ", marks = {" + marks[0] + ", " + marks[1]
                                + ", " + marks[2] + "}";
                return temp;
        }
}
**************************************************

Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.

Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.


Related Solutions

Modify StudentLinkedList class by adding the following methods: printStudentList: print by calling and printing “toString” of...
Modify StudentLinkedList class by adding the following methods: printStudentList: print by calling and printing “toString” of every object in the linkedList. Every student object to be printed in a separate line.  deleteStudentByID(long id): delete student object from the list whose ID is matching with the passed parameter.  sortListByID(): sort the linkedlist according to students IDs.  findMarksAverage(): find the average of all marks for all students in the list.  findMinMark(int markIndex): find the student with the minimum...
JAVA- Modify the LinkedList1 class presented in this chapter by adding sort() and reverse() methods. The...
JAVA- Modify the LinkedList1 class presented in this chapter by adding sort() and reverse() methods. The reverse method reverses the order of the elements in the list, and the sort method rearranges the elements in the list so they are sorted in alphabetical order. The class should use recursion to implement the sort and reverse operations. Extend the graphical interface in the LinkedList1Demo class to support sort and reverse commands, and use it to test the new methods. LinkedList1: class...
C++ Modify the class unorderedList to include a recursive forward print and a recursive reverse print...
C++ Modify the class unorderedList to include a recursive forward print and a recursive reverse print Make your unorderedList a list of characters instead of integers Insert ten characters into the list and print it out both ways #include <iostream> #include <string> #include <cstdlib> using namespace std; struct node { int info; node* next; }; class unorderedList { private: int length; node* listPtr; public: unorderedList() {length = 0; listPtr = NULL;} void makeEmpty(); void insertItem(int item); void printList(); bool isFull()...
Using Java create a program that does the following: Modify the LinkedList1 class by adding sort()...
Using Java create a program that does the following: Modify the LinkedList1 class by adding sort() and reverse() methods. The reverse method reverses the order of the elements in the list, and the sort method rearranges the elements in the list so they are sorted in alphabetical order. Do not use recursion to implement either of these operations. Extend the graphical interface in the LinkedList1Demo class to support sort and reverse commands, and use it to test the new methods....
Modify listarr.java program by adding the following 2 methods: public void insertsorted(x); // Inert x in...
Modify listarr.java program by adding the following 2 methods: public void insertsorted(x); // Inert x in a sorted list. protected int binsearch(x); // Binary search for x Assume you have a data file p1.txt with the following contents: 8     4 15 23 12 36 5 36 42 3 5 14 36 and your main program is in p1.java file. To compile: javac p1.java To execute: java p1 < any data file name say p1.txt Your output should be formatted (i.e....
Instructions Modify the Product class from the Practice Exercise 7 by adding a quantity member. Include...
Instructions Modify the Product class from the Practice Exercise 7 by adding a quantity member. Include a getter and setter, using decorators, and modify the appropriate constructor to also accept a quantity parameter. Then modify the inventory.py file from the practice exercise to include quantity values in the constructor calls with a quantity of 100 for product1 (hammers) and 3000 for product2 (nails). Add print statements to display the quantity values as shown in the Expected Output included below. Submission...
How to print these methods in a separate main class? need the output to look like...
How to print these methods in a separate main class? need the output to look like this: Enter three integers whose GCD is to be found -> Enter an integer n to find the nth Fibonacci number -> Enter the base and exponent , an integer, of a power -> Enter two positive integers 1 and j where i < j -> gcd() = fib() = (a number ^ a number) = a number There are ___ palindromic numbers between...
3. [Method 1] In the Main class, write a static void method to print the following...
3. [Method 1] In the Main class, write a static void method to print the following text by making use of a loop. Solutions without a loop will receive no credit. 1: All work and no play makes Jack a dull boy. 2: All work and no play makes Jack a dull boy. 3: All work and no play makes Jack a dull boy. 4: All work and no play makes Jack a dull boy. 4. [Method 2] In the...
Method calling in c# I need to write methods for calling the min and max numbers...
Method calling in c# I need to write methods for calling the min and max numbers using this code; Console.WriteLine("Calling highest method."); Console.WriteLine("Highest number is: {0}", highest(3)); Console.WriteLine("Calling lowest method."); Console.WriteLine("Lowest number is: {0}", lowest(3));
The class Person, uploaded on Blackboard with Lab 5, only has methods to set and print...
The class Person, uploaded on Blackboard with Lab 5, only has methods to set and print the name of a person. Redefine the class Person to include the following operations: Set the last name only Set the first name only Set the middle name Check whether a given last name is the same as the last name of this person Check whether a give first name is the same as the first name of this person Check whether a given...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT