To Course Home Page
IT 313 -- Examples
Links to Examples
HelloWorld Project
Zipfile: hello-world.zip
This project has no modules defined.
Creating an IntelliJ HelloWorld Project
Greeter Project
Zipfile: greeter.zip
This project has four modules defined.
Creating a Project with Multiple Modules
- Module greeter1:   Display a greeting to the person whose name is specified.
  
  Main.java 
- Module greeter2:   Same as the 
greeter1 
module, but use the makeGreeting method to construct the greeting.
  
  Main.java 
- Module greeter3:   Same as the 
greeter2 
module, but put the main method and the makeGreeting method in separate 
classes.
  
  Main.java   
Greeter.java 
- Module greeter4:   Instead of inputting from standard in and outputting to standard out,
use an input dialog and a message dialog for input and output, respectively.
  
  Greeter.java 
InchesToCm Project
Zipfile: inches-to-cm.zip
- Module in2cm1:   Input a length in inches and convert it to centimeters.
  
  Main.java 
- Module in2cm1:   Input a length in inches and convert it
centimeters. Use a method to perform the conversion.
  
  Main.java 
- Module in3cm1:   Input a length in inches and convert it centimeters. Use a method to perform the
conversion, placing the method in a the separate source code file Convert.java. The method call must be qualified by the
class where it is located.
  
  Main.java   
Greeter.java 
TerminalIO Project
Zipfile: terminal-io.zip
- Module wordtonum:  
Input a one digit number in words, then output the corresponding integer.
  
  Main.java 
- Module tipcalculator:   Calculate the tip for a 
restaurant bill. Always tip at least one dollar. 
  
  Main.java 
- Module gradecalculator:   Input class score, 
output course grade.
  
  Main.java 
ComputeAverage Project
Zipfile: compute-average.zip
- Module ave1:   Enter quiz scores as double values at the keyboard.
Terminate list with 999.9.  Output average of scores.
  
  Average.java - Module ave2:   Enter count of quiz scores. Then enter quiz scores as
double values at the keyboard. Output average of scores.
  
  Average.java 
- Module ave3:   Enter quiz scores as double values at the keyboard.
Terminate the list with Control-D. Output average of scores.
  
  Average.java 
- Module ave4:   Enter name and quiz score pairs separated by commas.
Terminate the list with Control-D. Output average of scores.
Sample input list:
Alice,96
Bob,84
Chloe,98
Danny,100
^D
  
  Average.java 
Loops Project
Zipfile: loops.zip
- Module counting:   Count to 100 using while and for loops.
Also count backwards from 100 to 1 by 7s.
  
  Main.java 
- Module stats:   Compute the count, sum, average, min,
and max for a list input from the keyboard.
  
  Main.java 
- Module dice1:   Print NUM_ROLLS rolls of two fair 
dice; rand.nextInt(6) returns a random int in the interval [0,6) (0 inclusive, 6 exclusive).
  
  Main.java 
- Module montecarlo:   Estimate the value of 
π (pi) by 
generating random points (x, y) with x and y in [0.0, 1.0). The probability that 
(x, y) lies in the circle
with center (0.5, 0.5) and radius 1.0 is 
π/4.
  
  Main.java 
- Module hailstone:   Given the start value n0, generate the Hailstone sequence:
    
If ni is even ni+1 = ni / 2, otherwise ni+1 = 3 * ni + 1.
The sequence is called a Hailstone sequence because its
values move up and down in an unpredictable manner, similar
to hailstones in a thunderstorm cloud.
Mathematicians believe that all Hailstone sequences terminate
with one, even though they have not been able to formally prove this
for all starting values.
  
  Main.java 
Drawing Project
Zipfile: drawing.zip
- Instantiate a MyFrame object derived from the Swing
JFrame class. The MyFrame object 
contains a JPanel object that displays a Swing drawing 
using Graphics methods. No modules are defined for this
project.
    
Main.java  
MyFrame.java 
MyPanel.java 
Unicode Project
Zipfile: unicode.zip
- Module unicode1:   Create a UTF-8 encoded file that contains
these Unicode characters: Greek alpha, Greek beta, Greek gamma, Hebrew aleph.
  
  Main.java 
- Module unicode2:   In a Swing JPanel, display the 
Unicode characters Greek alpha, Greek beta, Greek gamma, Hebrew aleph.
  
  Main.java  
  MyFrame.java  
  MyPanel.java 
StaticMethods Project
Zipfile: static-methods.zip
No modules are defined for this project.
- Class:   CountDown.java   
Print the count down sequence for a rocket launch. The countDown method is 
static because it is called from a class (not called from an object). 
 
- Class:   Square.java 
  Test the square method that returns the square of its input value.
 
- Class:   Test.java 
  Test the countdown and square methods defined in Countdown.java and 
Square.java, respectively. 
 
- Class:   PrintPowers.java 
  Print table of the values, squares, cubes, and 4th powers of ints from 1 to 
10. 
 
- Class:   Acrostic.java 
 
An acrostic is a poem arranged so that the first letters
of each line have a meaning.  Given an input array of strings
that represent the lines of a poem, return the string composed
of the first concatenated letters of the lines of the poem.
 
- Class:   WriteCheck1.java
 
Use stepwise refinement to write helper methods to implement the details of 
writing the check. Print the count down sequence for a rocket launch. 
 
InstanceMethods
Zipfile: instance-methods.zip
No modules are defined for this project.
- Class: 
StringTest.java   Test some methods and other 
features of the String class. 
 
- Class:  
CalendarTest.java   Test some instance 
variables of a Calendar object 
 
- Class:  
IntegerTest.java   The 
Integer class is called a wrapper class because it wraps an
int value in an object. Test some instance methods of 
the Integer class. 
 
- Class:  
SSBCompare.java   Create 
String objects using a loop without and with the assistance of a
StringBuilder object. 
 
UnitTests
Zipfile: unit-tests.zip
Creating a JUnit5 Test Class for IntelliJ
- Module greetertest:   The unittest class
GreeterTest tests the makeGreeting 
method in the Greeter class.
  
  Greeter.java
  GreeterTest.java 
- Module stringtest:   The unittest class StringTest 
tests methods in the String class. No String class is included in this
module; use a fake class (e.g., FakeClass) to use for creating a test class.
  
  StringTest.java 
- Module phoneletters2digits:   The 
phoneLettersToDigits method of the GetDigits 
class, convert letters to the digits of a phone number. The 
GetDigitsTest class contains unit tests for the 
GetDigits class method. 
  
  PhoneLetters2Digits.java   
PhoneLetters2DigitsTest.java 
- Module: amt2words   The amt2Words 
method in the Amt2Words class inputs a 
double amount < 100.00 and converts it to words suitable for using as the 
amount on a check. The Amt2WordsTest class provides the
test1 method with assertEquals 
statements to test the Amt2Words.amt2Words method. 
  
  Amt2Words.java
  Amt2WordsTest.java 
Classes Project
Zipfile: 
classes.zip
- Module person:   This Person 
class has fields (instance variables) name, gender, 
and age. Getters are defined for name and gender; a 
getter and setter are defined for age. The haveBirthday method adds one to age. 
  
  Person.java  
Test1.java (Traditional Tests)  
Test2.java (Unit Tests) 
- Module counter:   Implement 
Counter class that counts items, for example, persons, animals, items on 
an assembly line, etc. 
  
  Counter.java  
Test1.java (Traditional Tests)  
Test2.java (Unit Tests) 
- Module pet:   Define Pet 
class with fields name, animal,
vaccinated. Add constructor getters, setters, and
toString method. 
  
  Pet.java  
Test1.java (Traditional Tests)  
Test2.java (Unit Tests) 
Zipfile: input-output.zip
No modules are defined for this project.
- Class: 
StringTest.java   Test a 
Scanner object that reads from a string.
Also use the String split method to extract the words from the same string.
 
 
- Class: 
ReadFromWeb.java   Read raw HTML lines from input file and
print them to stdout.
 
- Class: 
WriteGreetings.java   Read names of persons from input file 
names.txt,
then write greetings to each of them, each in its own output file.
 
- Class: 
UseFileChooser.java   Open an output file with a FileChooser dialog.
Read names and write greetings as in the WriteGreetings class.
 
- The input file names.txt is used for the 
WriteGreetings and UseFileChooser
classes.
 
Inheritance Project
Zipfile: inheritance.zip
TestPackage
Zipfile: testpackage.zip
No modules are defined for this project.
- Class: 
Counter.java  Implement a Counter class
according to this UML diagram. Before creating the class, add the package it313.sjost to the src folder.
 
- Class: 
TestCounter.java   Implement a test file to test
the Counter class.  The test file is not in the it313.sjost package.
 
 
 JFreeChart Project
Zipfile: 
jfreechart.zip
jFreeChart JAR Files for this example and Project 3b:
jfreechart-1.0.19.jar   jcommon-1.0.23.jar
- Class: BarChart.java   This Person 
class has fields (instance variables) name, gender, 
and age. Getters are defined for name and gender; a 
getter and setter are defined for age. The haveBirthday method adds one to age.
 
- Class: LineChart.java   Implement 
Counter class that counts items, for example, persons, animals, items on 
an assembly line, etc.
 
Interfaces Project
Zipfile: 
interfaces.zip
Serialization Project
Zipfile: 
serialization.zip
EmployeeFind Project
Zipfile: 
employeefind.zip
- Show how to search collection for a specified substring.
 
