CS 102 (Spring '09)
[Schedule] [Programs] [Notes & Reference] [Examples][Syllabus] [Lab & TA] [Tests] [Grades]

Program #1: TwentyFour

Prof. Reed, CS 102, Spring '09
Due Monday 1/26 at 1:00 p.m.


Write a program in Java to play the game of "TwentyFour." ( Idea taken from the card game called TwentyFour.) Running your program will look something like what is shown below, where user input is shown in bold:

Author: Dale Reed 
Program: #1, TwentyFour 
TA: Englebert Humberdink, T 4-5 
Jan 13, 2009

Welcome to the game of TwentyFour.  Choose one of the sets of 4 numbers below .
You then need to use each of those four numbers exactly once, combining them somehow 
with the basic mathematical operators (+,-,*,/) to yield the value twenty-four. 
Possible sets of 4 numbers are: 
   8         5         7         5          9         8      
 5   1     1   1     8   8     9   4      2   2     6   4    
   8         6         2         3          5         2      

Please enter the first number: 8
Enter the operator to be used (+,-,*, or /): -
Enter the next number: 5
That gives: 3

Enter the operator to be used (+,-,*, or /): *
Enter the next number: 8
That gives: 24

Enter the operator to be used (+,-,*, or /): /
Enter the next number: 1
That gives: 24

Well done, genius! 

Would you like to play again (Y/N): Y

Possible sets of 4 numbers are: 
   8         5         7         5          9         8      
 5   1     1   1     8   8     9   4      2   2     6   4    
   8         6         2         3          5         2      

Please enter the first number: 5

You need to know the following concepts in order to write this program:

How to use BlueJ, simple input and output, using variables, simple if statements, assignment statements, how to copy your solution over to your UNIX account, using turnin.


  1. Make sure you have read the first couple of chapters of the book before starting this assignment. You may also need sections of chapter 3.
  2. Make sure you read the syllabus regarding the grading criteria. Particularly on the first program, students tend to lose points for not documenting adequately and for not choosing meaningful variable names.
  3. See this sample program, which gives you a good starting point, as well as illustrates various concepts you need for this program.
  4. Remember to include your TA's NAME and your LAB DAY in the documentation header of your programs AS WELL AS in the output that appears on the screen.
  5. Do not be deceived. This is considered to be an easy program, compared to what is to come in the course.
  6. Transfer your program into your CS account. Note that your CS account information is posted outside the elevators on the 9th floor in SEO, and also posted on the wall in the CS lab at 2260 SEL.
  7. You may not use additional methods (that's what groupings of lines of code are called) for this program. All your code must be in one method, as shown in the sample program.
  8. Turnin your program electronically using the "turnin" command from your CS account. You should have already done this once in your first lab. If you missed this for some reason, please look at the web site "Lab & TA Info" page, which links to the content done in the first lab. The turnin command should be used as follows:
  9. turnin -c cs102 -p program1 twentyfour.java
    where the file containing your solution is called twentyfour.java .    To practice using the turnin command you can use the project named "junk" (rather than program1 in the example above.). Do not name your program anything besides twentyfour.java

    If you want to verify that your project was turned in, look in the turnin directory for a file with your userid. For instance for this project, from your CS account you would type:
    ls -l ~i102/submit/program1

Note that you can execute turnin as many times as you would like, up until the program deadline when turnin will be disabled for this project. Each time you execute turnin for a project, you overwrite what you had turned in previously for that project. For this first program only, and only if you do not yet have an cs account, you may email your solution to your TA. Note that emailing your solution rather than using turnin may significantly delay the grading of your assignment.

[CS Dept] [UIC] [Prof. Reed]