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 (1/24)
hello.scala.
- Several versions of program to count out change (1/31, 2/02, 2/14)
change.scala,
change2.scala,
change3.scala.
- Simplified grade-calculating program, preliminary version (2/07)
grades.scala.
Improved version (2/07)
grades2.scala.
- Function to compute roots of quadratic equation (2/09)
roots.scala.
- Function to compute bounding box (2/14)
bbox.scala.
- Factorial function (2/16)
factorial.scala.
- Program to "count down" using recursion (2/16, 2/23)
countdown.scala.
- Program to maintain running balance for checkbook (2/23)
balance.scala,
balance2.scala
(version using match),
balance3.scala
(slightly improved version, not in class).
- Simple array demo program (2/28)
arraydemo.scala.
Revised version (3/20)
arraydemo2.scala.
Another version using collection methods (3/22)
arraydemo-cm.scala.
Yet another version using loops (4/03)
arraydemo-loop.scala.
- Simple list demo program (3/01)
listdemo.scala.
Revised version (not in class)
listdemo2.scala.
Another version using collection methods (3/22)
listdemo-cm.scala.
Yet another version using loops (4/03)
listdemo-loop.scala.
- Program to check whether string is a palindrome (3/20)
palindrome.scala.
- Program to show grade distribution (3/22)
grade-dist.scala,
grade-dist2.scala.
- Program to sum integers using loop (4/03)
sum-loop.scala,
- Program to find primes (4/03)
primes.scala.
- Program to maintain running balance and transaction history for
checkbook (4/05, 4/12, 4/17):
Version from class
balance-plus.scala.
Improved(?) version
balance-plus-v2.scala.
Version using case classes (and replacing check/deposit with
debit/credit)
balance-plus-v3.scala.
Version that uses file(s) to save transactions
balance-plus-v4.scala.
- Program to sum integers read from file (4/10, 4/17):
sum-from-file.scala,
(simple-but-verbose version).
sum-from-file2.scala
(short-but-dense version, not in class).
sum-from-file-catch-errors.scala (version that catches errors).
- Program to change text file to all-caps (not in class):
text-file-caps.scala.
- Program to echo command-line arguments (4/17):
echo-args.scala.
- Insertion-sort functions (4/19):
insertion-sort.scala.
- Example GUI programs (4/24):
"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