// Car.java
// Class definition
// Uses overloaded constructors
// Example to illustrate the creation of a user-defined class
// Saved in jre\classes\edu\lehigh\notes directory
package edu.lehigh.notes;
public class Car {
// instant variables
private String model;
private int topSpeed;
private double zeroToSixty;
private double sixtyToZero;
private boolean sexy;
// constructor method -- takes five arguments
public Car( String m, int ts, double a, double b, boolean h ) {
model = m;
topSpeed = ts;
zeroToSixty = a;
sixtyToZero = b;
sexy = h;
}
// constructor method -- takes four arguments -- no topSpeed
public Car( String m, double a, double b, boolean h ) {
model = m;
topSpeed = -1; // no top speed given
zeroToSixty = a;
sixtyToZero = b;
sexy = h;
}
public int getTopSpeed( ) {
return topSpeed;
}
public double getZeroToSixty( ) {
return zeroToSixty;
}
public double getSixtyToZero( ) {
return sixtyToZero;
}
public boolean getSexy( ) {
return sexy;
}
public String toString( ) {
return "The " + model + " accelerates to 60 in " + zeroToSixty + " and brakes from 60 in " + sixtyToZero + " .";
}
public double perform( ) {
return zeroToSixty + sixtyToZero;
}
}