News:

Please note these forums are mostly a testing ground for my SMF work and I don't really use them otherwise.

Main Menu

Paste-1204954273:v:use_geshi-1:v:type-java5

Started by JayBachatero, Mar 08, 2008, 05:31 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

JayBachatero

/**
 * Students.
 * @author Juan "JayBachatero" Hernandez
 *
 */

public class Student
{
   // Instance variables.
   private String name;
   private int grades[] = new int[3];

   public Student()
   {
   }

   /**
    * Constructor for the student.
    * @param name
    * @param grades
    */
   public Student(String name, int[] grades)
   {
      // Set the values.
      this.name = name;
      this.grades = grades;
   }

   /**
    * Sets the name for the student.
    * @param name
    */
   public void setName(String name)
   {
      this.name = name;
   }

   /**
    * Gets the name;
    * @return
    */
   public String getName()
   {
      return this.name;
   }
   /**
    * Sets the grades for the student.
    * @param grades
    */
   public void setGrades(int index, int grade)
   {
      this.grades[index] = grade;
   }

   /**
    * Gets the grades.
    * @return
    */
   public int[] getGrades()
   {
      return this.grades;
   }

   /**
    * Returns the grades for a specific index.
    * @param index
    * @return
    */
   public int getGrades(int index)
   {
      return this.grades[index];
   }

   /**
    * Gets the average of the grades.
    * @return
    */
   public double findAverage()
   {
      // Lets return the sum of the grades.
      return this.arraySum(this.grades) / this.grades.length;
   }

   /**
    * Adds an array of integers.
    * @param theArray
    * @return the sum of the integers.
    */
   public int arraySum(int[] theArray)
   {
      // Initialize the sum.
      int sum = 0;

      for (int i = 0; i < theArray.length; i++)
         sum += theArray[1];

      // Return it.
      return sum;
   }

   /**
    * Adds an array of doubles.
    * @param theArray
    * @return the sum of the doubles.
    */
   public double arraySum(double[] theArray)
   {
      // Initialize the sum.
      double sum = 0;

      for (int i = 0; i < theArray.length; i++)
         sum += theArray[1];

      // Return it.
      return sum;
   }

   /**
    * Calculates the letter grade from an number grade.
    * @param average
    * @return the letter grade.
    */
   public char whatLetterGrade(double average)
   {
      // Letter.
      char letter;

      // Lets determine the letter grade.
      if (average <= 100 && average >= 90)
         letter = 'A';
      else if (average >= 80)
         letter = 'B';
      else if (average >= 70)
         letter = 'C';
      else if (average >= 60)
         letter = 'D';
      else
         letter = 'F';

      // Return the grade.
      return letter;
   }

   /**
    * Loops through an array and gets the highest grade in the array.
    * @param grades
    * @return the highest grade.
    */
   public int getHighestGrade(int[] grades)
   {
      // Lets initialize the grade with the lowest possible grade; 0.
      int grade = 0;

      // Loop through the grades.
      for (int i = 0; i < grades.length; i++)
         if (grades > grade)
            grade = grades;

      return grade;
   }
}