Problem 1 List Client Suppose that you have a singly linked

Problem 1 (List Client)

Suppose that you have a singly linked list that is created by the following statement ListInterface quizScores = new LList(); A professor wants to add to this list quiz scores received by a student throughout a course and find the average of these quiz scores, ignoring the lowest score. Write a Java program at the client level that will:

a. Find and remove the lowest score in the list

b. Compute the average of the scores remaining in the list

c. Print the result.

Solution

package com.spring.youtube;

import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;

public class screQuiz {
   static List quizScores=new ArrayList();
  
   //add scores to a list.
  
   public static void main(String hj[]){
      
       quizScores.add(1);
       quizScores.add(2);
       quizScores.add(81);
       quizScores.add(23);
       quizScores.add(234);
       quizScores.add(24);
      
       System.out.println(\"Printing elemets of list\");
       for(int i=0;i<quizScores.size();i++){
           System.out.println(i+\"\ \");
       }
      
       /*
       * this method removes lowest score from list.
       */
       removelowestscore();
      
       /*
       * this method prints Print list.
       *
       */
      
   }

   private static void removelowestscore() {

   int minIndex;
   if (quizScores.isEmpty()) {
   minIndex = -1;
   } else {
   final ListIterator<Integer> itr = quizScores.listIterator();
   Integer min = itr.next(); // first element as the current minimum
   minIndex = itr.previousIndex();
   while (itr.hasNext()) {
   final Integer curr = itr.next();
   if (curr.compareTo(min) < 0) {
   min = curr;
   minIndex = itr.previousIndex();
   }
   }
   }
  
   quizScores.remove(minIndex);
   }
  
   private void printelements(){
       for(int i=0;i<quizScores.size();i++){
           System.out.println(i+\"\ \");
       }
      
   }
  
}

Problem 1 (List Client) Suppose that you have a singly linked list that is created by the following statement ListInterface quizScores = new LList(); A professo
Problem 1 (List Client) Suppose that you have a singly linked list that is created by the following statement ListInterface quizScores = new LList(); A professo

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site