full - import java.util.*; import java.lang.*; class...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
import java.util.*; import java.lang.*; class Rental{ public boolean checkOut(Customer outCust, Date outDate) { if( getCurrentCust() != null ) return false; setCurrentCust(outCust); setCheckOutDate(outDate); return true; } public boolean checkIn(Date inDate) { double outTime; int i; if( currentCust == null ) return false; outTime = (inDate.getTime() - getCheckOutDate().getTime()); outTime /= (1000*60*60); for( i=maxHistory-1; i>0; i-- ) { historyCusts[i] = historyCusts[i-1]; historyLengths[i] = historyLengths[i-1]; } historyCusts[0] = getCurrentCust(); historyLengths[0] = outTime; if( numHistory < maxHistory ) numHistory++; currentCust = null; checkOutDate = null; return true; } public void printHistory() { for( int i=0; i<numHistory; i++ ) System.out.print(historyCusts[i].getName() + "," + historyLengths[i] + "," ); System.out.println(""); } public abstract double getLength(Customer myCust); public abstract double getLengthMax(); public abstract double getLengthMean(); public abstract double getLengthMedian();
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
} public Movie(String title, Customer[] historyCusts, double[] historyLengths) { setTitle(title); setCurrentCust(null); setCheckOutDate(null); this.historyCusts = new Customer[maxHistory]; this.historyLengths = new double[maxHistory]; numHistory = Math.min(historyCusts.length, maxHistory); for( int i=0; i<numHistory; i++ ) { this.historyCusts[i] = historyCusts[i]; this.historyLengths[i] = historyLengths[i]; } } public double getLength(Customer myCust) { double totalLength = 0.0D; for(int i = 0; i<numHistory; i++) { if (historyCusts[i].equals(myCust)) { totalLength+=historyLengths[i]; } } return totalLength; } public double getLengthMean() { double mean= 0.0D; for (int i=0; i<numHistory; i++) { mean+=historyLengths[i]; } if (numHistory != 0) { mean/=(double)numHistory; } return mean; } public double getLengthMax() { double max = 0.0D; for( int i=0; i<numHistory; i++ ) if( historyLengths[i] > max ) max = historyLengths[i];
Background image of page 2
} public double getLengthMedian() { double[] myLengths = new double[numHistory]; for( int i=0; i<numHistory; i++ ) myLengths[i] = historyLengths[i]; Arrays.sort(myLengths); if( numHistory==0 ) return 0.0; else if( numHistory%2 == 1 ) return myLengths[(numHistory-1)/2]; else return (myLengths[(numHistory/2)-1] + myLengths[(numHistory/2)])/2.0; } public boolean equals(Object o) { if (o instanceof Movie) //get explaination about whats going on in this equals method { Movie movie = (movie)o; if (movie.getCheckOutDate() ==null && getCheckOutDate() !=null) // how did they know this could be null { return false; } if (movie.getTitle().equals(getTitle() && movie.getNumHistory()==getNumHistory() && (movie.getCheckOutDate() ==null || movie.getCheckOutDate().equals(getCheckOutDate()))) { for (int i=0; i<numHistory; i++) { for(intj=0; j<numHistory; j++) { if( movie.getHistoryCusts() [i].equals( historyCusts[j] ) ) if( movie.getHistoryLengths()[i] == historyLengths[j] ) break; } if( j==numHistory )// what do both of these mean? break;
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/25/2010 for the course CIS CIS3023 taught by Professor Seema during the Spring '10 term at Florida College.

Page1 / 17

full - import java.util.*; import java.lang.*; class...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online