Computer Science 202
Introduction to Programming
Fall 2013, The College of Saint Rose
Class Examples
Class examples will be linked below. Please report any missing examples.
- Java and Objectdraw Basics
-
- TouchyWindow - basic event handlers and Text object
- ColorEvents - more graphics primitives, more event
handlers, setting colors.
- SunAndMoon - moving objects in response to events
- MouseDroppings - accessing the mouse location
- Spirograph - remembering a mouse location in an
instance variable
- Scribble - update the saved location on each drag event
- RubberBand - changing the endpoint of a line
- Conditionals and Numbers
-
- Java Applications
-
- Seuss - a Java application, with only System.out.println
- HelloYou - a Scanner for keyboard input
- Rectangle - the nextInt method of a Scanner
- BooleanDemo - an example showing Scanner's nextInt and demonstrating lots of logical operations
- NoInterestLoan - using JOptionPane and the
Integer.parseInt method
- BasketballName - using a JOptionPane in an applet (i.e., a WindowController)
- RunsScored - somewhat more complex example of a
console application
- Repetition
-
- Methods
-
- BaaBaaBad - motivating example for methods
- BaaBaaBetter - defining a static method
- BaaBaa2Methods - 2 methods
- NumberInfo - a method that takes a parameter
- HoursWorked - passing a String to a method, and usins a Scanner to break it into components
- HoursWorked2 - same example, but pass in the Scanner as a parameter
- SumOfSquares - a method that takes two parameters
- Sum1ToN - a method that returns a value
- Sum1ToNBetter - a better version of the previous method
- Distance - a method that computes the distance between two points in the plane
- GradingBreakdown - a longer program that reads lots of inputs, just screaming out for a method to help organize
- GradingBreakdownBetter - the same program with a method introduced to organize the code better
- DrawFlags - more nested loops, private methods, this time with graphics
- Random Numbers
-
- RandomDemo - examples of how to generate various types of random numbers in standard Java
- GuessingGame - a random number for a children's guess the number game
- MonteCarloPi - using random numbers to approximate Pi, Math.sqrt
- MonteCarloPiVisual - an Objectdraw version of the Monte Carlo method to approximate Pi
- File I/O
-
- HelloWorldFile - opening a file for output with a
PrintWriter
- CircleAreas - read in numbers from a keyboard,
print circle radii to a file
- AddNumbersFromFile - read in a fixed number of numbers from a file, add them up, a file Scanner
- AddNumbersFromFileSentinel - read in numbers from a file, add them up, ending with a sentinel value
- AddNumbersFromFileAll - read in numbers from a file until no more numbers are available (end of file), Scanner's hasNextInt method
- WordCount - count the number of words in an input file, Scanner's hasNext method
- Shout - read in a file, print its contents to another file but with all words upcased, Scanner's hasNextLine and String's toUpperCase method.
- The switch Statement
-