DEV Community

Lars
Lars

Posted on • Edited on

Week 2 β€” Backend x DevOps | Java and Git/GitHub

This week's achievements πŸ†

  • Completed 31 exercises from Exercism's Java track
  • Built a simple calories calculator app in Java
    • GitHub logo larsb-dev / caloriescalculator

      A simple CLI tool to help you calculate your Total Daily Energy Expenditure (TDEE)

      CaloriesCalculator Java CLI Tool

      Abstract

      This is my very first simple Java CLI Tool as part of my Backend x DevOps journey. Its purpose is straightforward β€” calculate a person's Total Daily Energy Expenditure (TDEE).

      How it works

      After running the app, the user is prompted to type their name, sex, weight, height, birth year and activity level into the CLI. Once the user inputs are all validated, they are used as arguments to instantiate a Person object.

      The Person object is then passed as an argument to a previously instantiated CaloriesCalculator object, whose calculate() method returns the user's TDEE. The value is stored in the Person object.

      Algorithm to calculate calories

      Before diving into this project it was necessary to understand how to calculate a person's calories accurately.

      The process consists of three steps:

      1. Calculate the BMR (calories needed for basic bodily functions)
      2. Determine the activity level
      3. Calculate…
  • Practiced Git and GitHub

Last week, I said I’d focus on learning JavaScript as my main language for backend development. However, I’ve realized that it actually makes more sense to focus on Java and Kotlin, since I already have some experience with them. What matters most is consistently focusing on one language for a period of time and solving lots of problems to develop the "programming mindset". I will explore Spring and Ktor web frameworks.

Did I achieve my other goals?

  • Learn HTTP on MDN Web Docs β†’ essential for REST APIs ❌
  • Write a blog post about how to use Python for network automation ❌

I haven’t yet achieved these two goals. The reason is that I’ve been focusing on solving as many Java coding challenges as possible and improving my skills with Git/GitHub. Tackling APIs right now would be a bit too early.

The blog post about Python for network automation is related to a school project. I’ll write it next week, as I finished the class diagram and refactored the Python code this week.


Learnings 🧠

My first Java app

CaloriesCalculator class diagram

I started by designing my app with a UML class diagram. This helped me visualize the relationships between my classes.

The application follows an object-oriented design approach, and I made sure to prioritize input validation as I developed the CLI application.

Β Excerpt from the CliApp class

public class CliApp {

    public static void main(String[] args) throws IOException {

        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        CaloriesCalculator caloriesCalculator = new CaloriesCalculator();

        try {

            String name;

            while (true) {
                System.out.println("Please enter your name:");
                name = formatString(bufferedReader.readLine());

                if (checkName(name)) {
                    break;
                } else {
                    System.err.println("Not a valid name β€” allowed letters: [A-Za-z]");
                }
            }
Enter fullscreen mode Exit fullscreen mode

Possible Future Improvements

  • Write custom exceptions instead of using System.err.println("");
  • Add the option to choose caloric deficit or surplus depending on weight goal
  • Test the app with unit tests
  • Deploy the app to run inside a Docker container in the cloud
  • Add a more advanced CLI tool with picocli

Goals for next week 🎯

  • Write a blog post about how to use Python for network automation
  • Continue solving Java problems (I can't specify an exact number, as I don't know how long each of them is gonna take me)
  • Finish a Git/GitHub course and after that use Git "daily"

Top comments (0)