CS110 Java Programming Assignment #2

Instructor: Trish Cornez





  Instructions - Complete the following before the start of class:
  1. Code, debug, comment, and print the source code for each program. All programs must contain your name, date, a program message, and code comments. Points will be deducted on programs that are not well coded and commented and pages that are unstapled.
  2. Execute each program three times with the input supplied. Program 6 should execute just once.
  3. Print the snapshots from all executions.



PROGRAM 1:
Angles are often measured in degrees, minutes, and seconds. There are 360 degrees in a circle, 60 minutes in one degree, and 60 seconds in one minute. Write a program that reads two angular measurements given in degrees, minutes, and seconds, and then calculates and prints their sum. Constants are required for this program.

Use your program to verify the following :

Measurement #1
        Enter the degrees: 74
        Enter the minutes: 29
        Enter the seconds: 13

Measurement #2
        Enter the degrees: 105
        Enter the minutes: 8
        Enter the seconds: 16
The sum of measurement #1 and measurement #2 is 179 degrees, 37 minutes, and 29 seconds

Measurement #1
        Enter the degrees: 7
        Enter the minutes: 14
        Enter the seconds: 55

Measurement #2
        Enter the degrees: 5
        Enter the minutes: 24
        Enter the seconds: 55
The sum of measurement #1 and measurement #2 is 12 degrees, 39 minutes, and 50 seconds

Measurement #1
        Enter the degrees: 1
        Enter the minutes: 17
        Enter the seconds: 48

Measurement #2
        Enter the degrees: 237
        Enter the minutes: 42
        Enter the seconds: 12
The sum of measurement #1 and measurement #2 is 239 degrees, 0 minutes, and 0 seconds




PROGRAM 2:


The shipping clerk at the Redlands Handcrafted Bike Shop is faced with the following problem:

Write an interactive Java program that reads the number of handcrafted bikes to be shipped and prints the number of large, medium, and small containers needed to send the shipment in the minimum number of containers and with the minimum amount of wasted space.
TIP: Use contants for the number of bikes each size of container can hold.
Execute this program three times and use the following numbers for input: 3, 48, and 10598.

Here is an example of a possible run:


How many handcrafted bikes will be shipped? 26

You will need 2 large containter(s), 1 medium container(s), and 1 small container(s)




PROGRAM 3:


Write a program that performs long multiplication.
  1. Prompt the user for a three digit integer x
  2. Prompt the user for a two integer y
  3. Compute x multiplied by y using a similar display as follows:
    NOTE: Format for right alignment.




    PROGRAM 4:


    Write a program that prompts the user for their first, middle, and last names, in uppercase. Display number of letters in their name and their initials in lowercase.

    Example: Input
    SUE
    BORT
    THOMAS

    Output: You have 13 letters in your name and your initials are sbt



    PROGRAM 5:


    Assume that a robot is used to tile a floor with alternating black and white tiles. Write a program that yields the color (0 for black, 1 for white), given the row and column number. For example, given the following floor, if the user inputs row 1 column 2, the output will be 1 (white).





    PROGRAM 6:


    Write a program that does the following:
    1. causes a negative overflow of an int
    2. causes a positive overflow of an int
    Write a few words explaining your results.