DEV Community

Discussion on: 6 Hacks to create a Good Coding Habit

Collapse
 
matkasur profile image
Info Comment hidden by post author - thread only visible in this permalink
Matkasur

package progusingjava;

//DO NOT MODIFY THE CODE PROVIDED TO YOU

public class TransportFacility {
private static String[] locationArr={"Northyork", "Scarborough", "Etobicoke"};
private static double[] transportCostArr={1500.0, 1000.0, 2000.0};
private double transportFee;
private int distance;

public TransportFacility(int distance) { 
    this.distance = distance;
} 

public double getTransportFee() {
    return this.transportFee; 
}

//To Trainees
public double identifyTransportFee(String location) {
    this.transportFee = 0.0;

if (this.distance > 0) {
    for (int i = 0; i < locationArr.length; i++) {
        if (locationArr[i].equals(location)) {
            this.transportFee = transportCostArr[i];
            break;
        }
    }
}

return this.transportFee;

}

@Override
public String toString() {
    return "TransportFacility (distance=" + this.distance + ")"; 
}
Enter fullscreen mode Exit fullscreen mode

}

Some comments have been hidden by the post's author - find out more