// Defines the class "Runner"
public class Runner {
// Instance variables that stores name, mileTime, Varsity, and threeMileTime
private String name;
private float mileTime;
private float threeMileTime;
private boolean varsity;
// Constructor 1: has no arguments and sets default values
public Runner() {
this.name = "Unknown";
this.mileTime = 0.00f;
this.threeMileTime = 0.00f;
this.varsity = false;
}
// Constructor 2: has parameters and sets values based on parameters
public Runner(String name, float mileTime, float threeMileTime, Boolean varsity) {
this.name = name;
this.mileTime = mileTime;
this.threeMileTime = threeMileTime;
this.varsity = varsity;
}
// Setter method to update name
public void setName(String name) {
this.name = name;
}
// Setter method to update mileTime
public void setMileTime(float mileTime) {
this.mileTime = mileTime;
}
// Setter method to update threeMileTime
public void setThreeMileTime(float threeMileTime) {
this.threeMileTime = threeMileTime;
}
// Setter method to update varsity
public void setVarsity(Boolean varsity) {
this.varsity = varsity;
}
// Method to display runner's information
public void displayInfo() {
System.out.println("Name: " + name);
System.out.println("Mile time: " + mileTime);
System.out.println("3 mile time: " + threeMileTime);
System.out.println("Varsity: " + varsity);
}
// Static method for testing and demonstrating the class
public static void main(String[] args) {
// Create instances of Runner class using constructors
Runner runner1 = new Runner(); // Using constructor 1
Runner runner2 = new Runner("Timothy", 5.37f, 21.07f, false); // Using constructor 2
// Display initial information of the created runners
System.out.println("Info:");
System.out.println("Runner 1:");
runner1.displayInfo();
System.out.println();
System.out.println("Runner 2:");
runner2.displayInfo();
System.out.println();
// Change information using setters
runner1.setName("Joseph");
runner1.setMileTime(4.39f);
runner1.setThreeMileTime(16.59f);
runner1.setVarsity(true);
// Display updated information of runner1
System.out.println("Updated Runner 1:");
runner1.displayInfo();
}
}
Runner.main(null);
Info:
Runner 1:
Name: Unknown
Mile time: 0.0
3 mile time: 0.0
Varsity: false
Runner 2:
Name: Timothy
Mile time: 5.37
3 mile time: 21.07
Varsity: false
Updated Runner 1:
Name: Joseph
Mile time: 4.39
3 mile time: 16.59
Varsity: true