[GUILD] Assignment 4

Need help with your code? Post it here and we'll try our best to help.
User avatar
Kamasabi
Is Gettin' Pwned
Posts: 9
Joined: Tue Jul 17, 2007 11:01 pm
Contact:

[GUILD] Assignment 4

Postby Kamasabi » Sun Sep 30, 2007 10:21 pm

Code: Select all

/*
Class:  CSIS 2302
Section:  01
Name:  Aaron Groff
Professor:  Gayler
Assignment #: 4
*/


public class ParkingTimes
{
   private int numTimes;
   private double [] times;
   
// constructor

   public ParkingTimes()
   {
      times = new double [10];
      numTimes = 0;
   }
   public void addTime(double time)
   {
      if( numTimes == times.length)
      {
         increaseSize();
      }
      times[numTimes] = time;
      numTimes++;
   }
   
//finds the averages of times

   public double averageTime()
   {
      double total = 0.0;
      
      for(int j = 0; j < times.length; j++)
      {
         total += times[j];
      }
      double average = total / numTimes;
      
      return average;
   }

//increase size of array if exceeded

   private void increaseSize()
   {
      double [] tempTime = new double[times.length + 1];
      
      for (int i = 0; i < times.length; i++ )
      {
         tempTime[i] = times[i];
      }
      times = tempTime;
   }
   
//finds the max time

   public double maxTime()
   {
      double max = times[0];
      
      for( int k = 0; k < times.length; k++ )
      {
         if (times[k] > max)
            max = times[k];
      }
      return max;
   }

//finds the min time

   public double minTime()
   {
      double min = this.maxTime();
      
      for (int l = 0; l < numTimes; l++ )
      {
         if (times[l] < min )
            min = times[l];
      }
      return min;
   }
}
Last edited by Kamasabi on Sun Sep 30, 2007 11:01 pm, edited 4 times in total.

User avatar
Elric of the void
Site Admin
Posts: 774
Joined: Mon Jul 02, 2007 11:21 pm

Postby Elric of the void » Sun Sep 30, 2007 10:35 pm

Code: Select all


 private void increaseSize()
   {
      double [] tempTime = new double[times.length +1];
     
      for (int i = 0; i < times.length; i++ )
      {
         tempTime[i] = times[i];
      }
      times = tempTime;
   }

User avatar
Elric of the void
Site Admin
Posts: 774
Joined: Mon Jul 02, 2007 11:21 pm

Postby Elric of the void » Sun Sep 30, 2007 10:50 pm

Excellent another job well done :)


Return to “Code Monkeys”

Who is online

Users browsing this forum: No registered users and 2 guests