Homework 03
Version 1

 

Due by 8:00 AM on Monday, September 20, 1998

This assignment consists of three problems that require you to work with variables, user input, output, and simple arithmetic.

Notice that this assignment specifies required names for your program. If the required name is Conversion1, then your code file should be named Conversion1.java and the class name in your code should be Conversion1. We will insist that you follow the specified names because variable file names makes the graders' job very difficult.

  1. Write a program named Conversion1. Prompt the user to enter a number of years and days. Tell the user how long that is in minutes and how long that is in seconds. You should assume that years are 365.25 days long, but you should use ints for all your variables. Be careful how you account for that extra quarter day per year. Here is a sample run:
    How many years? 1
    How many days? 3
    
    That is 530280 minutes, or 31816800 seconds. 
    

    In a comment at the end of the program, explain, if you can, what causes the strange change in results between 68 years 18 days and 68 years 19 days.

  2. Write a program named Conversion2 Prompt the user for a number of seconds. Tell them how many days/hours/minutes/second it is. Here are a few examples:
     How many seconds? 3600
     
    That is 0 days, 1 hours, 0 minutes, and 0 seconds.
     
     
    How many seconds? 31816800
     
    That is 368 days, 6 hours, 0 minutes, and 0 seconds.
     
     
    How many seconds? 537462
     
    That is 6 days, 5 hours, 17 minutes, and 42 seconds.
    

  3. Write a program named Dice which simulates a throw of a pair of dice. That is, it generates and reports two random integers from 1 to 6 and their sum.

Last modified August 23 for Fall 99 cs5 by fleck@cs.hmc.edu


This page copyright ©1998 by Joshua S. Hodas. It was built with Frontier on a Macintosh . Last rebuilt on Tue, Sep 8, 1998 at 10:08:22 PM.
http://www.cs.hmc.edu/~hodas/courses/cs5/week_03/homework.html