Program Development

There are several full length programs in the book. I would like you to write (copy) these pieces of code and get them to run. Each program will be in a file by itself with .java extension. Your code must have the following template:

/*

File:

Description:

Name:

Date:

*/
You must make sure that the following programs run as shown in the book.

After you have made sure that all the programs run on the command line, zip all the file stogether into a single file called:

myuteid_chap_2.zip
Substitute your UT EID for the place holder myuteid in the file name. Upload the zip file to the turnin system. Do not upload the files individually. We must receive the zip file by 11 PM on Wednesday, 26 June 2013.

Is this an Algorithm?

Lynne and Calvin are trying to decide who will take the dog for a walk. Lynne suggests that they flip a coin and pulls a quarter out of her pocket. Calvin does not trust Lynne and suspects that the quarter maybe weighted (meaning that it might favor a particular outcome when tossed) and suggests the following procedure to fairly determine who will walk the dog.

  1. Flip the quarter twice.
  2. If the outcome is heads on the first flip and tails on the second, then I will walk the dog.
  3. If the outcome is tails on the first flip, and heads on the second, then you will walk the dog.
  4. If both outcomes are tails or both outcomes are heads, then we flip twice again.
Calvin's technique is an algorithm.
a) True
b) False.
You do not have to submit this answer.

Write Algorithms for these Problems

You do not have to submit these answers.

  1. How would you add a list of numbers on the computer?
  2. How would you find the largest number in a list of numbers without sorting?
  3. How would you find the number of occurrences of a given number in a list of unsorted numbers? You may sort if want to.

Number Conversions

You do not have to submit these answers.

  1. Convert the following numbers in decimal to 8-bit 2's complement binary: 28, -39
  2. Write the binary equivalent of all numbers from 0 to 15 in 4-bit binary.
  3. These are 8-bit 2's complement binary. What decimal numbers do they represent?
  4. The hexadecimal number B4 is a 2's complement number in 8-bit binary. Convert it to decimal.
  5. Add 3D and F5 and express the answer in octal.
  6. Add 517 in octal to 3A in hexadecimal and express the answer in decimal. [Hint convert both numbers to binary and add.]
  7. Add the following 2's complement 8-bit numbers: 1011 1001 and 1110 0110. Ignore the overflow bit. Express the answer in decimal.