- Class: Employee.java   Base class.
 
- Class: Executive.java   Derived class.
 
- Class: 
EmployeeRoster.java   User defined collection class that holds
Employee or Executive objects.
 
- Class: Test.java   Test class for EmployeeRoster collection class.
 
PackageAccessibility Project
Zipfile: 
packageaccessibility.zip
- Test the four kinds of accessibility: public, protected, private, package (default).
 
- Package: it313   Classes:
A.java   
B.java
  
- Package: Default   Classes:
C.java   
Main.java
 
 
Patterns1 Project
Zipfile: 
patterns1.zip
- Module: logger  Illustrate the Singleton software 
pattern. Only one instance of a singleton class is allowed. This is accomplished 
by using a private constructor. Create the file c:/logger before running this 
example.
    
Logger.java  
Main.java 
- Module: reusableobjects  Illustrate the Singleton 
software pattern.
    
Reusable.java  
Main.java 
- Module: factory   Illustrate the Factory software pattern
Make the constructor private so that objects can only be obtained using
the static getInstance method.
    
FactoryObject.java  
Main.java 
- Module: employeefactory   Illustrate the Factory software pattern.
The getInstance method can create objects from three different classes.
    
Person.java  
Employee.java  
Executive.java  
EmployeeFactory.java  
Test.java 
Observer Project
Zipfile: observer.zip
- Module: observer   An observable object can 
have one or more observers; an observer may be any object that implements interface 
it313.util.Observer. After an observable instance changes, an application calling 
the it313.util.Observable's notifyObservers method causes all of
its observers to be notified of the change by a call to their
update method.
    Package: it313.util  
Classes: 
Observable.java  
Observer.java 
- Module: messageboard1  Illustrate the 
Observer software pattern. Student is the observer; MessageBoard is the 
observable. 
    
Classes:
MessageBoard.java  
Student.java  
Main.java 
- Module: messageboard2   Illustrate the Observer software pattern. In addition to the currentMessage, an
archive of old messages is kept is an array list.
    
Classes:
MessageBoard.java  
Student.java  
Main.java 
- Module: casino   The Manager object is the observer.
The SlotMachine objects are the observables.
    
Classes:
SlotMachine.java  
Manager.java  
Main1.java  
Main2.java 
Patterns2 Project
Zipfile: 
patterns2.zip
JDBC Project
Zipfile: jdbc.zip
JAR File Download:
https://bitbucket.org/xerial/sqlite-jdbc/downloads/
Show how to use Java Database Connectivity (JDBC) classes to create, populate, and query databases.
- Class:   CreateTable.java  Create a simple 
SQL table with three columns (name, gender, age) and two rows (primary keys Alice and Bob).
 
- Class:   LoadKids.java  Create the kids table and
populate it from the data in the input file kids.txt.
 
- Class:   DisplayKids.java  Repeatedly input an id between from 1001 to 1196
then display the name, gender, and age of the kid with that id.
 
- Class:   LoadTransactions.java  
Create the transactions table and
populate it from the data in the input file 
transactions.txt.
 
- Class:   DisplayTransactions.java  Repeatedly input an id between from 1001 to 
5000
then display the buyer, seller, amount, and timestamp with that id.
 
Swing Project
Zipfile: 
swing.zip
- Module swingcontrols:   Show how to create a simple Swing
frame with some controls. Look up these controls in the Java Class Library.
   
MyFrame.java 
- Module listener:   A listener is added to the 
three buttons, which can report which button was clicked. The event handler then 
goes back to the button and obtain the caption from the clicked button.
    
MyFrame.java 
Recursion Project
Zipfile: 
recursion.zip
Multithreading Project
Zipfile: 
multithreading.zip
- Show how to use threads to add numbers in parallel. A class that implements Runnable can be run in a thread.
    Classes:
Adder.java  
Main.java 
SwingGui Project
Zipfile: 
swinggui.zip
- Use the IntelliJ GUI Form Designer to create a simple GUI form:
Creating a Swing GUI Project
    Classes:    MyForm.java
    XML File:
MyForm.form 
KotlinProj Project
Zipfile: kotlinproj.zip
- Look at several sample Kotlin source code files:
- Class: Hello.java   
The customary Hello World program in a new language.
 
- Class: DuckTyping.java  
Kotlin variable initialization.
 
- Class: Strings.java   
Various ways to represent String objects.  Use """ to allow embedded line feeds.
 
- Class: Collections.java   
Create and read from an array and a hash table.
 
- Class: Person.java   
Define a Person class. Getters and setters are automatically generated.
 
- Class: TestPerson.java   
Test the Person class in Person.kt.
 
- Class: TestAssert.java   
The Kotlin require statement is reminiscent of assertEquals. It throws an exception if the statement is not true.