Programming by Doing

“The best way to learn is to do.” - P.R. Halmos


If you've ever tried to teach yourself programming and couldn't quite get going, then these assignments are for you. Refined over fifteen years, these are the assignments I have used to teach the basics of Java to nearly 2,000 ordinary public school students over my career.

Buy My Books!

If you are having trouble figuring out how to do these assignments without help, then my book with videos “Learn Java the Hard Way” will explain things a lot better. (Especially if you have never coded before!)

Or if you have finished most of these assignments and are ready for the object-oriented side of Java, “Learn Object-Oriented Java the Hard Way” is the book for you!

If you have any questions about these assignments, please read the Frequently-Asked Questions at the bottom of this page.

Happy coding!
- Graham Mitchell

Last updated: Saturday, 2015-11-28

  Basics and Printing - 9 assignments, 58 points
0Basics and PrintingInstalling the Java Development Kit (JDK)20 points
1Basics and PrintingCompiler Check3 points
2Basics and PrintingCompiling Practice  - code provided3 points
3Basics and PrintingAn Important Message  - code provided5 points
4Basics and PrintingA Good First Program  - code providedby Zed Shaw4 points
5Basics and PrintingComments and Slashes  - code providedby Zed Shaw3 points
6Basics and PrintingA Letter to Yourself7 points
7Basics and PrintingYour Initials6 points
8Basics and PrintingNumbers and Math  - code providedby Zed Shaw7 points
  Variables - 5 assignments, 48 points
9VariablesVariables and Names  - code providedby Zed Shaw7 points
10VariablesMore Variables and Printing  - code providedby Zed Shaw7 points
11VariablesUsing Variables9 points
12VariablesStill Using Variables10 points
13VariablesYour Schedule15 points
  Keyboard Input - 7 assignments, 106 points
14Keyboard InputAsking Questions  - code providedby Zed Shaw10 points
15Keyboard InputThe Forgetful Machine12 points
16Keyboard InputName, Age, and Salary15 points
17Keyboard InputMore User Input of Data16 points
18Keyboard InputAge in Five Years18 points
19Keyboard InputA Dumb Calculator20 points
20Keyboard InputBMI Calculator15-28 points
  If Statements - 17 assignments, 505 points
21If StatementsWhat If  - code providedby Zed Shaw15 points
22If StatementsHow Old Are You?25 points
23If StatementsElse And If  - code providedby Zed Shaw20 points
24If StatementsWeekday Name  - code provided15 points
25If StatementsHow Old Are You, Specifically?20 points
26If StatementsSpace Boxing30 points
27If StatementsA Little Quiz40 points
28If StatementsModulus Animation  - code provided20 points
  GUIs - 3 assignments, 55 points
29GUIsUsing Swing for Input  - code provided25 points
30GUIsA Boring Window  - code provided10 points
31GUIsA Frame with a Panel with Writing on It  - code provided20 points
32If StatementsTwenty Questions... well, actually just Two35 points
33If StatementsChoose Your Own Short Adventure!60 points
34If StatementsAge Messages 325 points
35If StatementsTwo More Questions35 points
36If StatementsBMI Categories35-45 points
37If StatementsGender Game50 points
38If StatementscompareTo() Challenge35 points
39If StatementsAlphabetical Order30 points
40If StatementsThe Worst Number-Guessing Game Ever15 points
  Random Numbers - 8 assignments, 160 points
41Random NumbersRandomness  - code provided15 points
42Random NumbersMagic 8-Ball™  - code provided10 points
43Random NumbersA Number-Guessing Game20 points
44Random NumbersFortune Cookie15-25 points
45Random NumbersDice25 points
46Random NumbersOne Shot Hi-Lo35 points
47Random NumbersThree-Card Monte20 points
  While Loops - 12 assignments, 500 points
48While LoopsEnter Your PIN  - code provided15 points
49While LoopsKeep Guessing50 points
50While LoopsDice Doubles45 points
51While LoopsCounting with a While Loop  - code provided30 points
52While LoopsPIN Lockout  - code provided10 points
53While LoopsNumber-Guessing with a Counter40 points
54While LoopsHi-Lo with Limited Tries55 points
55While LoopsAdding Values in a Loop30 points
  Do-While Loops - 5 assignments, 130 points
56Do-While LoopsDo-While Swimming  - code provided15 points
57Do-While LoopsFlip Again?  - code provided20 points
58Do-While LoopsShorter Double Dice40 points
59Do-While LoopsAgain with the Number-Guessing35 points
60While LoopsSafe Square Root55 points
61While LoopsRight Triangle Checker65 points
62While LoopsCollatz Sequence30-60 points
63While LoopsShort Adventure 2: With a Loop75 points
63bWhile Loops[New!] Baby Nim60 points
63cWhile Loops[New!] Nim70-185 points
  For Loops - 14 assignments, 335 points
64For LoopsCounting with a For Loop  - code provided10 points
65For LoopsTen Times15 points
66For LoopsCounting Machine20 points
67For LoopsCounting Machine Revisited25 points
68For LoopsCounting by Halves20 points
69For LoopsXs and Ys15 points
70For LoopsNoticing Even Numbers30 points
71For LoopsFizz Buzz40 points
72For LoopsLetter at a Time  - code provided20 points
73For LoopsFor Loop Challenge40 points
74For LoopsAdding Values with a For Loop30 points
75Random NumbersBaby Blackjack20 points
  Projects - 5 assignments, 860 points
76ProjectsProject: Blackjack80-200 points
  Graphics - 31 assignments, 1441 points
77GraphicsGraphics Demo 1: Basics  - code provided20 points
78GraphicsGraphics Demo 2: Arcs and Custom Colors  - code provided20 points
79GraphicsGraphics Demo 3: Fonts and Lines  - code provided15 points
80GraphicsA Circle20 points
81GraphicsA Smiling Face40 points
82GraphicsA Clock Face50-70 points
83GraphicsGraphing Lines  - code provided40 points
84GraphicsGraphing Parabolas  - code provided40 points
85GraphicsGraphics Demo 4: Polygons  - code provided40 points
86GraphicsDrawing a Boring Triangle30 points
87GraphicsDrawing Random Triangles60 points
88GraphicsDrawing Random Right Triangles80-140 points
89GraphicsSierpinski Triangle150 points
90GraphicsBoxy 1  - code provided50 points
91GraphicsBoxy 2  - code provided40 points
92GraphicsBoxy 3  - code provided60 points
93GraphicsSmiling Face Function  - code provided80 points
94GraphicsForest and Trees  - code provided150 points
95GraphicsImage Demo - Showing Images on the Screen  - code provided20 points
96GraphicsMotivational Poster50-80 points
  Functions - 17 assignments, 1070 points
97FunctionsPicture Menu  - code provided10 points
98FunctionsFlicker Phrase  - code provided15 points
99FunctionsHeron's Formula  - code provided15 points
100FunctionsDistance Formula  - code provided50 points
101FunctionsMonth Name60 points
102FunctionsMonth Offset60 points
103FunctionsWeekday Calculator90 points
104FunctionsArea Calculator110 points
105FunctionsFunction Call Alphabet90 points
106FunctionsFill-In Functions100 points
107FunctionsMore Fill-In Functions100 points
108FunctionsKeychains for Saleby Aaron Gadberry40 points
109FunctionsKeychains for Sale, for real this timeby Aaron Gadberry65 points
110FunctionsKeychains for Sale, real ultimate powerby Aaron Gadberry80 points
111FunctionsCalling Functions from Other Files40 points
112FunctionsEvenness Function60 points
113FunctionsFinding Prime Numbers85 points
114Do-While LoopsBaby Calculator  - code provided20 points
115ProjectsProject: Calculator80-300 points
116For LoopsA Refresher20 points
117For LoopsRefresher Challenge20 points
118For LoopsDisplaying Some Multiples30 points
  Nested Loops - 9 assignments, 580 points
119Nested LoopsNesting Loops  - code provided20 points
120Nested LoopsOdometer Loops  - code provided25 points
121Nested LoopsBasic Nested Loops50 points
122Nested LoopsMultiplication Table65 points
123Nested LoopsNumber Puzzle I60 points
124Nested LoopsGetting Individual Digits80 points
125Nested LoopsMore Number Puzzles100 points
126Nested LoopsNumber Puzzles III: Armstrong Numbers90 points
127Nested LoopsNumber Puzzles IV: A New Hope90 points
  File Input and Output - 10 assignments, 535 points
128File Input and OutputLetter Revisited40 points
129File Input and OutputHigh Score50 points
130File Input and OutputSimple File Input40 points
131File Input and OutputSumming Three Numbers from a File50 points
132File Input and OutputSumming Three Numbers from Any File65 points
133File Input and OutputDisplaying a File60 points
134File Input and OutputSumming Several Numbers from Any File60 points
135File Input and OutputSimple Web Input  - code provided15 points
136File Input and OutputA Little Puzzle75 points
137File Input and OutputVowel Capitalization80 points
  Arrays - 16 assignments, 1245 points
138ArraysBasic Arrays 020 points
139ArraysBasic Arrays 130 points
140ArraysBasic Arrays 240 points
141ArraysBasic Arrays 325 points
142ArraysCopying Arrays55 points
143ArraysGrades in an Array and a File90 points
144ArraysFinding a Value in an Array80 points
145ArraysHow Many Times?40 points
146ArraysIs It There or Not?85 points
147ArraysWhere Is It?90 points
148ArraysFinding the Largest Value in an Array100 points
149ArraysLocating the Largest Value in an Array110 points
150ArraysGiving an Array a Bunch of Values at Once  - code provided30 points
151ArraysParallel Arrays100 points
152ArraysTic-Tac-Toe  - code provided150 points
153ArraysHangman200 points
  Sorting - 11 assignments, 1000 points
154SortingMadLib Random  - code provided40 points
155SortingMovie Title Generator  - code provided40 points
156SortingPokéSwap  - code provided40 points
157SortingPokéTrader  - code provided30 points
158SortingPokéTrader 2  - code provided20 points
159SortingSorting an Array  - code provided100 points
160SortingExchange Sort  - code provided120 points
161SortingBubble Sort  - code provided130 points
162SortingSelection Sort  - code provided130 points
  Records - 11 assignments, 1070 points
163RecordsWeb Addresses  - code provided30 points
164RecordsWeb Addresses Array  - code provided10 points
165RecordsAddress toString()  - code provided20 points
166RecordsBasic Records80 points
167RecordsA Little Database100 points
168RecordsA Little Database is shorter with a loop100 points
169RecordsGetting Data from a File120 points
170RecordsGetting More Data from a File140 points
171RecordsStoring Data in a File150 points
172RecordsReading What You Wrote160 points
173RecordsSorting an Array of Records160 points
174SortingSorting Strings150 points
175SortingSorting Records on Two Fields200 points
  Objects - 1 assignment, 100 points
176ObjectsA Tic-Tac-Toe Class  - code provided100 points
  ArrayLists - 14 assignments, 1165 points
177ArrayListsBasic ArrayLists 020 points
178ArrayListsBasic ArrayLists 130 points
179ArrayListsBasic ArrayLists 240 points
180ArrayListsBasic ArrayLists 325 points
181ArrayListsCopying ArrayLists55 points
182ArrayListsFinding a Value in an ArrayList80 points
183ArrayListsArrayList - There or Not?85 points
184ArrayListsArrayList - Where Is It?90 points
185ArrayListsGetting the Largest Value in an ArrayList100 points
186ArrayListsLocating the Largest Value in an ArrayList110 points
187ArrayListsSorting an ArrayList120 points
188ArrayListsSorting an ArrayList of Strings150 points
189ArrayListsSorting Sentences100 points
190ArrayListsSorting an ArrayList of Records160 points
191ProjectsProject: Address Book200-400 points
192ProjectsProject: Hearts300-500 points
  Project Euler - 20 assignments, 1715 points
193Project EulerProject Euler 001 - Sum Multiples of 3 or 520 points
194Project EulerProject Euler 002 - Sum Even Fibonacci Numbers40 points
195Project EulerProject Euler 003 - Largest Prime Factor of Big Number60 points
196Project EulerProject Euler 004 - Largest Palindromic Product70 points
197Project EulerProject Euler 005 - Smallest Divisible by 1-2050 points
198Project EulerProject Euler 006 - Sums of Squares Minus Squares of Sums50 points
199Project EulerProject Euler 007 - The 10001st Prime80 points
200Project EulerProject Euler 008 - Largest Product of Consecutive Digits100 points
201Project EulerProject Euler 009 - Pythagorean Triplet75 points
202Project EulerProject Euler 010 - Sum of Primes Under Two Million100 points
203Project EulerProject Euler 011 - Largest Product of 4 Numbers in Grid160 points
204Project EulerProject Euler 012 - First Triangle Number w/501 Divisors160 points
205Project EulerProject Euler 013 - Sum 100 Fifty-Digit Numbers80 points
206Project EulerProject Euler 014 - Longest Collatz Sequence150 points
207Project EulerProject Euler 015 - Routes Through a 20x20 Grid100 points
208Project EulerProject Euler 016 - Sum of the Digits of 2^100050 points
209Project EulerProject Euler 017 - Letters in One to One Thousand110 points
210Project EulerProject Euler 018 - Maximum Sum Path through Triangle160 points
211Project EulerProject Euler 019 - Sundays on the 1st of the Month50 points
212Project EulerProject Euler 020 - Sum of the Digits of 100!50 points
213GraphicsMouse Demo  - code provided20 points
214GraphicsTraffic Light - Drawing Shapes and Clicking Them  - code provided40 points
215GraphicsShapes Demo - Easily Drawing and Transforming Shapes  - code provided1 points
216GraphicsLast Clicked - Drawing Boxes Where You Clicked  - code provided1 points
217GraphicsNo Erasey - Making Stuff Stay on the Screen  - code provided1 points
218GraphicsDrag Location - Getting Drags instead of Clicks  - code provided1 points
219GraphicsDrawing Layers  - code provided1 points
220GraphicsEtch-A-Sketch  - code provided20 points
221GraphicsBouncing Ball  - code provided1 points
222GraphicsPong  - code provided100 points
223GraphicsReversi  - code provided200 points
224ProjectsProject: Paint200-500 points

Frequently-Asked Questions

Can I email you for help?
No, sorry. There are thousands of you doing these assignments!
How can I get help?
There's forum on Reddit devoted just to the assignments on this site. Your question has probably been asked before, so check there! If you have a new question, upload your code to a Gist and then make a post. Someone will answer within a couple of days!
Are the solutions available?
No! Many teachers around the world use these assignments to teach their students. If answers were available some students would use them to cheat!
What if I buy your book? Are the solutions to these assignments in there?
Nope! My book is super great and you should totally buy it, but it will only teach you how to complete assignments like these.
It seems like some explanations are missing. Did you forget to upload something?

No, I didn't forget. Back in 2005, I didn't have any assignments to explain new concepts. I taught my students everything through lectures.

Then in 2010 I stopped lecturing and started creating "assignments" to replace my lectures. I got some of these completed, and you see them here. Students worked through the material at their own pace and asked me questions in person about anything that I hadn't gotten around to.

Finally, in 2013 I wrote “Learn Java the Hard Way”. Now students now use my book to learn each concept and then they use the rest of the assignments listed here to practice.

So the explanations for some of the later assignments (like File Input & Output) aren't "missing"; they never existed. Sorry for the inconvenience!