SE 475 Assignment 1

Joe Hughes - Sep 11 - - Dev Community

This is the first of several posts to go along with my assignment in SE 475 - Managing Globally Distributed Software Systems.

In this first assignment I was given the task of setting up my IDE, class github repository, creating this blog page, and developing a console application that calculates the nth sequence of the Fibonacci series.

Choosing an IDE

At the moment, I have experience using VS Code, IntelliJ, and Eclipse. VS Code I like the most for coding in Python and I use it the most on a daily basis. Especially for my personal projects. Eclipse isn't bad but I've used it the least out of the three by far and am just not as familiar with its features. However, when deciding on an IDE to use for this assignment and most likely future assignments, I chose IntelliJ. It has the ability to create a project and give you the necessary files for that project. For this assignment, which is fairly simple, I just needed to create a single main file that would run the application in the console. IntelliJ's project set-up feature is perfect for this because all I had to do was write my code in the given Main.java file and run it.

Setting up my github repository

This was super simple and straight forward. I already have experience with version controlling from a handful of different projects I have worked on. All I had to do was go to github, go to the class repo and create a private repo within it. Then I will be able to git init in my local project file path, commit changes, and push the changes to the repo.

Creating THIS blog

Included in the assignment was to create this blog page. I am currently working on my own portfolio website where I have a page dedicated to my blog posts. I wanted to use that initially for this, but I am still designing the UI of the website, so I chose my favorite developer-focused blog site dev.to. It makes creating posts super easy with mdx.

Developing the Fibonacci Sequence Calculator

The main task in this assignment was to create a console application where one can enter a number, n, as an index, and the nth value in the Fibonacci series would be printed. I first created the function main which would take an inputted number, n, run the function to calculate the value in the Fibonacci series, and then print the returned value. I utilized the java.util.Scanner to that scans the input parsing through any whitespace or delimiters. Then .nextInt() checks that the scanned input is an int. Essentially these two utils combined allows me to read numbers from the input and immediately have them as an int data type.

public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.print("Enter the sequence index (n) to calculate the Fibonacci number: ");
        int n = scanner.nextInt();

        long result = calculateFibonacci(n);

        System.out.println("The " + n + "th Fibonacci number is: " + result);

        scanner.close();
    }
Enter fullscreen mode Exit fullscreen mode

The next function I wrote was calculateFibonacci. It takes the argument int n which is the inputted value representing the position in the Fibonacci series we want to calculate. It checks if n is equal to 0 or 1, returning n if it is true as these are the first two cases of the Fibonacci sequence. Then it stores the i-2 value as prev, the i-1 value as current, and i value as next. These variables are then used to iteratively calculate the nth Fibonacci value. Using a for loop, it calculates the next Fibonacci number by adding prev and current. Updates prev to be the previous current. Updates current to be the newly calculated next value. Then after the loop concludes, returns current representing the nth Fibonacci value. I used this approach because it has a time complexity of O(n), where as the alternative recursive approach has a time complexity of O(2^n).

    public static long calculateFibonacci(int n) {
        if (n <= 1) {
            return n;
        }

        long prev = 0;
        long current = 1;

        for (int i = 2; i <= n; i++) {
            long next = prev + current;
            prev = current;
            current = next;
        }

        return current;
    }
Enter fullscreen mode Exit fullscreen mode

I then put the two functions with in the class FibonacciSequenceCalculator.

This is the full code.

import java.util.Scanner;

public class FibonacciSequenceCalculator {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.print("Enter the sequence index (n) to calculate the Fibonacci number: ");
        int n = scanner.nextInt();

        long result = calculateFibonacci(n);

        System.out.println("The " + n + "th Fibonacci number is: " + result);

        scanner.close();
    }

    public static long calculateFibonacci(int n) {
        if (n <= 1) {
            return n;
        }

        long prev = 0;
        long current = 1;

        for (int i = 2; i <= n; i++) {
            long next = prev + current;
            prev = current;
            current = next;
        }

        return current;
    }
}
Enter fullscreen mode Exit fullscreen mode

Expectations for this class

I already have some experience with development in global environments, although it has been of my own ambition. I am excited to have a structured learning process so that I can gain all the necessary information about software development in global environments to improve my developing efficiency, knowledge, and skill.

.
Terabox Video Player