University of Toronto
Scarborough College
Fall 1997
CSC A06F: INTRODUCTION TO
COMPUTER PROGRAMMING
Examples of Java code
This directory contains some examples of Java code. Some will be from
lectures and tutorials, and others will be new. I'll add examples as
I get the time to do so.
Also check the examples
on the main web page.
You can also try searching the
web for the string "public static void main" to find Java
programs.
The examples
Go straight to the example directory.
- Problem: Find the maximum of a set of numbers entered by the
user.
Solution: Max.java
- Problem: Find the minimum of a set of numbers entered by the
user.
Solution: up to you.
- Problem: Find the second highest number of a set of numbers
entered by the user.
Solution: up to you.
- Problem: write a program that maintain results from an
election. Each ward should be a separate object, and there should be
a main election object that controls all the ward objects.
Solution: Election.java and Ward.java
- Problem: Modify the Ward class above so that it can have an
unlimited number of candidates in it.
Solution: up to you. Hint: use an array.
- Problem: Modify the Election class above so that it can have an
unlimited number of wards in it.
Solution: up to you. Hint: use an array.
- Problem: Write a program that reads in a list of students and
grades, calculates the average, and outputs each student's difference
from the average.
Solution: Grades.java (uses
arrays, for loops, StringBuffer, and StringTokenizer)
- The GraphicsTest Application
Solution: GraphicsTest.java
- The GraphicsTest Applet
Solution: GraphicsTest_Applet.java,
GraphicsTest_Applet.html
(Will run in Netscape, or you can save everything and run it with the
appletviewer)
- The SampleGUI (with a button and Canvas)
Solution: SampleGUI.java,
SampleGUI.html
(Will run in Netscape, or you can save everything and run it with the
appletviewer)
- Fancy cash registers, and a store with 3 cash registers.
Solution: CashRegister.java FancyCashRegister.java ReallyFancyCashRegister.java Store.java
- The SampleEventGUI (with a button and Canvas and an event
listener)
Solution: SampleEventGUI.java, SampleEventGUI.html (WILL NOT
RUN IN NETSCAPE, so you must save both files, and run the HTML source
using the appletviewer.)
- The ButtonsGUI (it has two buttons, each with a listener.
Solution: ButtonsGUI.java, ButtonsGUI.html (WILL NOT
RUN IN NETSCAPE, so you must save both files, and run the HTML source
using the appletviewer.)
Last modified: Fri Nov 7 20:16:36 EST