i've had a pretty good day today up to now....

i have a method calcFinalOCAS() which should take an average of a list, replace the lowest value (if its lower than the substitution score), do the average again.

now this works but when its compiled and i run it but it alters the original tmaMarks list. ive tried to create a new list and do the calculations on the new list but it seams to sort both lists... can anyone shed some light on why it would do this? how should i get the tmaMarks so that i dont alter the original list?

/**
    * Calculates and sets the finalOCAS of the receiver
    */
   public void calcFinalOCAS()
   {
      // put your code here (see part (iii)(c))
      this.calcSubstitutionScore();
            
      Collections.sort(this.tmaMarks);
      
      
      int minVal = this.tmaMarks.get(0);
      
      
      if (substitutionScore > minVal)
      
      {
         this.tmaMarks.set(0, substitutionScore);
      }
      
      //tmaMarks = getTmaMarks();
      finalOCAS = average(tmaMarks);
   }

and the whole class code

import java.util.*;

/**
 * Class Student - Simple class representing an OU student and their marks
 * 
 * @author M255 Course Team 
 * @version 1.0
 */

public class Student
{
   /* instance variables */
   private String name;            // String representing student's name
   private List<Integer> tmaMarks; // list of student's TMA marks.
   private int examMark;           // student's exam mark. -1 indicates exam has not been taken
   private int substitutionScore;  // student's substitution score. -1 if not yet calculated
   private int finalOCAS;          // final continuous assessment score. -1 if not yet calculated
   
   

   /**
    * Constructor for objects of class Student
    */
   public Student(String aName)
   {
      // put your code here (see part (i))
      
      name = aName;
      List<Integer> tmaMarks = new ArrayList<Integer>();
      examMark = -1;
      substitutionScore = -1;
      finalOCAS = -1;
      
   }

   
   /* instance methods */
   
   /**
    * Returns the integer average (rounded down) of the integers
    * in the list given as the argument
    */
   // put your code for the class method average() here (see part (iii)(a))

   public Integer average(List<Integer> values)
   {

      
      int total = 0;
      for (int eachElement : values)
      {
         total = total + eachElement;
      }
      int avg = ((int)total) / values.size();
      
      System.out.println("average = " + avg);
      return avg;
   }
 
   
        
   /**
    * Returns the name of the receiver
    */
   public String getName()
   {
      return this.name;
   }
   
   
   
   /**
    * Sets the tmaMarks of the receiver to someTmaMarks
    */
   public void setTmaMarks(List<Integer> someTmaMarks)
   {
      this.tmaMarks = someTmaMarks;
   }
   
   
   
   /**
    * Returns the tmaMarks of the receiver
    */
   public List<Integer> getTmaMarks()
   {
      return this.tmaMarks;
   }
   
   
     
   /**
    * Sets the examMark of the receiver to aMark
    */
   public void setExamMark (int aMark)
   {
      this.examMark = aMark;
   }
   
   
     
   /** 
    * Returns the examMark of the receiver
    */
   public int getExamMark()
   {
      return this.examMark;
   }
   
   
   
   /**
    * Sets the substitutionScore of the receiver to aScore
    */
   private void setSubstitutionScore (int aScore)
   {
      this.substitutionScore = aScore;
   }
     
   
   
   /**
    * Returns the substitutionScore of the receiver
    */
   public int getSubstitutionScore()
   {
      return this.substitutionScore;
   }
   
   
   
   /**
    * Sets the finalOCAS of the receiver to anOCAS
    */
   private void setFinalOCAS (int anOCAS)
   {
      this.finalOCAS = anOCAS;
   }
   
   
     
   /**
    * Returns the finalOCAS of the receiver
    */
   public int getFinalOCAS()
   {
      return this.finalOCAS;
   }
   
   
  
   /** 
    * Displays the name and set of marks of the receiver
    */
   public void displayMarks()
   {
      System.out.println("TMA marks are " + this.tmaMarks);
      System.out.println("Exam mark is " + this.getExamMark());
      System.out.println("Substitution score is " + this.getSubstitutionScore());
      System.out.println("Final OCAS is " + this.getFinalOCAS());
      
   }
   
   

   /**
    * Calculates and sets the substitutionScore of the receiver
    */
   public void calcSubstitutionScore()   
   {
      // put your code here (see part (iii)(b)
     int tmaMarks = average(this.tmaMarks);
     int examMark = this.getExamMark();
     
     substitutionScore = ((tmaMarks + examMark) / 2);
     
   }
   
   
   
   /**
    * Calculates and sets the finalOCAS of the receiver
    */
   public void calcFinalOCAS()
   {
      // put your code here (see part (iii)(c))
      this.calcSubstitutionScore();
            
      Collections.sort(this.tmaMarks);
      
      
      int minVal = this.tmaMarks.get(0);
      
      
      if (substitutionScore > minVal)
      
      {
         this.tmaMarks.set(0, substitutionScore);
      }
      
      //tmaMarks = getTmaMarks();
      finalOCAS = average(tmaMarks);
   }
  
   
   

}
This question has already been answered. Start a new discussion instead.