I periodically teach an introduction to programming course using Java. I want to give my students some exciting assignments that they can relate to or find interesting. At the very least, I want assignments that make sense and have an internal cohesion (for example, some very bad programming exercises seem contrived just so that you have to use the most recent programming construct covered).

To give you an idea of scope, here's what's being covered:

  • The assignments must be in Java, using some external library can be done, but it would need to be a simple API and not a full framework
  • Variables, Primitives and Strings
  • Console input and output
  • if, for, while
  • Arithmetic and logical operators
  • Simple graphics with line and shape drawing
  • Static methods
  • One-dimensional arrays

The students will not go into advanced topics (e.g., no recursion, no emphasis on inheritance). Thus, I'm not looking for complex projects: "Have them write a C compiler. I did it when I was 5 and it was the only way I learned!"

If you have ideas that are more advanced than the scope, please post them on the "Challenging" question linked below, and not this one.

Instead, what I'm looking for are interesting ideas that can be accomplished in a short program. For example:

  • Students can write a console version of the "Star Wars Name" Generator. This is effectively reading Strings and using substring, but I think it's fun. A similar variation would be a "Mad Libs" program. I used this one five years ago, and perhaps it's already "stale."

  • Using some trig supplied to them, students can draw regular polygons, and create interesting spiral shapes.

  • It's also not out of the question to use some simple animation class with most of the code supplied to them. And if you know a Twitter or Facebook service that can be accessed with a simple API, I would be very interested to know.

Please note that this question is different from the "Challenging Java questions for beginners" Question. I'm not looking for challenging per se, just interesting. I think if students work on something where they can easily answer "why would anyone ever want to program that?" then they will learn better.

Even simple problems like computing Miles per Gallon can be good. Although, if there's a way to update it to be more relevant, all the better. If you have an exercise from somewhere else (a book or a website), please cite the source.

To help you think about the typical freshman today, check out the Beloit Mindset list, for many examples that will surely make you feel old.

  • Just out of curiosity, what level of students are you teaching that you think that topics like recursion and object oriented design are too advanced? These topics were covered in depth in my first semester, introductory programming class. I think you are doing your students a disservice if you try to keep the coursework too simplistic.
    – Mayra
    Nov 12, 2010 at 19:07
  • @Mayra: This is for the introduction to programming course, the first course for CS majors. I'm seeking exciting problems for students to use in the first 5 weeks (or even the first day), and not only at the end. It's a real challenge to work in these requirements (and believe me that some issues are out of my control), hence I'm turning to you guys for help.
    – Macneil
    Nov 12, 2010 at 21:51

17 Answers 17


Given the constraints, I'd suggest implementing a version of Hangman. It would allow for the students to demonstrate all of the techniques you are introducing them to, without being overly complex.

It can also be used as a developing project as the course progresses. e.g. once you have covered strings and variables starts out as a text version


You have 10 guesses left.      * * * E * * T
What is your next guess?

then introduce loops to remove the cut and paste element from the code as the 10 guesses count down... building up to having line graphics and the stick person being hung / saved at the end of the 5 week course.

Like most other people who have experience of recruiting and interviewing programmers, it really makes me cringe that this level of tuition is needed at university, but alas, it probably will continue to be needed until schools treat programming as a serious subject on a par with mathematics or sciences

  • Great idea! I think I'm going to use this one. :-) BTW, what do you mean by "level of tuition"? As in the costs?
    – Macneil
    Nov 21, 2010 at 7:01
  • Its more a gripe about the lack of programming tuition before university. Imagine arriving at University to do chemistry and spending the first term being told about atoms, molecules and electrons. 3 years is just too short a time to understand computer science. Nov 21, 2010 at 14:11
  • I really like this idea, no need for complex graphics, can be done on a command line reasonably well. It's fun and not yet another math problem solver.
    – Joppe
    Nov 23, 2010 at 13:12

Sounds like a text adventure game could be a terrific assignment somewhere mid semester. I had a class that made us play Colossal Cave Adventure and then make our own game. It taught me a lot of the basic constructs early on, and it was so much fun to do everyone got into it.

  • 2
    Sounds fun, but keep it small.
    – user1249
    Nov 14, 2010 at 10:05

How about using a problem or two from http://projecteuler.net/ Some of these are quite interesting and one could see the benefit of writing a program to solve them. They are small enough that several can be done as assignments. Another one that I've like to use is finding $1.00 words. Each letter in the alaphabet is worth its position in pennies i.e. a = 1, b=2. How many $1.00 dollar words can you find? This could involve file i/o (reading in a dictionary), arrays, looping etc.

  • 1
    +1 for Project Euler. Very cool. Although some of the problems are a little too advanced, there are many that aren't.
    – Macneil
    Nov 12, 2010 at 22:05
  • I love Project Euler but I'm not so sure if it would have been fun if I had to the exercises at university. Nov 13, 2010 at 10:56
  • No not all of them would be fun but some I think we be good choices
    – Gratzy
    Nov 13, 2010 at 15:41
  • Implement a Monopoly game. Monopoly has an obvious sequence and lends itself to division into funcitons very easily. It also only requires a one dimensional array and a few basic classes. The logic is simple enough so that the students will think more about "how" than "what", and it results in something that can be demonstrated to others.

  • Give them an encrypted file that was encrypted with some reversible rule and ask them to write a decoder (make it simple enough though). This gives an extra incentive to solve it because of the mystery about the message's content.

  • I don't know why you only cover one dimensional arrays and not matrices (they really aren't all that different), but if you are willing to include that into the sylabus Jon Conway's Game of Life is also relatively easy and results in something fun.

  • A game like chess requires some thought but is still within the confines of what a beginner can do with minimal inheritance (specific pieces inherit from a general class Piece, and the board holds objects of type Piece), and 2D arrays (you can choose to simplify it by not requiring to implement hard stuff like stelmate detection or inability to castle if an enemy pieces is threatening the castling path).

  • +1 for the Monopoly game suggestion. As for 2D arrays, I agree absolutely that they can lead to very interesting assignments. However, there are constraints that make it so 2D arrays aren't viable (e.g., the textbook is already fixed, and a billion other faculty politics issues that I will not bore you with, nor will I bore you with my personal opinion on these matters out of my control).
    – Macneil
    Nov 12, 2010 at 21:59
  • Ah, we had to create a monopoly game in school. And an encryption breaker.
    – Carra
    Nov 17, 2010 at 16:57
  • +1 for Monopoly. Once the students have it coded up, ask them to generate the probabilities of landing on the various properties. That knowledge really helps strategically.
    – joshdick
    Nov 23, 2010 at 15:40

We created quite a few projects with just i/o, functions and conditional operators in school. All done before we learned about object oriented programming. These projects advanced slowly to be more and more difficult. Suffice to say, the 4 hours we had each week weren't nearly sufficient towards the end of the year.

All these projects were done with just functions & i/o:

  • A game that learns. You take a number of sticks, the pc takes a number of sticks. Repeat. The last one who holds a stick looses. We had to create a simple self learning program that got better after each game. Good example to learn 2D arrays.

  • A code breaker. You know the Caesar encryption, pick a letter and add the value of the letter to each letter of your word. E.g. key = 'a' and the word = "secret". This would become "tfdsfq". Can be done by reading in the file and then creating a frequency table for each letter. You also read in an English bible. Then you can simply see that the most used letter in the English alphabet is an 'e' and solve it. Added challenge: use a key like 'ab' which was our assignment. Good exercise to understand i/o.

  • A barcode maker. This program was an exercise to call an external library. You got a code and had to generate an image with the bar code. An external library was used to generate the image.

  • A genetic algorithm to solve the traveling salesmen problem. This was a more advanced project for 2 or 3 persons. You start with a random route and this route improves all the time until you have a "good route". Bonus: create a map with the route.

  • A working lzw compression program. This was the final, 4 people project. The parameters were quite simple. "Zip file.txt file.zip" or something similar. Fun project but understanding the lzw algorithm took a while.

  • Very interesting... What school did you go to? Was this all in your first year?
    – Macneil
    Nov 18, 2010 at 2:25
  • It was a course to warm people for the informatics engineering specialization. You could still change your specialization after that year. The students did know basic loops, some i/o to the screen/files and functions.
    – Carra
    Nov 23, 2010 at 13:29

A calculator would be a good project for learning arithmetic operations. You can make it a simple menu-based console app, or a GUI. Four functions (+,-,*,/) to start, with extra points for more complex things like square root, etc.

For string handling, I'd suggest some validation problems. Email addresses come to mind - leaving them unchecked can lead to SQL injection holes, or other things, and they're relatively straightforward to validate. For appending, maybe have a program that can take first, middle, and last names and string them together with spaces, and also take a full name and parse it into each component. The first is used more than the second in real life, but I haven't been able to think of another parsing scenario that would be simple enough.

To demonstrate static methods, you could assign an email-lookup problem. Have a file of names and emails, and the static constructor could put the names/emails into a list, with a static method to find the email for a given name.

Hope these give you some ideas! Good luck with your class.

  • 1
    +1 Thanks! This is exactly the kind of answer that I'm looking for.
    – Macneil
    Nov 12, 2010 at 22:00
  • Games are more fun than calculators.
    – user1249
    Nov 14, 2010 at 10:05

One very interesting and cool thing for an assignment is writing an implementation of Conway's Game of Life in 2D. It maps very well to basic array data structures, it's fun and pretty easy to do, but still requires some thinking. It may open up some curiosity and experimentation as well (AI).

Advanced students can write a version in 3D for extra points.


I would iterate on a prime number generator.


  1. Print primes from 1 to 100.
  2. Print primes from input1 to input2.
  3. Record and print performance data of prime generation.
  4. Graph performance data of prime generation.
  5. Iterate on algorithm optimization of the prime number generator.

I'm using the ACM Library to help intro students do simple graphics and games. We've been able to do basic, two-player click-based games with nothing more than the skills you outlined. This week they are doing the Fox and Hounds game.

I've been trying to stay away from console I/O as long as possible. It's a foreign concept to many students these days, as they've all grown up with GUIs. So I focus on MVC, getting the model correct, and adding the GUI only after they've tested their model. Testing is done via automated unit testing and the Code Pad in BlueJ. No public static void main() is necessary, ever.

  • interesting. Perhaps you would write your experiences up in an article or a blog entry?
    – user1249
    Nov 14, 2010 at 10:07

I taught intro way in the last century, and it was BASIC, but like you I wanted to get the students going on a fun project of their own devising. So I suggested a bunch of possibilities:

  • Simple adventure game, like Wumpus
  • Sports simulation (text only, graphics for the ambitious) for baseball or whatever
  • Science, like simulating genetic evolution
  • Sport/science, like sailboat racing
  • Finance, like having your own bank for the people in your household, or investments
  • Music or simple graphical games

... or whatever students thought of. They would come to me and say "how about a program to do XYZ?" and I would always say "Great", and then maybe guide them a little not to make it too complicated.

Usually their projects ended up being a few hundred lines of code, and they always enjoyed it.

P.S. I gave this assignment after the students were competent with basic control structures, I/O, arrays, and sequential files. It was a term project, a major part of their grade, and I had intermediate milestone assignments, like an outline part way through, so they didn't try to do it all at the end and hit a wall. I wanted to get them into this as early in the semester as possible, when they had enough skills to get started, typically around week 6 or 8.


I had a teacher write a program that you wrote modules for. Basically, it was a game and you had to write an algo to solve it, everything was there to make it graphical and pretty and work nicely. Perhaps you should write your own game framework and give them basic tools that are dumbed-down versions of cool things they can do later outside of the box you've put them in.


In my intro course, three projects stuck out at me

Write a program to display a random Mondrian painting
Write the first part of a BrickBreaker game, get the ball bouncing around inside a set area
Write a text-based adventure game

From my algorithms class
Implement a Serpinski triangle

These four projects gave me a great understanding of string processing, randomization, graphics, recursion and animation.


Are all of the students in the class CS majors? My guess would be not. I would come up with assignments that are tailored to the majors in the class.


  • Art students could write a program that takes the dimensions of a piece of canvas and a frame to calculate the amount of the canvas would be unavailable for painting (due to wrapping and stapling the canvas around the frame).

  • Econ students could calculate compound interest on an item.

  • Math students could choose problems from Project Euler.

  • 1
    The class is for majors and non-majors. Many are in biology.
    – Macneil
    Nov 18, 2010 at 2:26
  • Interesting. Idea: find a picture of single-cell organisms swimming around in water. Convert the image to B&W. Write a program to count the number of organisms in the water. This will bring up all sorts of interesting discussion topics: edge detection, differentiation between water and non-water, dust elimination, etc. Nov 18, 2010 at 20:55
  • well for bio, the obvious thing that springs to mind is cellular automata. You can take a loot at bioquest.org to get a few ideas. Nov 18, 2010 at 21:13

In High School, I took an introductory programming class, and we used Karel J. Robot. It provides a gui for viewing your robot, and has a very basic set of sensors and movement methods which you have to extend in order to make it do interesting stuff. I think its good because robots are easy to understand for people who haven't yet developed a grasp of the difference between software is.

There is also Processing, which I just discovered, which was originally designed to teach programming, and its also in java.


I'm going to be the dissenter here. I think you should give them valid business type-problems to solve not playtoys. If they aren't serious enough to be interested and motivated with the kind of work they will be actually doing as a professional, I'd rather you flunked them out in the intro course. Real work isn't about making cool stuff, it's about meeting the client's needs. I've also seen a lot of people who can;t make the leap between what they learning in a game and using the same techiniques in business programming.

Every senior developer and hiring manager I know is disgusted with the quality of recent graduates. Try focusing on what they need to learn to work in the real world and forget about making it fun.

  • I think many students would find a business problem interesting. If you can suggest something concrete and improve your answer that would be helpful. I'm seeking specifics.
    – Macneil
    Nov 12, 2010 at 22:02
  • 1
    It ought to be a problem that they can't do (easily) on their TI-83 calculator. Yet Another Tax Calculator won't cut it. Nov 14, 2010 at 6:11
  • 1
    These students ar new to programming and need to take their babysteps in this course. Making it boring is perhaps not the most efficient way to teach them how to program and we should look at the Best teachers instead of just making them recite the Java specification from end to end.
    – user1249
    Nov 15, 2010 at 17:00
  • 1
    No. These projects should above all be fun. Fun projects can be difficult. In fact, most of my pet projects are harder than the everyday programming I do at work.
    – Carra
    Nov 17, 2010 at 18:56
  • 2
    I see your point, but I respectfully disagree, at least in part, and at least for an introductory course. There are many avenues of programming one can take, and I think a course like this should cover different things that programs can do. Showing students that computers are only good for problems we deem "necessary for business" does not a creative programmer make, because it limits their mindset. I think that a well designed course would challenge students to solve real-world problems, in addition to showing the fun things that computers can do, like programming a game Nov 18, 2010 at 17:37

An assignment for building a silly widget on their mobile phones. Something that they could show their friends. I have a uber-cheap AT&T phone and it takes jar files of some sort .


The most important assignments I've seen force people to think about something they would have not otherwise considered. Something entirely outside of the simple course material, something that seems impossible. Something that has multiple valid solutions.

A few that have impressed me:

  1. Roshambo AIs (used in the AI course at UOA). A simple function that returns -1, 0, 1 for rock, paper, scissors. The AIs are pit against each other, and stats are collected by an aggregate utility program. This assignment constantly surprises people in how many approaches are viable (and how many perform so poorly).

  2. Simple sorting problems with impossible characteristics. Sort a file of infinite length with finite memory. This problem shook my foundation of thinking in algorithms. There are many related problems: windowed averages over infinite-length data, etc., each forces a solution to something apparently impossible.

  3. Simulation problems that appear trivial. Traffic simulations (vehicle, network), race car simulations (left, right, faster, slower), grocery store simulations.

  4. Networking problems (a great weakness in the graduates I've worked with over the last few yearrs). Peer networking problems with handhelds, for example, proving complexity of n-sync issues, peer updates, peer trust, etc.

  5. Little languages (another weakness in recent grads). Develop a little language for a simple game AI (checkers, roshambo, tanks, CSS mojo, Twitter bots). Thinking about concepts of language design, interpretation, and actions is fundimental.

  • Do the paper, rock, scissors AIs get to know the result, or see what the history was?
    – Macneil
    Nov 21, 2010 at 23:28
  • Yes, the histories are available via arrays in the C example (but it would apply equally to Java, Ruby, etc.). Check out the original competition page: webdocs.cs.ualberta.ca/~darse/rsbpc.html Nov 22, 2010 at 5:11

Not the answer you're looking for? Browse other questions tagged or ask your own question.