Question

In: Computer Science

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 mark in a specific index:

o 0: Quizzes

o 1: Midterm Exam

o 2: Final Exam

import java.util.LinkedList;

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

Student.java


class Student{
   // instance variables
   private String name;
   private Long ID;
   private int [] marks = new int [3];
   // parameterized constructor
   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;
   }
   // getter methods
   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;
   }

}

StudentLinkedList.java

import java.util.LinkedList;

public class StudentLinkedList {
   // method to print students list
   public static void printStudentList(LinkedList<Student> list) {
       for (Student student : list)
           System.out.println(student);
   }
   // method to delete the student from list by using id
   public static void deleteStudentByID(LinkedList<Student> list,long id) {
       for (Student student : list)
           if(student.getID()==id)
               list.remove(student);
       System.out.println("Student with "+id+" ID deleted successfully");
   }
   // method to find average marks of every student
   public static void findMarksAverage(LinkedList<Student> list) {
       for (Student student : list) {
           int total=0;
           for (int marks : student.getMarks())
               total+=marks;
           System.out.println("Average marks of student "+student.getName()+": "+(total/3));
       }
   }
   // method to find the minimum marks in specified exam
   public static void findMinMark(LinkedList<Student> list,int markIndex) {
       int minimim=0;
       for (Student student : list) {
           int[] temp=student.getMarks();
           if(temp[markIndex]<minimim)
               minimim=temp[markIndex];
       }
       if(markIndex==0)
           System.out.println("Minimum marks in quizzes: "+minimim);
       else
       if(markIndex==1)
           System.out.println("Minimum marks in midterm exam: "+minimim);
       else
           System.out.println("Minimum marks in final exam: "+minimim);
   }
   public static void main(String[] args) {
       // create LinkedList with Student types
       LinkedList<Student> linkedlist = new LinkedList<Student>();
       // add student objects into list
       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.add(0, new Student("John Don", 20131025, 11, 31, 31));
       printStudentList(linkedlist); // print student list
       System.out.println(); // new line
       deleteStudentByID(linkedlist, 20121024); // delete student whose id is 20121024
       System.out.println();
       findMarksAverage(linkedlist); // find average marks
       System.out.println();
       findMinMark(linkedlist, 0); // find minimum marks in quizzes
       System.out.println();
       findMinMark(linkedlist, 1); // find minimum marks in mid term exam
       System.out.println();
       findMinMark(linkedlist, 2); // find minimum marks in final exam
       System.out.println();
       printStudentList(linkedlist); // print student list
   }
}

Output


Related Solutions

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...
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()...
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...
JAVA In the last lesson, we wrote a class with methods to print out the song...
JAVA In the last lesson, we wrote a class with methods to print out the song The Ants Go Marching. Notice that this is a class where there are no instance variables and we don’t really need to generate multiple objects. With students or pets, it makes sense to have multiple objects. With the Song, we can just make the methods static and have just 1 copy of them. Copy in your class from the last lesson into this active...
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));
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT