CSE 142 Spring'04
Sample Code and Other Stuff
Cone of Learning
by Edgar Dale showing how much you retain after reading, hearing,
seeing, etc.
What's the moral? See the bottom of the pryamid ...
DOING THE REAL THING!! Gotta practice.
HuskyCard.java
modeling a card with operations of deposit, withdraw, display, etc.
Model an hourly worker:
HourlyWorker.java
Model a worker's time card:
TimeCard.java
This example shows use of an object of one class as an instance
variable of another class.
An HourlyWorker object has a name, wage, pay, and
TimeCard object as its instance variables.
A class Play, found in
Play.java
plays around with loops. It has methods
-- to compute factorial
-- a double your money problem
-- has pseudocode for printing a pyramid in stars
-- has methods to display
*
**
***
****
___* (dash stands for a
blank)
__**
_***
****
Common algorithms using loops are demonstrated in
SimpleStats.java
It has methods to
-- accumulate ... addition, finding an average
in a sequence of values
-- accumulate ... multiplication, computing factorial
-- find the highest in a sequence of values
-- find the lowest in a sequence of values
Some of these are useful in assignment #3.
SimpleList.java
demonstrates how to use ArrayLists and Iterators with loops.
This example demonstrates how to use ArrayLists and Iterators
with more complex problems involving loops. It is useful for assignment
#4.
List2.txt is pseudocode for solving the following problem:
Given two ArrayList filled with Integer objects,
build, print, and return a new ArrayList filled
with all the Integers in common to both lists.
The list is to have unique Integer objects in it.
The code for this is found in
List2.java.
TestList2.java
includes a main method to test the List2 class without
having to
type in values to build lists. After compiling, in the interactions
pane,
enter
java TestList2
An alternate implementation was developed during the 9:30 lecture on
5/12/2004. AListFun includes code,
plus a method to generate random lists for test purposes, and a main()
method that can be run.
Solve the problem to write a method which is given an array of char
and reverses the characters, for example:
BEFORE:
+---+---+---+---+---+ +---+---+---+---+---+---+
| w o r l d |
| m o t h e r |
+---+---+---+---+---+ +---+---+---+---+---+---+
AFTER:
+---+---+---+---+---+ +---+---+---+---+---+---+
| d l r o w |
| r e h t o m |
+---+---+---+---+---+ +---+---+---+---+---+---+
The solution is found at
CharArray.java
Implement a Worker and WorkerList. Sort the list. Shows use of Comparable
interface.
The Worker class code is found at
Worker.java (implements Comparable) .
The WorkerListTest class which only has a main method and
the WorkerList class is in
WorkerListTest.java .
Show simple simulation of the insertion sort:
Insertion.java
Show the binary search :
BinarySearch.java