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...
Write in Java Modify the parent class (Plant) by adding the following abstract methods:(The class give...
Write in Java Modify the parent class (Plant) by adding the following abstract methods:(The class give in the end of question) a method to return the botanical (Latin) name of the plant a method that describes how the plant is used by humans (as food, to build houses, etc) Add a Vegetable class with a flavor variable (sweet, salty, tart, etc) and 2 methods that return the following information: list 2 dishes (meals) that the vegetable can be used in...
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()...
For this project, you are to modify the Employee class posted on Blackboard by adding a...
For this project, you are to modify the Employee class posted on Blackboard by adding a bonus field. The bonus field should be equal to zero when an Employee object is created. You need to add a setter and a getter method to the new bonus field. The Dirany’s company saves all employee information in the dirany.txt file (attached). The file saves each employee’s information in a new line and all attributes are separated by tabs. For example, the first...
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....
Problem 5: (10 pts) Modify the patient class with two overloaded methods to display a bill...
Problem 5: (10 pts) Modify the patient class with two overloaded methods to display a bill for astandard visit based on age. In the first method do not use any parameters to pass in data. If the patient is over 65, then a standard visit is $75. If the patient is under 65, then the standard doctors office visit is $125. Build a second method where you pass in a discount rate. If the patient is over 65, then apply...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT