COSC 236

Assignment 1

Due date: Tuesday, 03/03/2020

Make sure that you document the programs (add comments!) and use proper style (indent!) Remember Java naming rules discussed in Lecture 2 (class website).
For each program you will turn in the printouts with:

  1. The source file - Print the Java program using the DrJava editor: File --> Print
  2. The output window  - Print the output window using the Print Screen key from your keyboard, and then open a Word document and paste the image in that document. Next, print the Word document with the screen shot.

Please staple all pages together (a must!). You should also be prepared to make a demo of your programs if you are asked so.


1. Write a Java program that will ask the user to type in a number of seconds, and then convert that number into the appropriate number of hours, minutes, and seconds.

Sample output:

You entered 23569 seconds.
23569 seconds would be 6 hours, 32 minutes and 49 seconds.


2. Write a Java program that takes as input any change expressed in cents and computes the number of half-dollars, quarters, dimes, nickels, and pennies to be returned. Use as many half-dollars as possible, then quarters, dimes, nickels, and pennies, in that order.

Sample output:

The change you entered is 648.

The number of half-dollars to be returned is 12.

The number of quarters to be returned is 1.

The number of dimes to be returned is 2.

The number of nickels to be returned is 0.

The number of pennies to be returned is 3.

 



3. Write a Java program to calculate and print the monthly paycheck for an employee. The net pay is calculated after taking the following deductions:

    Federal income tax  = 15%
    State income tax    =  6%
    Social security tax =  5%
    Medicare/Medicaid   =  3%
    Pension plan        =  8%
    Health insurance    = $125.00

Your program should ask the user to input the employee ID, last name, first name, and the earnings (gross amount) for current month. The output should be the net pay, after deductions. Format the output to have 2 decimal places. NOTE: This assignment is all about formatting the output

Sample output:

Enter employee id #: 12345678

Enter employee first name: John

Enter employee last name:  Doe

Enter employee earnings: 4750

 

Employee id:                       12345678

Employee name:                    Doe, John

===========================================

EARNINGS:                           4750.00

Federal Tax:                         712.50

State Tax:                           285.00

Social Security:                     237.50

Medicare/Medicaid:                   142.50

Pension Plan:                        380.00

Health Insurance:                    125.00

===========================================

NET PAY:                            2867.50



4. Write a Java program to calculate the squares and cubes of all integers from 1 to 10. Align the printout as in the sample output. NOTE: This assignment is all about formatting the output.

Sample output:

Number       Square      Cube
=============================
     1            1         1
     2            4         8
     3            9        27
     4           16        64
     5           25       125
     6           36       216
     7           49       343
     8           64       512
     9           81       729
    10          100      1000