DEV Community

Cover image for 6 Hacks to create a Good Coding Habit
Pragyan Tripathi
Pragyan Tripathi

Posted on

6 Hacks to create a Good Coding Habit

6 Hacks to create a Good Coding Habit:

  1. Set aside a dedicated time and place for the habit.

  2. Start with small achievable goals.

  3. Practice regularly.

  4. Seek help and feedback.

  5. Stay organised.

  6. Reward yourself.

Image description

Thanks for reading this.

If you have an idea and want to build your product around it, schedule a call with me.

If you want to learn more about DevOps and Backend space, follow me.

If you want to connect, reach out to me on Twitter and LinkedIn.

Top comments (6)

Collapse
 
matkasur profile image
Info Comment hidden by post author - thread only accessible via permalink
Matkasur

package progusingjava;

//DO NOT MODIFY THE CODE PROVIDED TO YOU

public class Student {
private static int counter = 100;
private String studentId;
private String studentName;
private String studentLocation;
private long contactNumber;
private double totalFee;
private MusicInstrumentCourse musicInstrumentCourse;
private boolean transportationRequired;

public Student(String studentName, String studentLocation, long contactNumber,
        MusicInstrumentCourse musicInstrumentCourse, boolean transportationRequired) {
    this.studentName = studentName;
    this.studentLocation = studentLocation;
    this.contactNumber = contactNumber;
    this.musicInstrumentCourse = musicInstrumentCourse;
    this.transportationRequired = transportationRequired;
}

public String getStudentId() {
    return this.studentId;
}

public String getStudentLocation() {
    return this.studentLocation;
}

public double getTotalFee() {
    return this.totalFee;
}

public boolean validateStudent() {
    if (("" + this.contactNumber).length() == 10 && this.studentName.length() >= 3) {
        return true;
    }
    return false;
}

// To Trainees
public void generateStudentId() {

    String coursePrefix = this.musicInstrumentCourse.getInstrumentCourseName().substring(0, 2).toUpperCase();

    String studentId = coursePrefix + ++counter ;

    this.studentId = studentId;

}

public double calculateInstrumentFee() {
    double instrumentFee = 500.0;
    if (musicInstrumentCourse.getInstrumentCourseName().equalsIgnoreCase("Piano")) {
        instrumentFee += 1500.0;
    } else if (musicInstrumentCourse.getInstrumentCourseName().equalsIgnoreCase("Drum")) {
        instrumentFee += 1000.0;
    } else if (musicInstrumentCourse.getInstrumentCourseName().equalsIgnoreCase("Guitar")) {
        instrumentFee += 750.0;
    }
    return instrumentFee;
}

// To Trainees
public void calculateTotalFee(TransportFacility transport) {
    double paidParkingFee = 0.0; 
    if (validateStudent()) {
        if (this.musicInstrumentCourse.getCourseDuration() > 1) {
            this.musicInstrumentCourse.calculateCourseFee();
            double courseFee = this.musicInstrumentCourse.getCourseFee();

            if (courseFee != -1.0) {
                double instrumentFee = calculateInstrumentFee();

                if (this.transportationRequired) {
                    double transportationFee = transport.identifyTransportFee(this.studentLocation);

                    double totalFee = instrumentFee + transportationFee + paidParkingFee + courseFee;
                    this.totalFee = totalFee;
                } else {
                    paidParkingFee = 300.0;

                    double totalFee = instrumentFee + paidParkingFee + courseFee;
                    this.totalFee = totalFee;
                }

                generateStudentId();
            } else {
                this.totalFee = -1.0;
                this.studentId = "NA";
            }
        } else {
            this.totalFee = -1.0;
            this.studentId = "NA";
        }
    } else {
        this.totalFee = -1.0;
        this.studentId = "NA";
    }

}

@Override
public String toString() {
    return "Student (studentName=" + this.studentName + ", studentLocation=" + this.studentLocation
            + ", contactNumber=" + this.contactNumber + ", musicInstrumentcourse=" + this.musicInstrumentCourse
            + ", transportationRequired=" + this.transportationRequired + ")";
}
Enter fullscreen mode Exit fullscreen mode

}

Collapse
 
matkasur profile image
Info Comment hidden by post author - thread only accessible via 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

}

Collapse
 
matkasur profile image
Info Comment hidden by post author - thread only accessible via 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

}

Collapse
 
perses05 profile image
Info Comment hidden by post author - thread only accessible via permalink
Perses05

jaldi kar brooo

Collapse
 
perses05 profile image
Info Comment hidden by post author - thread only accessible via permalink
Perses05

I$_QNP2!9L

Collapse
 
perses05 profile image
Info Comment hidden by post author - thread only accessible via permalink
Perses05

hi

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