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

CPSC 233: Assignment 1(Worth 2%)

 

Due Wednesday January 28

Writing a lucky number generator

Some people believe that there are some specific numbers that provide them more luck than other numbers.  For example, we all have heard of people who pick the same lottery numbers every week because they believe that these numbers will provide them with a higher probability of being able to win.  For this assignment you are to write a program that will ask the user a series of questions and generate for the person their very own "lucky number".1

Your program will ask the user four questions:

1) The person's age

2) The person's favourite primary color

3) The person's gender

4) The person's current level of education

1) Age

This value must be a positive integer between 1 and 113 (inclusive).  This value will stored as-is in an integer variable and is used to determine the modifier resulting from the person's age.

 

2) Favourite primary color

The person will be able to pick their favourite of the following three colors:

Color

Color modifier

Red 15
Blue 20
Green 10

1 Note: The Lucky Generator program is to be used for entertainment purposes only and neither I nor the University of Calgary provides an express or implicit guarantees that the numbers generated will provide you with greater financial profit or personal gain.

 

3) Gender

Gender

Gender modifier

Male 73
Female 79

 

4) Current level of education

For this question the program will ask the person to indicate the level of education that the person currently enrolled in or the highest level that has been completed (if the person is not currently a student).

Level of education

Education modifier

High school

12

Undergraduate post-secondary

16

Graduate: Masters program

18

Graduate: Doctoral program

21

The lucky number generator will perform a calculation that is based on the answers to these four questions:

    Largest lucky number = The remainder of (age modifier x gender modifier) modulo (color modifier x education modifier)

The lucky number will generated as a positive integer between zero and the value calculated in the previous line.   In the example shown below the value calculated will be:

    Largest lucky number = (113 * 79) Modulo (20 * 21)

                                      = (8927) Modulo (420)

                                      = 107

With these values the program will then generate a random value between 0 and 107 (inclusive).  You can generate a random number by using the pre-created code provided by Sun: class Random or Math.

 

Grading

Assignments that receive a "C"

These assignments perform everything up to and including the tabulation of the largest possible lucky number (601 in the example above).   This intermediate value will be displayed as the lucky number but it is not randomly generated and is based solely on the user's input.  This means that if the user provides the same answers for successive runs of the program Assignment submissions must follow good coding style and must be fully documented.   After performing one calculation the program will prompt the user to ask him or her if they wish to generate another lucky number:

The programs that are awarded a grade of "C" do not perform any error checking.

 

Assignments that receive a "B"

These assignments fulfill all of the requirements for a C-level submission and performs some rudimentary error checking:

1) Age must be an integer value between 1 and 113 years (inclusive)

2) The favourite primary color chosen must be of the following:

3) Gender must either be male (m) or female (f).

4) Currently level of education must fall into one of the following categories:

Your program must be to detect when the person enters in a value outside of the allowable ranges and provide a reasonable mechanism for dealing with the situation such as the one shown below:

It is however not expected that your program can determine if the person enters in the correct type of data  (e.g., at this point it's acceptable if your program crashes if the person enters a character instead of an integer).   

 

Assignments that receive an "A"

These assignments fulfill all of the requirements for B-level submission but randomly generates the lucky number.   This means that if the user types in the same values different runs of the program different lucky numbers may be generated.

First run of the program: Lucky number generated is 58.
 
Second run of the program, same input: Lucky number generated is 103.

 

Other submission requirements

In addition to having fulfill the generic assignment requirements the requirements specific to this assignment include:

1. Good coding style and documentation:  They will play a role in determining your final grade for this assignment.  Your grade can be reduced by a letter step (e.g., "A" to "A-" for poor programming style such as employing poor naming conventions for identifiers).

2. Include a README file in your submission:  For this assignment your README file must indicate what grade level has been completed (A, B or C).  This will allow your marker to quickly determine what he or she must look for and speed up the marking process.

3. Assignments (source code and the README file) must be electronically submitted via submit.  In addition a paper print out of the source code must be handed into the assignment drop box for the lab that you are registered in (located on the second floor of the Math Sciences building).  Electronically submitting the assignment allows your marker to run the code in order to quickly determine what features were implemented.  Providing a paper printout makes it easier for your marker to read and flip through your source code.

 

Sample Executable

You can out the sample byte code program called "Lucky.class" which can be found in Unix in the directory: /home/233/assignments/assignment1+2

 

New Concepts to be applied for the assignment

  1. Writing, compiling and running simple Java program
  2. Documenting programs
  3. Input and output
  4. Formulas
  5. Decision making constructs
  6. Loops