To Home Page
IT 212 -- Examples
Index of Examples
Terminal I/O
- Hello Example -- Print a
"Hello, World" message to an output file.
Bitwise and HexDump
- Bitwise Example -- Compute bitwise and, or, exclusive or, and bitwise complement of the inputs.
- HexDump Utility -- Display characters in a file in both hex and character.
Lists and Methods
-
Array1 Example array1.py
values1.txt --
Read an array from a file, then compute the sum of the array.
-
Array2 Example array2.py
values1.txt --
Define and use two methods:
(1) read_array that reads an array from a file, and
(2) sum_array that computes the sum of the elements of an array.
-
TwoDArray Example
two-d-array.py
course-scores.txt --
Define and use two methods:
(1) read_2d_array that reads a two-dimensional array with two columns from a file, and
(2) weighted_ave computes the weighted average of the items stored in a two-dimensional array.
-
RaggedArray Example
ragged-array.py
values2.txt --
Define one method:
(1) read_ragged_array that reads an array from a file.
Classes
-
BasketballPlayer Example
UML Diagram
BasketballPlayer Class
Traditional Test Script -- Create
and test a BasketballPlayer class.
-
Person Example
UML Diagram
Person Class
Traditional Test Script
Unit Test Script -- Create a Person class with
fields name, gender, age and method have_birthday.
-
Card Example
UML Diagram
Card Class
Traditional Test Script
Unit Test Script -- Create a
Card class with
fields rank and suit. The instance methods are
__init__, __str__, and
color.
-
Pet Example
UML Diagram
Pet Class
Traditional Test Script
Unit Test Script -- Create a Pet class with with
fields name, animal_type, and methods vaccinate, is_vaccinated.
-
SimpleClock Example
UML Diagram
SimpleClock Class
Traditional Test Script
Unit Test Script -- Create a SimpleClock class with
field sec and method tick.
-
BankAccount Example
UML Diagram
BankAccount Class
Traditional Test Script -- Create a BankAccount class.
-
VendingMachine Example
UML Diagram
VendingMachine Class -- Create a VendingMachine class with
private fields _num_quarters, _num_candy_bars, and public methods
deposit_quarter, dispense_candy_bars.
-
BabyDragon Example
BabyDragon Class
Test Script Create a BabyDragon class
with public methods eat, get_tossed, put_to_bed, rocked, go_for_walk and private
methods is_hungry, must_go, wake_up_suddenly, passage_of_time.
Lists of Objects
Inheritance
Read from Web
SQL via Python and SQLite3
- SQLKids1 Example
sqlkids1.py -- Create SQL table using hardcoded Python statements.
- SQLKids2 Example
sqlkids2.py -- Create SQL table using data read from keyboard.
Java Basics
Java Control Structures
Java Classes
- Person2 Example
Python:
person.py
test.py
Java:
Person.java
Test.java -- Translate the Person class into Java.
Use public instance variables
- PersonArray2 Example
persons.txt
Input File: Python:
person.py
test.py
Java:
Person.java
Test.java -- Create an array of Person objects from data read from the persons.txt file,
using public instance variables.
- Person3 Example
Java:
Person.java
Test.java -- Translate the Person class into Java. Use private instance variables with public getters and setters.
Use public instance variables