Java / Learning / stream

Java Post 1: Gumballs per Kid

As described in my previous post I will be working through this book and the examples within it, showing the development of my thought process. The idea is to take selected tasks and write my own programs before looking at how the author does it.

IMG_5535

Above you can read the task given. In addition to this the author had written that he wants a full number of gumballs rather than a fraction, as they are hard to share. This is why I have used “int”.

Screen Shot 2017-06-21 at 09.02.34

After playing around for a short while I came up with the following program, which works and displays the information in a short and concise manor, allowing the user to work through it in a very straightforward fashion.

Screen Shot 2017-06-21 at 09.03.36

Above is the version of the author. While I have an extremely limited experience with programming, it feels like he is making the program needlessly complicated as well as the outcome not being particularly user friendly. While it is nice that the answer is encased in a full text, the fact that you are writing two numbers straight after each other following two questions could easily lead to confusion. To top it off his program is also a line longer.

I am happy with my first written program. It felt really good that it was very easy, worked and was even shorter than the author’s example. Needless to say, I look forward to doing more.

One thought on “Java Post 1: Gumballs per Kid

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s