Lecture notes for the Introduction to Computer Science II by James Tam Return to the course web page

CPSC 233: Assignment  1

Part I: Binary number representations (25 marks)

Conversions to/from binary (8 marks: half marks for the correct answer, half marks for showing your work1)

  1. 100102 (binary) to decimal.

 

Your answer:

  1. 1011.012 (binary) to decimal.

 

Your answer:

  1. 2510 (decimal) to binary.

       

Your answer:

  1. 12.510 (decimal) to binary.

 

Your answer:

 

Binary additions (4 marks: half marks for the correct answer, half marks for showing your work1)

   101000   101011  
  +010111   +010110  
Binary result        

 

 

Conversions to/from regular binary and twos complement (3 marks)

Original value

Converted value (you fill in)

 010010 (regular binary)                               (twos complement)
-010010 (regular binary)                               (twos complement)
100101 (twos complement)                               (regular binary)

 

Subtractions using the twos complement negate and add technique with 4 bits (10 marks = 5 marks per question x 2 questions. For each question you get 1 mark for the value in binary, 1 mark for showing the value as a twos complement bit pattern, 1 mark for the decimal value and 2 marks for showing your work1)

  510
- 710
Show your work here:

 

 

Answer (Twos complement):

Answer (Binary):

Answer (Decimal):

 

710
- 310
Show your work here:

 

 

Answer (Twos complement):

Answer (Binary):

Answer (Decimal):

 

 

Part II: Introduction to Java Programming (25 marks)

New Concepts to be applied for the assignment

  1. Program documentation
  2. Formulas
  3. Decision making
  4. Looping

Determining your fundex rating

Ever wonder how fun a person you are, here's your chance to find out by determining how you rate on the fun index scale "the fundex".2

Your program will ask the user three questions.  For each question a numerical 'modifier' will be calculated, each of the three modifiers will be used to calculate the overall fundex rating.

1) The person's age

2) The person's house or apartment number.

3)  The person's pet

1) Age

This value must be a positive integer between 1 and 113 (inclusive).  The age modifier will be the remainder of dividing the person's age by 100. If the user enters a value outside of this range then the program should provide an error message and assume that age is the default of 27.

2) Address

The person enters in a positive integer between 1 and 9999 (inclusive).  If the user enters a value outside of this range then the program should provide an error message and assume a default address of 4944.

The  address modifier will be equal to the remainder of dividing the address by 100.

3) Type of pet

Finally the person must indicate what type of pet that he or she owns, the values for the pet modifier are shown in the table below. If the person does not provide one of these answers then the program will automatically set the as a default value "no pet" so that the pet modifier will be set to 2. (That means that the variable storing the pet information should indicate that the person does not have a pet and the pet modifier should be determined from this value and an error message should be displayed). To keep it simple the program should accept the user's input as a single character e.g., 'n' for no pet but it should be able to handle lower or upper case values. (Run the sample executable to see how this is supposed to look).

Pet

Pet modifier
No pet 2
Fish 5
Dog 6
Cat 7
Reptile 8
Other 9
Multiple pets 10

The fundex generator will perform a calculation that is based on the answers to these three questions:

    Fundex = (age modifier + address modifier) * pet modifier

The program will then display the numerical fundex value as well as providing a text description of what the numbers mean:

Fundex value Description  
000 - 499 What a bore!
500 - 999 A genuinely fun person.
1000 - 1499 A real wit.
Over 1500 A party animal!

Finally the program will employ a loop so that each time that a calculation has been performed the program will prompt the user if he or she wishes to run the program again or if they want to exit the program.

Submitting your work:

  1. Assignments (source code/'dot-java' files) must be electronically submitted according to [the assignment submission requirements].  For this particular assignment you will have to submit a paper hard copy of Part I in the assignment drop boxes (second floor Math Sciences).
  2. As a reminder, you are not allowed to work in groups for this class. Copying the work of another student will be regarded as academic misconduct (cheating).  For additional details about what is and is not okay for this class please refer to the following [link].
  3. Before you submit your assignment to help make sure that you haven't missed anything here is a [checklist] of items to be used in marking.

 

External libraries that can be used

  1. Libraries that allow for text-based (console) input and output.

Sample executable

 

1 As a guideline for how much work to show for your conversions use the same level of detail that I show in my examples during lecture.

2 Note: The fundex is to be used for entertainment purposes only and neither I nor the University of Calgary provides any express or implicit guarantees that the numbers generated will actually predict your success at social interactions.