Tonight, I sat down to start my Java regimen. I opened up my book to where I had left off the night before, and I started reading the code in the book and writing it up on Eclipse. For the past few weeks, this simple regimen has been effective. However, as I’ve learned from my time in the gym, our muscles get used to regimens. To help keep myself engaged and to avoid that rote mechanical feeling, I need to change things up. So, I did. Here is what I did.
To start, here is the example code from the book:
Naturally, the first step is for you to read the code. But, to read the code you have to constantly ask, what is going on here?
On line 1, the code is importing the Scanner class, this signals to us that the User will provide some information. Lines 11 and 12 show us that the program is going to use two integer variables: number, and maxValue. Reading on, we see the scanner object, keyboard, is created on line 18 before prompting the user to enter a value to be stored in the maxValue variable. The program is going to set up a table that is going to show, on one side, a number, and then right across, after a couple of tabs, its perfect-square.
From lines 27 to 31, we see the for-loop. Here the first variable, number, is used as the loop control variable and is initialized to 1. Right after, is the condition for the loop: the loop is going to cycle through the values, from 1 to the value less than or equal to the maxValue the user will provide. Finally, the program will increment the number variable. Basically, this for loop is going to help create the perfect-squares table by showing a number and then calculating and displaying its perfect square all the while repeating until the loop reaches the maxValue at which point the loop and the program ends.
Not too bad; it’s an easy code to read.
Now that I know what the program is doing, I ask myself, what would be one simple specification that a client would possibly provide me when asking me to create such a program?
I came up with this:
What did I just do? What is so great?
Well, I think what I did was first obviously read the code, but then, more significantly, I broke down the program to identify its parts. In doing so, I made a simple algorithm that is at the heart of the program.
At first, this all seems like a lot of work, but it’s work that my brain muscles need to get used to.
Passively writing and rewriting code is a good gateway exercise, to help develop the habit of sitting down and coding. In my years of studying literature, that first step is actually part of three stages to reading and writing. This first stage is called the textual stage where you’re learning to read, write, and decode texts.
Now, as this blog post exemplifies, I’m ready for the next stage, and my it’s actually my favorite stage: The Analytical.
Hi there, thank you for reading my blog post. If you liked what you read, please give this post some love by clicking on the WordPress Like button. And, if you have any comments, questions, and or concerns about anything, I invite you to post a reply in the comment section below.