600.107 Introduction to Programming in Java
Spring 2013


Warm-up Assignment #4
Due: by 6pm on Wednesday, 3/6

Part A: (ungraded) Read Chapters 15, 5 & 6. Look at the review questions for each chapter. Recommended exercises to do on your own: 6.4 and 6.12. Write and run a JAVA program to check your answers. You are permitted to work together on any ungraded work for the course. Your midterm is Monday 3/4, Chapters 1-4, 11. There are practice tests on the main course webpage.

Part B: [5 points] Think about how you can break the program 4a below into smaller pieces. Write a one line description of each method (subroutine) that you will use when writing your solution. Submit this in a plain text file w4.txt on Blackboard.


Programming Assignment #4
Due: by 1pm on Wednesday, 3/13

Part A: Exercise Stats [45 pts]

The purpose of this assignment is to work with plain text files, random data generation and methods to decompose your code into small subroutines. The application is to create a log of exercise data, similar to what a person might write down throughout a month of activity. The program has two main parts: generating the data and processing data.

Note that throughout this assignment description we will use '[' and ']' to indicate inclusive range boundaries and '(' and ')' to indicate exclusive range boundaries. For example (10,15] means between 10 (exclusive) and 15 (inclusive). Also, unless otherwise specified random data for a particular distribution must be equally likely.

Generating Data: The first part of your program must randomly generate a number in the range [20,30] and then create data for that many different exercise logs. As it generates the data, it must write each entry to one line of a plain text file called "exLog.txt". Each log entry will start with a particular exercise type, followed by data particular to that type of exercising. The exercise types are "Running", "Biking", "Lifting" and "Dancing", and must be randomly generated. The accompanying data must be written to the file in the ordered specified below. [10]

Running: include number of minutes and miles covered in the log. The minutes must be an integer between [15,240] but with 75% probability that the value is between [15,60], 20% probability that it is (60,120) and 5% probability that it is [120,240]. Within each of those groups all values must be equally likely. The miles must be a generated in accordance with the minutes value so that the average speed is between 5.0 and 15.0 miles/hour. So randomly generate a speed with 1 digit of precision after the decimal point in the range [5.0,15.0). Then use it to calculate the mileage and write to the text file with 1 digit of precision after the decimal point (use standard rounding). [6]

Biking: include number of minutes and miles covered in the log. The data will be similar to that for running, but with different ranges. Here the minutes will be an integer between [30,90] with 50% probability and in the range (90,300] with 50% probability. The miles will be generated just like for running, but with average speeds ranging from [8,25). [6]

Lifting: include number of minutes, how many different exercises, and how many reps for each one. Randomly choose from between [2,15] different exercises and [10,45] reps for each. We will assume that on average each rep takes 5 seconds, plus there is a 2 minute gap in moving from one exercise to another. So the total minutes should be calculated as 5*reps*exercises/60 + 2*(exercises-1), rounded up. [4]

Dancing: include number of minutes and average beats per minute (bpms) of the music danced to. The minutes must range from [30,120] and the bpms should be a real number with one digit of precision between [80.0,220.0). [3]

Here is an example of one line for each different type of exercise:

Dancing 75 160.3
Lifting 35 10 20
Running 30 5.2
Biking 120 24.0

Processing Data: The second part of your program is to read some file that has the above format, and compute various statistics from the data. First of all, get the name of the file to read from user input. Note that the user must enter the full and exact name of the file, including any desired ".txt" extension. This part of the program could read the file created in the first part, or it could process any other file in the same format, so you will not know how many lines are in the input file. You must read and process the entire file. [5]

Processing requires the program to determine and display on standard output (the screen):

Implementation Details

The following requirements must be strictly followed in your actual program solution. Any violations will incur severe point penalties, even if your code works properly.

Helpful Hint: remember that any method which reads from or writes to a file should declare "throws IOException" in its header. Also, don't forget to use "close" to save a file when you are done writing output to it.


General assignment requirements, style and submission details: