Take the 2-minute tour ×

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.

share|improve this question

closed as too broad by gnat, GlenH7, MichaelT, Michael Kohne, Bart van Ingen Schenau Sep 1 '13 at 9:22


17 Answers 17

up vote 7 down vote accepted

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

share|improve this answer

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.

share|improve this answer
Sounds fun, but keep it small. –  user1249 Nov 14 '10 at 10:05
  • 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).

share|improve this answer

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.

share|improve this answer
+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 '10 at 22:05

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.

share|improve this answer

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.

share|improve this answer
+1 Thanks! This is exactly the kind of answer that I'm looking for. –  Macneil Nov 12 '10 at 22:00

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.

share|improve this answer

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.
share|improve this answer

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.

share|improve this answer

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.

share|improve this answer

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.

share|improve this answer

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.

share|improve this answer

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.

share|improve this answer
The class is for majors and non-majors. Many are in biology. –  Macneil Nov 18 '10 at 2:26

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.

share|improve this answer

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.

share|improve this answer
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. –  Barry Brown Nov 14 '10 at 6:11
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 '10 at 17:00
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 '10 at 18:56
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 –  Nick Donohue Nov 18 '10 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 .

share|improve this answer

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.

share|improve this answer
