600.107 Introduction to Programming in Java
Homework #2 - Due by 11:30pm on Thursday, 9/21

Overview

The goals of this assignment are to: A) install and learn to use some more programming tools, B) understand good programming style, C) use numerical data types and arithmetic operations correctly, and D) convert pseudocode to Java code, writing a complete program. You'll need to download our posted HW2start.zip file to get the files necessary to do several parts of this assignment.

Deliverables: Your final submission on blackboard must be a single zip file called HW2.zip that contains the following files from all parts of the assignment: Hw2a.pdf, HomeworkB.java, Formulas.java, and Hw2d.java. Remember that you can submit multiple times on Blackboard, but that we only grade the last one. Therefore, make sure that your final submission includes all 4 parts!


Part A: More jGRASP

Continuing your exploration of jGRASP and the java language, you have several things to do for this part of the assignment. As you do them, you will be creating a text document to submit.

Create a pdf document named "Hw2a.pdf" that has a short reflection on the checkstyle installation and learning to use the debugger. The document must also include ordered lists of the values that the main variables took on when tracing the debug program, and a copy of all the checkstyle errors that were generated. You not required to fix the checkstyle errors for this program, but may find it helpful practice to try.

Part B: Checkstyle

For this part of the assignment you will take your understanding of checkstyle a step further by making a program compatible with our style guidelines. This means that when you are done with it, there won't be any more checkstyle errors. The program to use is version B of the homework grade calculation, included in the assignment zip for convenience (HomeworkB.java). This file has has 5 types of style errors: missing period, indentation, operator spacing, magic numbers, missing {}. You must fix every instance of each error type. (Hint: use the jGRASP control structure diagram to fix most of the indentation for you: just turn it on!) Submit the fixed file, which should still be named HomeworkB.java.

Part C: Formulas

Now you will write some arithmetic statements to complete a few functions that have been written for you already in Java. Here you will use the file FormulasStart.java. The first thing you'll need to do is change the name of the file to Formulas.java so that it compiles. Then you should follow the instructions to write the necessary formulas so that each function does what it is supposed to do. We will do the first one in class together. When you run the program, it will create some output that will show you if your formulas are correct or not. You are strongly encouraged to add some tests of your own. This file is not required to be checkstyle compliant!

Part D: Time Flies

Write a program that is a Java version of the elapsed time pseudo-code we traced in class (day 2, slide #28). You must change the prompts somewhat so that they ask for starting hours and minutes, and then also elapsed hours and minutes. Your program should then compute and output the finish time (using a 24 hour clock) in hours and minutes. Call your program Hw2d.java. Your your program should be fully checkstyle compliant. Here is a sample run:

    Enter starting time in hours and minutes: 14 30
    Enter elapsed time in hours and minutes: 9 100
    The finish time in hours and minutes is: 1 10
    

As an extra challenge you can try doing several things: 1) print the output in standard time (12-hour clock) with the "am" or "pm" notation, 2) print the output in HH:MM format with exactly two digits for the minutes, 3) read the input in HH:MM format. You will need to look up some Java things we haven't yet covered for the challenge.

Here are a few more sets of input and output you can use to test your program. However, you should definitely think of other cases on your own, work out the correct answers, and try them out. [Disclaimer: I figured these out in my head, so let me know if they seem wrong... :-)]

    Enter starting time in hours and minutes: 2 15
    Enter elapsed time in hours and minutes: 0 50
    The finish time in hours and minutes is: 3 5

    Enter starting time in hours and minutes: 8 47
    Enter elapsed time in hours and minutes: 10 73
    The finish time in hours and minutes is: 20 0

    Enter starting time in hours and minutes: 22 0
    Enter elapsed time in hours and minutes: 20 10
    The finish time in hours and minutes is: 18 10


General assignment requirements, style and submission details: