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.
  1. Problem: Find the maximum of a set of numbers entered by the user.
    Solution: Max.java

  2. Problem: Find the minimum of a set of numbers entered by the user.
    Solution: up to you.

  3. Problem: Find the second highest number of a set of numbers entered by the user.
    Solution: up to you.

  4. 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

  5. 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.

  6. 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.

  7. 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)

  8. The GraphicsTest Application
    Solution: GraphicsTest.java

  9. 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)

  10. 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)

  11. Fancy cash registers, and a store with 3 cash registers.
    Solution: CashRegister.java FancyCashRegister.java ReallyFancyCashRegister.java Store.java

  12. 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.)

  13. 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