CSCI 161 — Lab 3
Due: Tuesday, September 19, 2017 @ 10:00AM
Objectives
- Write a Java Project from scratch
- Learn how to declare and use variables
- Learn how to use arithmetic expressions to perform a non-trivial computation
- Use good naming conventions when creating variables
- Leverage your improved knowledge of the Java programming language to produce the desired output
Overview
- Given a time in seconds, convert it to days, hours, minutes, and seconds
- Use a variable with an initial value of 2,693,793 seconds.
- Ensure your program works by testing many other values, but submit the version with the number above assigned to the appropriate variable.
- Do not use methods other than
main
- You must use the modulus operator (
%
) in your solution
- Name your Java file
TimeBreakdown.java
Style
Use good programming style:
- Write comments
- Choose mnemonic, meaningful variable names (e.g. seconds, minutes)
- Indent consistently (
Ctrl+Shift+F
will format your code)
- Remember the comment block at the top of your program
Input Specification
No user input is required. the value 2693793
should be "hard-coded" into the program. Do not accept any user input for the version you submit, and ensure the version submitted has the value specified.
Output Specification
Use PRECISELY the format shown below with the EXACT same spacing. Note: the output below is for an initial value of 104,442
seconds.
A time of 104442 seconds is equivalent to
1 day(s)
5 hour(s)
0 minute(s)
42 second(s)
Hints and Reminders
- Use only variables and expressions of type int
- Try to factor expressions into variables where appropriate
- You will want to update variables to new values in addition to declaring new variables
- In my reference solution, I declare 6 variables. We know that one is the input (in seconds) and four represent the output (days, hours, minutes, seconds)
- Do NOT make complicated expressions. All expressions should be in the form:
a = b op c;
where a
and b
are variables and c
is a number
- Use the remainder (modulus
%
) operator. Think about how to calculate the output seconds from seconds, minutes from seconds, etc.
- Add some meaningful comments that indicate what you are calculating at various points
- Do NOT forget your top comment block with filename, name, date, course, and description
- Ensure your program works for any number of non-negative seconds, including 0
- Create a new project for this lab. If you forget how, review Lab 1
Submission
Submit the Java source code file on Autolab under the "Lab 3" assignment.
Grading
- 20 points will be awarded for having a well-formatted, well-documented source code file. This includes your name, date, description, and comments throughout the program. This also includes other style requirements, such as method naming conventions. NOTE: The autograder will not display these points.
- 40 points will be awarded for matching the desired output
- 40 points will be awarded for an efficient calculation of each unit (e.g. days, hours, minutes, seconds). Using extra variables or not enough variables will result in a point deduction.
- NOTE: if your program does not compile/run, the highest score you will earn will be a 20/100