CSCI 1320 (Principles of Programming I):
Sample Programs
Disclaimer: Code linked from this page is intended as a
cleaned-up and commented version of examples from class.
Many programs could be further improved with
regard to functionality or design, but then they would
no longer be as close to what we did in class.
Programs
- "Hello, world" program (09/01)
hello.scala.
- Two version of program to "make change" (09/13)
make-change.scala,
make-change2.scala.
- Simplified grade-calculating program, preliminary version (09/15)
grade.scala.
Improved version (09/20)
grade2.scala.
Further improved version (not in class)
grade3.scala.
- Program to compute roots of quadratic equation (09/20)
roots.scala.
- Simple converter program (09/22)
converter.scala.
Improved(?) version (not in class)
converter2.scala.
Version allowing repeated conversions (9/29)
converter3.scala.
Version allowing repeated conversions and using "match" (9/29)
converter4.scala.
- Function to compute bounding box (09/22)
bbox.scala.
Improved version (09/27)
bbox2.scala.
- Factorial functions (09/27)
factorial.scala.
- Program to "count down" using recursion (09/27)
countdown.scala.
- Program to sum numbers using recursion (09/29)
sum.scala.
- Simple demo of arrays (10/06, 10/11)
arraydemo.scala.
Revised version (10/13, 11/03)
arraydemo2.scala.
Another version using collection methods (11/03)
arraydemo-cm.scala.
Yet another version using loops (11/08)
arraydemo-loop.scala.
- Simplified grade-calculating program, revised version showing
use of array (10/06)
grade4.scala.
- Simple demo of lists (10/11, 10/13, 11/03)
listdemo.scala.
Another version using collection methods (11/03)
listdemo-cm.scala.
Yet another version using loops (11/08)
listdemo-loop.scala.
- Program to check whether string is a palindrome (10/20)
palindrome.scala.
- Program to sum numbers using while loop (11/01)
sum-loop.scala.
- Program to find primes (11/01)
primes.scala.
- Simple ASCII-art program (11/08)
ascii-art.scala.
- Program to echo command-line arguments (11/15)
echo-args.scala.
- Program to sum integers read from file (12/01)
sum-from-file.scala,
(simple-but-verbose version),
sum-from-file2.scala
(short-but-dense version, not in class).
- Program to find all words in a file that can be formed from
a string of letters (11/15)
scrabblewords.scala
(version from class),
scrabblewords.scala,
(terser version).
You can get a zip file containing lists of words to use with
these programs at
http://iweb.dl.sourceforge.net/project/wordlist/Ispell-EnWL/3.1.20/ispell-enwl-3.1.20.zip.
- Program to sum integers read from file and catch exceptions (11/17)
sum-from-file-catch-errors.scala.
- Function to compute bounding box using case class (11/17)
bbox-case-class.scala.
- Program to play text-mode version of Conway's "game of life" (11/22)
conway.scala;
sample input file
conway-in1.txt.
(The game is described in
the Wikipedia article.)
- Program to demonstrate bubble sort (11/29)
bubblesort-demo.scala.
- Example GUI programs (12/01, in simpler form):
"Hello world"
gui-hello.scala.
Simple editor
simple-editor.scala.
Calculator prototype
calculator-prototype.scala.
Drawing-program prototype
drawing-prototype.scala.
Simple animation example
simple-animation.scala.
Other files