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 MusicInstrumentCourse {
private String instrumentCourseName;
private int courseDuration;
private double courseFee;
private static String[] instrumentCourseAvailableArr = { "Piano", "Drum", "Guitar" };
private static double[] instrumentCourseCostArr = { 2000.0, 3000.0, 2500.0 };

public MusicInstrumentCourse(String instrumentCourseName, int courseDuration) {
    this.instrumentCourseName = instrumentCourseName;
    this.courseDuration = courseDuration;
}

public String getInstrumentCourseName() {
    return this.instrumentCourseName;
}

public double getCourseFee() {
    return this.courseFee;
}

public int getCourseDuration() {
    return this.courseDuration;
}

public boolean validateMusicInstrumentCourse() {
    return (this.instrumentCourseName.equals("Piano") || this.instrumentCourseName.equals("Drum")
            || this.instrumentCourseName.equals("Guitar"));
}

// To Trainees
public void calculateCourseFee() {

    this.courseFee = -1.0;

    instrumentCourseName = instrumentCourseName.toLowerCase();

    boolean courseFound = false;
    double basicCost = 0.0;
    for (int i = 0; i < instrumentCourseAvailableArr.length; i++) {
        if (instrumentCourseAvailableArr[i].equalsIgnoreCase(instrumentCourseName)) {
            courseFound = true;
            basicCost = instrumentCourseCostArr[i];
            break;
        }
    }

    if (courseFound && basicCost != 0.0) {
        double basicFee = basicCost * courseDuration;

        double facilitiesFee = 0.1 * basicFee;

        basicFee += facilitiesFee;

        this.courseFee = basicFee;
    }

}

@Override
public String toString() {
    return "MusicInstrumentCourse (instrumentCourseName=" + this.instrumentCourseName + ", courseDuration="
            + this.courseDuration + ")";
}
Enter fullscreen mode Exit fullscreen mode

}

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