Wednesday, March 4, 2015

Warm up: 2

Task: Build an age checker to see if the user is 18 years old

Method 1: Using if/else statments

In this particular code I use if/else statements which became complex because I nested many if/else statements. Another problem with this method is that I had to input the date therefore, if I wanted to try this code out tomorrow it would not work because I would have to update the current date (Not Practical).        



 Method 2: Using Switch Statement and Date Class               
Image 1



Method 2 had more coding but overall simplified the complexity of the code. As well as reducing the complexity instead, of having to input the current date I used the Date class to automatically get and input the current date.

No comments:

Post a Comment