Question

In: Computer Science

home / study / engineering / computer science / computer science questions and answers / Modify...

home / study / engineering / computer science / computer science questions and answers / Modify StudentLinkedList Class By Adding The Following Methods:  PrintStudentList: Print ... Your question has expired and been refunded. We were unable to find a Chegg Expert to answer your question. Question: Modify StudentLinkedList class by adding the following methods:  printStudentList: print by call... 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: o 0: Quizzes o 1: Midterm Exam o 2: Final Exam public class StudentLinkedList { public static void main(String[] args) { LinkedList 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); } 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] = quizes; 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; } }

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

home / study / engineering / computer science / computer science questions and answers / create...
home / study / engineering / computer science / computer science questions and answers / create a new java file, containing this code public class datastatsuser { public static void ... Your question has been answered Let us know if you got a helpful answer. Rate this answer Question: Create a new Java file, containing this code public class DataStatsUser { public static void... Create a new Java file, containing this code public class DataStatsUser { public static void main...
home / study / engineering / computer science / computer science questions and answers / 2....
home / study / engineering / computer science / computer science questions and answers / 2. design an er-diagram for a bank that implements the following requirements. the database ... Question: 2. Design an ER-diagram for a bank that implements the following requirements. The database you d... 2. Design an ER-diagram for a bank that implements the following requirements. The database you design should store information about customers, accounts, branches and employees • Customer: Customers are identified by their SSN....
home / study / engineering / computer science / computer science questions and answers / write...
home / study / engineering / computer science / computer science questions and answers / write a program that in c++: 1.prompts the user to enter a positive integer, think of this ... Question: Write a program that in C++: 1.Prompts the user to enter a positive integer, think of this intege... Write a program that in C++: 1.Prompts the user to enter a positive integer, think of this integer as representing a specific number of pennies. 2. The program...
home / study / engineering / computer science / questions and answers / this is c....
home / study / engineering / computer science / questions and answers / this is c. create three files to submit. contacts.h ... Question: This is C. Create three files to submit. Contacts.... Bookmark This is C. Create three files to submit. Contacts.h - Struct definition, including the data members and related function declarations Contacts.c - Related function definitions main.c - main() function (2) Build the ContactNode struct per the following specifications: Data members char contactName[50] char contactPhoneNum[50] struct ContactNode*...
home / study / engineering / computer science / questions and answers / working with layout...
home / study / engineering / computer science / questions and answers / working with layout managers. notes: 1. in part ... Your question has been answered Let us know if you got a helpful answer. Rate this answer Question: Working with Layout Managers. Notes: 1. In part 2,... Bookmark Working with Layout Managers. Notes: 1. In part 2, note that the Game class inherits from JPanel. Therefore, the panel you are asked to add to the center of the...
The questions read as follows: home / study / engineering / computer science / computer science...
The questions read as follows: home / study / engineering / computer science / computer science questions and answers / Course Grades Java Class In A Course, A Teacher Gives The Following Tests And Assignments: ... Question: Course grades java class In a course, a teacher gives the following tests and assignments: A lab ... course grades java class In a course, a teacher gives the following tests and assignments: A lab activity that is observed by the teacher and...
home / study / science / nursing / nursing questions and answers / This Is A...
home / study / science / nursing / nursing questions and answers / This Is A Theoretical Case Taken From VHA Intensive Ethics Advisory Committee Training, 1998, ... Your question has been posted. We'll notify you when a Chegg Expert has answered. Post another question. Next time just snap a photo of your problem. No typing, no scanning, no explanation required. Get Chegg Study App Question: This is a theoretical case taken from VHA Intensive Ethics Advisory Committee Training, 1998,...
home / study / science / nursing / nursing questions and answers / you are a...
home / study / science / nursing / nursing questions and answers / you are a public health researcher. you have been asked to identify a vaccine-preventable disease. ... Question: You are a public health researcher. You have been asked to identify a vaccine-preventable disease... You are a public health researcher. You have been asked to identify a vaccine-preventable disease. Your research design should focus on determining why health care workers are not receiving the vaccination for your selected vaccine-preventable...
home / study / science / biology / questions and answers / which of the following...
home / study / science / biology / questions and answers / which of the following best explains why atp is ... Question: Which of the following BEST explains why ATP is a ... Save Which of the following BEST explains why ATP is a positive regulator of aspartate transcarbamoylase (ATCase)? A. Aspartate is only available when ATP levels are high. B. ATP levels correspond to CTP levels, thus when both ATP and CTP are high, ATCase is active. C....
home / study / science / physics / physics questions and answers / this is my...
home / study / science / physics / physics questions and answers / this is my second time posting this: question: i have been working on this and i have done ... Question: This is my second time posting this:   Question: I have been working on this and I have... This is my second time posting this:   Question: I have been working on this and I have done it. But I am not sure what velocity versus time plot,... I...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT