Computer Science 202
Introduction to Programming
Fall 2012, The College of Saint Rose
Class Examples
Class examples will be linked below. Please report any missing examples.
- Beginning with Programming
-
- Java Fundamentals
-
- Seuss - extended "Hello, World" type example
- HelloYou - keyboard input (with Scanner), variables, String type, String concatenation
- Rectangle - int variables, Scanner's nextInt method, mathematical expressions
- MilesPerGallon - double variables, Scanner's nextDouble method
- RunsScored - named constant, int vs.double math, reading multiple items from a Scanner after a single prompt
- Conditional Execution
-
- Repetition
-
- Random Numbers
-
- RandomDemo - examples of how to generate various types of random numbers in Visual Logic and Java
- GuessingGame - a random number for a children's guess the number game
- MonteCarloPi - using random numbers to approximate Pi, Math.sqrt
- 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.
- 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
- Classes
-