BankSimulator

Java program by George Wright Y9 Age ~14, converted to Oxygene for Java by PPS

Introduction

This program, which George developed while beginning to learn the Java language, is packed with technical features detailed in the next section. We converted the code to Oxygene for Java and made a few changes. The user interface is neatly constructed, as shown by these screenshots.

Enter Pin

Enter Pin

Menu

Menu

Transfer

Transfer

Confirmation

Confirmation

One of the many error messages

One of the many error messages

Create New User

Create New User

We hope that banks will not get any ideas from George's penalty for entering the wrong password three times! Students intending to write a similar application should think of a more realistic outcome. You could also (1) encrypt passwords for storage and (2) store a list of passwords used by each customer in order to prohibit their re-use. It would also be desirable to be able to delete a user other than by editing the CSV file.

Technical Features

The program benefits from these features:
  • object-oriented code;
  • extensive use of inheritance including abstract classes;
  • impressive validation with specific error messages;
  • error trapping;
  • use of Swing components;
  • string manipulation;
  • file handling;
  • use of generics;
  • use of inbuilt routines including charAt, format, length, substring, toCharArray (String), toString (Integer), parseDouble (Double) add, subtract, toString (BigInteger), sort (Collections), dispose, getContentPane, setDefaultCloseOperation, setTitle, setSize, setResizable, setLocation, setAlwaysOnTop, addWindowListener (JFrame), addActionListener (JButton), addItem (JCombobox), equals (Object), getSource (ActionEvent), getText (JTextComponent) and hasNext (Scanner).

In addition, the conversion to Oxygene for Java is notable for:

  • use of different namespaces for classes within the project;
  • source files sorted into folders as shown near the end of the project file below;
  • this line of code to implement only one of many methods in the interface:
    frame.addWindowListener(new interface WindowListener(windowClosing := @windowClosing));.

Sample CSV file

See the contents below of the Accounts.csv file that we used to test the application. It is placed in a folder named csv within the folder that contains the executable file BankSimulator.jar. The Accounts.csv file must not end with a blank line.

Surname,First Name,Pin Code,Balance,Tries Left 
Andrews,Amelia,1111,1111.11,3 
Barlow,Brian,2222,2222.22,3 
Crouch,Catherine,3333,3333.33,3 

XML Code in the project file BankSimulator.oxygene

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <Configuration Condition="'$(Configuration)' == ''">Release</Configuration>
    <ProjectGuid>{2447aa91-d726-4983-bf0c-0a84c050fc72}</ProjectGuid>
    <AllowLegacyCreate>False</AllowLegacyCreate>
    <Name>com.It423.BankSimulator</Name>
    <RootNamespace>com.It423.BankSimulator</RootNamespace>
    <DefaultUses />
    <StartupClass>
    </StartupClass>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
    <Optimize>false</Optimize>
    <OutputPath>.\bin\Debug</OutputPath>
    <DefineConstants>DEBUG;TRACE;</DefineConstants>
    <GenerateDebugInfo>True</GenerateDebugInfo>
    <EnableAsserts>True</EnableAsserts>
    <TreatWarningsAsErrors>False</TreatWarningsAsErrors>
    <CaptureConsoleOutput>False</CaptureConsoleOutput>
    <StartMode>Project</StartMode>
    <RegisterForComInterop>False</RegisterForComInterop>
    <CpuType>anycpu</CpuType>
    <RuntimeVersion>v25</RuntimeVersion>
    <XmlDoc>False</XmlDoc>
    <XmlDocWarningLevel>WarningOnPublicMembers</XmlDocWarningLevel>
    <WarnOnCaseMismatch>True</WarnOnCaseMismatch>
    <EnableUnmanagedDebugging>False</EnableUnmanagedDebugging>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
    <Optimize>true</Optimize>
    <OutputPath>.\bin\Release</OutputPath>
    <GenerateDebugInfo>False</GenerateDebugInfo>
    <EnableAsserts>False</EnableAsserts>
    <TreatWarningsAsErrors>False</TreatWarningsAsErrors>
    <CaptureConsoleOutput>False</CaptureConsoleOutput>
    <StartMode>Project</StartMode>
    <RegisterForComInterop>False</RegisterForComInterop>
    <CpuType>anycpu</CpuType>
    <RuntimeVersion>v25</RuntimeVersion>
    <XmlDoc>False</XmlDoc>
    <XmlDocWarningLevel>WarningOnPublicMembers</XmlDocWarningLevel>
    <WarnOnCaseMismatch>True</WarnOnCaseMismatch>
    <EnableUnmanagedDebugging>False</EnableUnmanagedDebugging>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="rt.jar" />
  </ItemGroup>
  <ItemGroup>
    <Folder Include="csv\" />
    <Folder Include="exceptions\" />
    <Folder Include="gui\" />
    <Folder Include="Properties\" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="exceptions\InvalidBalanceException.pas" />
    <Compile Include="exceptions\InvalidNameException.pas" />
    <Compile Include="exceptions\InvalidPinException.pas" />
    <Compile Include="gui\Base.pas" />
    <Compile Include="csv\CSVDatabaseWrite.pas" />
    <Compile Include="csv\CSVBase.pas" />
    <Compile Include="csv\CSVDatabaseRead.pas" />
    <Compile Include="gui\AccountDetails.pas" />
    <Compile Include="gui\BalanceChangeBase.pas" />
    <Compile Include="gui\ChangePinEnterNewPin.pas" />
    <Compile Include="gui\ChangePinEnterOldPin.pas" />
    <Compile Include="gui\ChangePinReenterNewPin.pas" />
    <Compile Include="exceptions\InsufficientFundsException.pas" />
    <Compile Include="gui\CreateUser.pas" />
    <Compile Include="gui\EnterPin.pas" />
    <Compile Include="gui\InputMoney.pas" />
    <Compile Include="gui\Login.pas" />
    <Compile Include="gui\MessageDisplay.pas" />
    <Compile Include="gui\NumPadBase.pas" />
    <Compile Include="gui\TransferFunds.pas" />
    <Compile Include="gui\WithdrawMoney.pas" />
    <Compile Include="BankSimulator.pas" />
  </ItemGroup>
  <Import Project="$(MSBuildExtensionsPath)\RemObjects Software\Oxygene\RemObjects.Oxygene.Cooper.targets" />
  <PropertyGroup>
    <PreBuildEvent />
  </PropertyGroup>
</Project>

Follow the numbered links below to see the Oxygene for Java code.

Programming - a skill for life!

Five programs including RandomPlatformScroller and TowerOfArcher by George Wright