This document shows the whole program for the implementation of the Withdraw operation specication.

Similar documents
This document shows a simpli ed version of the 7 paths derived from the program implementing the Withdraw operation speci cation.

JAC444 - Lecture 11. Remote Method Invocation Segment 2 - Develop RMI Application. Jordan Anastasiade Java Programming Language Course

SampleApp.java. Page 1

AppBisect > PrBisect > class Functie. AppBisect > PrBisect > class Punct. public class Functie { double x(double t) { return t;

COMP16121 Sample Code Lecture 1

jlabel14 = new javax.swing.jlabel(); jlabel15 = new javax.swing.jlabel(); jlabel16 = new javax.swing.jlabel(); jlabel17 = new javax.swing.

Answer on question #61311, Programming & Computer Science / Java

RMI. (Remote Method Invocation)

// autor igre Ivan Programerska sekcija package mine;

Java Programming Summer 2008 LAB. Thursday 8/21/2008

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

1 interface TemperatureSensor extends java.rmi.remote 2 { 3 public double gettemperature() throws java.rmi.remoteexception; 4 public void

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

JAVA RMI. Remote Method Invocation

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Page 1 of 16. Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Network. Dr. Jens Bennedsen, Aarhus University, School of Engineering Aarhus, Denmark

55:182/22C:182. Distributed Application Frameworks Java RMI, CORBA, Web Services (SOAP)

Lampiran A. SOURCE CODE PROGRAM

CSC System Development with Java. Database Connection. Department of Statistics and Computer Science. Budditha Hettige

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Goals. Lecture 7 More GUI programming. The application. The application D&D 12. CompSci 230: Semester JFrame subclass: ListOWords

Distributed Systems. 02r. Java RMI Programming Tutorial. Paul Krzyzanowski TA: Long Zhao Rutgers University Fall 2017

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Contents. Java RMI. Java RMI. Java RMI system elements. Example application processes/machines Client machine Process/Application A

* To change this license header, choose License Headers in Project Properties.

JRadioButton account_type_radio_button2 = new JRadioButton("Current"); ButtonGroup account_type_button_group = new ButtonGroup();

Multiple Choice Questions: Identify the choice that best completes the statement or answers the question. (15 marks)

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

DAFTAR LAMPIRAN. Source Code Java Aplikasi Keyword to Image Renamer Split

Java Graphical User Interfaces AWT (Abstract Window Toolkit) & Swing

17 GUI API: Container 18 Hello world with a GUI 19 GUI API: JLabel 20 GUI API: Container: add() 21 Hello world with a GUI 22 GUI API: JFrame: setdefau

CreateServlet.java

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

RMI Example RMI. CmpE 473 Internet Programming RMI

Remote Procedure Call

CSE 530A. DAOs and MVC. Washington University Fall 2012

Object Interaction. Object Interaction. Introduction. Object Interaction vs. RPCs (2)

package As7BattleShip;

APPENDIX. public void cekroot() { System.out.println("nilai root : "+root.data); }

import java.applet.applet; import java.applet.audioclip; import java.net.url; public class Vjesala2 {

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

#,!" $* ( #+,$ $$ $# -.,$ / 0' ".12 $ $$ 5/ #$" " " $ $ " # $ / 4 * # 6/ 8$8 ' # 6 $! 6$$ #$ * $ $$ ** 4 # 6 # * 0; & *! # #! #(' 7 / $#$ -.

Page 1 of 16. Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Remote Method Invocation

Java Programming Language Advance Feature

Generic architecture

CSci Introduction to Distributed Systems. Communication: RPC In Practice

03 Remote invocation. Request-reply RPC. Coulouris 5 Birrel_Nelson_84.pdf RMI

Last Class: Network Overview. Today: Distributed Systems

Distributed Systems. Distributed Object Systems 2 Java RMI. Java RMI. Example. Applet continued. Applet. slides2.pdf Sep 9,

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Outline. EEC-681/781 Distributed Computing Systems. The OSI Network Architecture. Inter-Process Communications (IPC) Lecture 4

Systems Programming. Bachelor in Telecommunication Technology Engineering Bachelor in Communication System Engineering Carlos III University of Madrid

Remote Method Invocation

* To change this license header, choose License Headers in Project Properties.

Swing - JTextField. Adding a text field to the main window (with tooltips and all)

Distributed Computing

COMPSCI 230 Threading Week8. Figure 1 Thread status diagram [

PlaniSphere. Creating a plug-in for PlaniSphere.

RMI Case Study. A Typical RMI Application

Java Database Connectivity

/** Creates new form NewJFrame */ public NewJFrame() { initcomponents(); initblogsearch(); //initializes Index List box }

!"# $ %&# %####' #&() % # # # #&* # ## +, # -

Questions and Answers. A. RMI allows us to invoke a method of java object that executes on another machine.

Example: Building a Java GUI

Eclipsing Your IDE. Figure 1 The first Eclipse screen.

IBD Intergiciels et Bases de Données

RAIK 183H Examination 2 Solution. November 10, 2014

Example: Building a Java GUI

Hanley s Survival Guide for Visual Applications with NetBeans 2.0 Last Updated: 5/20/2015 TABLE OF CONTENTS

Chapter 10 Inheritance. Big Java by Cay Horstmann Copyright 2009 by John Wiley & Sons. All rights reserved.

Designing an Interactive Jini Service

Handout 14 Graphical User Interface (GUI) with Swing, Event Handling

Midterm assessment - MAKEUP Fall 2010

JAVA CODE JAVA CODE: BINOMIAL TREES OPTION PRICING BINOMIALTREE CLASS PAGE 1

RMI (Remote Method Invocation) Over the year, there have been 3 different approaches to application development:

BSc ( Hons) Computer Science with Network Security. Examinations for / Semester 2

COMP16121 Notes on Mock Exam Questions

Lecture 28. Exceptions and Inner Classes. Goals. We are going to talk in more detail about two advanced Java features:

GUI (Graphic User Interface) Programming. Part 2 (Chapter 8) Chapter Goals. Events, Event Sources, and Event Listeners. Listeners

Complimentary material for the book Software Engineering in the Agile World

CS555: Distributed Systems [Fall 2017] Dept. Of Computer Science, Colorado State University

EAST WEST UNIVERSITY

CSCI 136 Written Exam #1 Fundamentals of Computer Science II Spring 2015

Overview. Lecture 7: Inheritance and GUIs. Inheritance. Example 9/30/2008

Java Never Ends MULTITHREADING 958 Example: A Nonresponsive GUI 959

JFrame & JLabel. By Iqtidar Ali

Unit 5 - Exception Handling & Multithreaded

CSC Java Programming, Fall Java Data Types and Control Constructs

Multimedia Programming

2018/2/5 话费券企业客户接入文档 语雀

CSCI 201L Midterm Written Summer % of course grade

Author - Ashfaque Ahmed

Building a GUI in Java with Swing. CITS1001 extension notes Rachel Cardell-Oliver

The Islamic University Gaza Department of Electrical & Computer Engineering. Midterm Exam Spring 2012 Computer Programming II (Java) ECOM 2324

Written by: Dave Matuszek

Transcription:

This document shows the whole program for the implementation of the Withdraw operation specication. * Account.java * 1 package ATM_BasicClasses; 3 import java.util.date; 4 5 public class Account { 6 public long id; 7 8 public int pass; 9 10 public int balance; 11 1 public int withdraw_limitation_per_day; 13 14 public int withdraw_limitation_of_date_; 15 16 public Date date_; 17 18 public Account(long id, int pass, int balance, 19 int withdraw_limitation_per_day, int withdraw_limitation_of_date_, 0 Date date_) { 1 this.id = id; this.pass = pass; 3 this.balance = balance; 4 this.withdraw_limitation_per_day = withdraw_limitation_per_day; 5 this.withdraw_limitation_of_date_ = withdraw_limitation_of_date_; 6 this.date_ = date_; 7 } 8 } * Command.java * 1 package ATM_BasicClasses; 3 public abstract class Command implements java.io.serializable { 4 public int request_type = -1; 5 6 /* 7 * 0:withdraw 1: deposit : transfer 3: change password 4: show balance 5: 8 * print passbook -1: default 9 */ 10 11 public long id = -1; 1 13 public int password = -1; 14 } * Command_Withdraw.java * 1

1 package ATM_BasicClasses; 3 public class Command_Withdraw extends Command { 4 public int withdraw_amount; 5 6 public Command_Withdraw(long id, int pass, int withdraw_amount) { 7 request_type = 0; 8 this.id = id; 9 this.password = pass; 10 this.withdraw_amount = withdraw_amount; 11 } 1 } * FoundAccount.java * 1 package ATM_BasicClasses; 3 public class FoundAccount { 4 public Account account; 5 6 public boolean found; 7 8 public FoundAccount() { 9 this.account = null; 10 found = false; 11 } 1 13 public FoundAccount(Account account) { 14 if (account!= null) { 15 this.account = account; 16 found = true; 17 } else { 18 this.account = null; 19 found = false; 0 } 1 } } * Response.java * 1 package ATM_BasicClasses; 3 public class Response implements java.io.serializable { 4 } * Response_Withdraw.java * 1 package ATM_BasicClasses; 3 public class Response_Withdraw extends Response { 4 public int success_or_fail; 5 6 /*-1: fail for undetermined reasons;

7 * 0: success; 8 * 1: fail because amount is over the balance 9 * : fail because id/password does not match 10 * 3: fail because amount is over the limitation in one day 11 */ 1 public Response_Withdraw(int result) { 13 success_or_fail = result; 14 } 15 16 } * Accounts.java * 1 package ATM_Database; 3 import java.sql.*; 4 import java.text.simpledateformat; 5 import java.util.date; 6 7 import ATM_BasicClasses.FoundAccount; 8 import ATM_BasicClasses.Account; 9 10 public class Accounts { 11 1 private Connection con; 13 14 private Statement stmt; 15 16 public Accounts() { 17 try { 18 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 19 con = DriverManager.getConnection("jdbc:odbc:bank_accounts"); 0 stmt = con.createstatement(resultset.type_scroll_sensitive, 1 ResultSet.CONCUR_READ_ONLY); 3 } catch (Exception e) { 4 e.printstacktrace(); 5 } 6 } 7 8 public void ReleaseConnection() { 9 try { 30 stmt.close(); 31 con.close(); 3 } catch (Exception e) { 33 e.printstacktrace(); 34 } 35 } 36 37 public FoundAccount Search_Account(long id, int Password) { 38 FoundAccount result = new FoundAccount(); 39 40 try { 3

41 String sql = "SELECT * FROM Account where id=" + id + " And pass=" 4 + Password; 43 ResultSet rs; 44 rs = stmt.executequery(sql); 45 46 if (rs.next()) { 47 Account account = new Account(rs.getLong("id"), rs 48.getInt("pass"), rs.getint("balance"), rs 49.getInt("withdraw_limitation_per_day"), rs 50.getInt("withdraw_limitation_of_date_"), rs 51.getDate("date_")); 5 result = new FoundAccount(account); 53 } 54 } catch (Exception e) { 55 } 56 57 return result; 58 } 59 60 public int Count_Accounts(long id, int Password) { 61 // return the number of accounts with the given id and password 6 int result = 0; 63 64 try { 65 String sql = "SELECT * FROM Account where id=" + id + " And pass=" 66 + Password; 67 ResultSet rs; 68 rs = stmt.executequery(sql); 69 70 while (rs.next()) { 71 result++; 7 } 73 } catch (Exception e) { 74 } 75 76 if (result > 1) { 77 System.out.println("Tell database operator this exception!"); 78 } 79 80 return result; 81 } 8 83 public int Count_Accounts(long id) { 84 // return the number of accounts with the given id 85 int result = 0; 86 87 try { 88 String sql = "SELECT * FROM Account where id=" + id; 89 ResultSet rs; 90 rs = stmt.executequery(sql); 91 9 while (rs.next()) { 93 result++; 4

94 } 95 } catch (Exception e) { 96 } 97 98 if (result > 1) { 99 System.out.println("Tell database operator this exception!"); 100 } 101 10 return result; 103 } 104 105 private boolean contains(account account) { 106 boolean result = false; 107 try { 108 String sql = "SELECT * FROM Account WHERE" + " id = " + account.id 109 + " AND pass = " + account.pass + " AND balance = " 110 + account.balance + " AND withdraw_limitation_per_day = " 111 + account.withdraw_limitation_per_day 11 + " AND withdraw_limitation_of_date_ = " 113 + account.withdraw_limitation_of_date_ + " AND date_ = #" 114 + new SimpleDateFormat("MM/dd/yyyy").format(account.date_) 115 + "#"; 116 117 ResultSet rs = stmt.executequery(sql); 118 119 if (rs.next()) { 10 result = true; 11 } 1 } catch (Exception e) { 13 e.printstacktrace(); 14 } 15 return result; 16 } 17 18 public void Update_Account_Withdraw(Account account, int amount) { 19 try { 130 if (this.contains(account)) { 131 account.balance = account.balance - amount; 13 account.withdraw_limitation_of_date_ = account.withdraw_limitation_of_date_ 133 - amount; 134 135 PreparedStatement Update; 136 137 Update = con.preparestatement("update Account" + " SET" 138 + " balance = " + account.balance 139 + ", withdraw_limitation_of_date_ = " 140 + account.withdraw_limitation_of_date_ + " WHERE id = " 141 + account.id + " "); 14 Update.executeUpdate(); 143 Update.close(); 144 } 145 } catch (Exception e) { 146 e.printstacktrace(); 5

147 } 148 } 149 150 public void Update_Account_Withdraw(Account account, Date date) { 151 // modify date_ as date, 15 // and modify account.withdraw_limitation_of_date_ as 153 // account.withdraw_limitation_per_day 154 try { 155 PreparedStatement Update; 156 157 Update = con.preparestatement("update Account SET" 158 + " withdraw_limitation_of_date_ =" 159 + account.withdraw_limitation_per_day + ", date_ = #" 160 + new SimpleDateFormat("MM/dd/yyyy").format(date) + "#" 161 + " WHERE id = " + account.id + " "); 16 Update.executeUpdate(); 163 164 Update.close(); 165 } catch (Exception e) { 166 e.printstacktrace(); 167 } 168 } 169 170 public void Update_Account_Withdraw(Account account) { 171 // modify date_ as today, 17 // and modify account.withdraw_limitation_of_date_ as 173 // account.withdraw_limitation_per_day 174 this.update_account_withdraw(account, new Date()); 175 } 176 } * CallbackClient.java * 1 package ATM_Machine; 3 import java.rmi.remote; 4 import java.rmi.remoteexception; 5 import ATM_BasicClasses.Response; 6 7 public interface CallbackClient extends Remote { 8 public void receiveresponse(response response) throws RemoteException; 9 } * CallbackClientImpl.java * 1 package ATM_Machine; 3 import java.net.inetaddress; 4 import java.net.malformedurlexception; 5 import java.net.unknownhostexception; 6 import java.rmi.naming; 7 import java.rmi.server.unicastremoteobject; 8 import java.rmi.notboundexception; 6

9 import java.rmi.remoteexception; 10 11 import ATM_BasicClasses.*; 1 import ATM_Server.CallbackServer; 13 14 public class CallbackClientImpl implements CallbackClient { 15 private static nal String CALLBACK_CLIENT_SERVICE_NAME = "callbackclient"; 16 17 private static nal String CALLBACK_SERVER_SERVICE_NAME = "callbackserver"; 18 19 private static nal String CALLBACK_SERVER_MACHINE_NAME = "localhost"; 0 1 private Response response; 3 private boolean responseavailable; 4 5 public CallbackClientImpl() { 6 try { 7 UnicastRemoteObject.exportObject(this); 8 Naming.rebind(CALLBACK_CLIENT_SERVICE_NAME, this); 9 } catch (Exception exc) { 30 System.err 31.println("Error using RMI to register the CallbackClientImpl " 3 + exc); 33 } 34 } 35 36 public void receiveresponse(response response) { 37 this.response = response; 38 this.responseavailable = true; 39 } 40 41 public void sendcommand(command command) { 4 try { 43 String url = "//" + CALLBACK_SERVER_MACHINE_NAME + "/" 44 + CALLBACK_SERVER_SERVICE_NAME; 45 Object remoteserver = Naming.lookup(url); 46 if (remoteserver instanceof CallbackServer) { 47 48 ((CallbackServer) remoteserver).execcommand(command, 49 InetAddress.getLocalHost().getHostName(), 50 CALLBACK_CLIENT_SERVICE_NAME); 51 } 5 responseavailable = false; 53 } catch (RemoteException exc) { 54 System.out.print(exc.toString()); 55 } catch (NotBoundException exc) { 56 } catch (MalformedURLException exc) { 57 } catch (UnknownHostException exc) { 58 } 59 } 60 61 public Response getresponse() { 7

6 return response; 63 } 64 65 public boolean isresponseavailable() { 66 return responseavailable; 67 } 68 } * GUI_MainFrame.java * 1 package ATM_Machine.GUI; 3 import javax.swing.jpanel; 4 import javax.swing.jframe; 5 import java.awt.gridlayout; 6 7 import javax.swing.jbutton; 8 9 import ATM_BasicClasses.*; 10 11 public class GUI_MainFrame extends JFrame { 1 13 private static nal long serialversionuid = 1L; 14 15 public JPanel jcontentpane = null; 16 17 private JButton jbutton = null; 18 19 private JButton jbutton1 = null; 0 1 private JButton jbutton = null; 3 private JButton jbutton3 = null; 4 5 private JButton jbutton4 = null; 6 7 private JButton jbutton5 = null; 8 9 public GUI_Withdraw_1_Insert_Card insert_card = new GUI_Withdraw_1_Insert_Card(); 30 31 public GUI_Withdraw Input_Password input_password = new GUI_Withdraw Input_Password(); 3 33 public GUI_Withdraw_3_Input_Amount input_amount = new GUI_Withdraw_3_Input_Amount(); 34 35 public GUI_Withdraw_4_Start_Withdraw start_withdraw = new GUI_Withdraw_4_Start_Withdraw(); 36 37 public GUI_Withdraw_5_DisplayResult withdraw_result = new GUI_Withdraw_5_DisplayResult(); 38 39 public GUI_ServiceUnavailable serviceunavailable = new GUI_ServiceUnavailable(); 40 41 public Response response; 4 43 public Command command; 8

44 45 /** 46 * This is the default constructor 47 */ 48 public GUI_MainFrame() { 49 super(); 50 initialize(); 51 } 5 53 /** 54 * This method initializes this 55 * 56 * @return void 57 */ 58 private void initialize() { 59 60 this.setsize(338, 17); 61 this.setcontentpane(getjcontentpane()); 6 this.settitle("atm SERVICES"); 63 this.addwindowlistener(new java.awt.event.windowadapter() { 64 public void windowclosing(java.awt.event.windowevent e) { 65 System.out.println("windowClosing()"); 66 System.exit(0); 67 } 68 }); 69 70 insert_card.setmainframe(this); 71 input_password.setmainframe(this); 7 input_amount.setmainframe(this); 73 start_withdraw.setmainframe(this); 74 withdraw_result.setmainframe(this); 75 serviceunavailable.setmainframe(this); 76 } 77 78 /** 79 * This method initializes jcontentpane 80 * 81 * @return javax.swing.jpanel 8 */ 83 private JPanel getjcontentpane() { 84 if (jcontentpane == null) { 85 GridLayout gridlayout = new GridLayout(); 86 gridlayout.setrows(3); 87 gridlayout.sethgap(0); 88 gridlayout.setvgap(0); 89 gridlayout.setcolumns(); 90 jcontentpane = new JPanel(); 91 jcontentpane.setlayout(gridlayout); 9 jcontentpane.add(getjbutton(), null); 93 jcontentpane.add(getjbutton1(), null); 94 jcontentpane.add(getjbutton(), null); 95 jcontentpane.add(getjbutton3(), null); 96 jcontentpane.add(getjbutton4(), null); 9

97 jcontentpane.add(getjbutton5(), null); 98 } 99 return jcontentpane; 100 } 101 10 /** 103 * This method initializes jbutton 104 * 105 * @return javax.swing.jbutton 106 */ 107 private JButton getjbutton() { 108 if (jbutton == null) { 109 jbutton = new JButton(); 110 jbutton.settext("withdraw"); 111 jbutton.addactionlistener(new java.awt.event.actionlistener() { 11 public void actionperformed(java.awt.event.actionevent e) { 113 withdrawservice(); 114 } 115 }); 116 } 117 return jbutton; 118 } 119 10 /** 11 * This method initializes jbutton1 1 * 13 * @return javax.swing.jbutton 14 */ 15 private JButton getjbutton1() { 16 if (jbutton1 == null) { 17 jbutton1 = new JButton(); 18 jbutton1.settext("deposit"); 19 jbutton1.addactionlistener(new java.awt.event.actionlistener() { 130 public void actionperformed(java.awt.event.actionevent e) { 131 depositservice(); 13 } 133 }); 134 135 } 136 return jbutton1; 137 } 138 139 /** 140 * This method initializes jbutton 141 * 14 * @return javax.swing.jbutton 143 */ 144 private JButton getjbutton() { 145 if (jbutton == null) { 146 jbutton = new JButton(); 147 jbutton.settext("transfer"); 148 jbutton.addactionlistener(new java.awt.event.actionlistener() { 149 public void actionperformed(java.awt.event.actionevent e) { 10

150 transferservice(); 151 } 15 }); 153 } 154 return jbutton; 155 } 156 157 /** 158 * This method initializes jbutton3 159 * 160 * @return javax.swing.jbutton 161 */ 16 private JButton getjbutton3() { 163 if (jbutton3 == null) { 164 jbutton3 = new JButton(); 165 jbutton3.settext("change PASSWORD"); 166 jbutton3.addactionlistener(new java.awt.event.actionlistener() { 167 public void actionperformed(java.awt.event.actionevent e) { 168 changepassowrdservice(); 169 170 } 171 }); 17 } 173 return jbutton3; 174 } 175 176 /** 177 * This method initializes jbutton4 178 * 179 * @return javax.swing.jbutton 180 */ 181 private JButton getjbutton4() { 18 if (jbutton4 == null) { 183 jbutton4 = new JButton(); 184 jbutton4.settext("inquire BALANCE"); 185 jbutton4.addactionlistener(new java.awt.event.actionlistener() { 186 public void actionperformed(java.awt.event.actionevent e) { 187 showbalanceservice(); 188 189 } 190 }); 191 } 19 return jbutton4; 193 } 194 195 /** 196 * This method initializes jbutton5 197 * 198 * @return javax.swing.jbutton 199 */ 00 private JButton getjbutton5() { 01 if (jbutton5 == null) { 0 jbutton5 = new JButton(); 11

03 jbutton5.settext("print PASSBOOK"); 04 jbutton5.addactionlistener(new java.awt.event.actionlistener() { 05 public void actionperformed(java.awt.event.actionevent e) { 06 printpassbookservice(); 07 08 } 09 }); 10 } 11 return jbutton5; 1 } 13 14 private void withdrawservice() { 15 this.settitle("withdraw_service"); 16 this.setcontentpane(insert_card); 17 this.setvisible(true); 18 } 19 0 private void depositservice() { 1 this.settitle("warning!"); this.setcontentpane(serviceunavailable); 3 this.setvisible(true); 4 } 5 6 private void transferservice() { 7 this.settitle("warning!"); 8 this.setcontentpane(serviceunavailable); 9 this.setvisible(true); 30 } 31 3 private void changepassowrdservice() { 33 this.settitle("warning!"); 34 this.setcontentpane(serviceunavailable); 35 this.setvisible(true); 36 } 37 38 private void showbalanceservice() { 39 this.settitle("warning!"); 40 this.setcontentpane(serviceunavailable); 41 this.setvisible(true); 4 } 43 44 private void printpassbookservice() { 45 this.settitle("warning!"); 46 this.setcontentpane(serviceunavailable); 47 this.setvisible(true); 48 } 49 50 } // @jve:decl-index=0:visual-constraint="10,10" * GUI_ServiceUnavailable.java * 1 package ATM_Machine.GUI; 1

3 import javax.swing.jpanel; 4 import javax.swing.jlabel; 5 import javax.swing.jbutton; 6 import javax.swing.swingconstants; 7 import java.awt.font; 8 import java.awt.flowlayout; 9 10 public class GUI_ServiceUnavailable extends JPanel { 11 1 private static nal long serialversionuid = 1L; 13 14 private JLabel jlabel = null; 15 16 private JButton jbutton = null; 17 18 private GUI_MainFrame mainframe; 19 0 /** 1 * This is the default constructor */ 3 public GUI_ServiceUnavailable() { 4 super(); 5 initialize(); 6 } 7 8 public void setmainframe(gui_mainframe mainframe) { 9 this.mainframe = mainframe; 30 } 31 3 /** 33 * This method initializes this 34 * 35 * @return void 36 */ 37 private void initialize() { 38 FlowLayout owlayout = new FlowLayout(); 39 owlayout.sethgap(50); 40 owlayout.setvgap(50); 41 jlabel = new JLabel(); 4 43 jlabel.settext("sorry! The service is not available!"); 44 jlabel.setfont(new Font("Dialog", Font.ITALIC, 14)); 45 jlabel.sethorizontalalignment(swingconstants.center); 46 this.setlayout(owlayout); 47 this.setsize(318, 195); 48 this.add(jlabel, null); 49 this.add(getjbutton(), null); 50 } 51 5 /** 53 * This method initializes jbutton 54 * 55 * @return javax.swing.jbutton 13

56 */ 57 private JButton getjbutton() { 58 if (jbutton == null) { 59 jbutton = new JButton(); 60 jbutton.settext("ok"); 61 jbutton.addactionlistener(new java.awt.event.actionlistener() { 6 public void actionperformed(java.awt.event.actionevent e) { 63 mainframe.settitle("atm SERVICES"); 64 if (mainframe.getcontentpane()!= mainframe.jcontentpane) 65 mainframe.setcontentpane(mainframe.jcontentpane); 66 } 67 }); 68 } 69 return jbutton; 70 } 71 7 } // @jve:decl-index=0:visual-constraint="10,10" * GUI_Withdraw_1_Insert_Card.java * 1 package ATM_Machine.GUI; 3 import javax.swing.jpanel; 4 import javax.swing.jlabel; 5 import javax.swing.jbutton; 6 import javax.swing.swingconstants; 7 import java.awt.font; 8 import java.awt.flowlayout; 9 import javax.swing.jtextfield; 10 import java.awt.dimension; 11 1 public class GUI_Withdraw_1_Insert_Card extends JPanel { 13 14 private static nal long serialversionuid = 1L; 15 16 private JLabel jlabel = null; 17 18 private JButton jbutton = null; 19 0 private JTextField jtextfield = null; 1 private JButton jbutton1 = null; 3 4 private long id = -1; 5 6 private GUI_MainFrame mainframe; 7 8 /** 9 * This is the default constructor 30 */ 31 public GUI_Withdraw_1_Insert_Card() { 3 super(); 33 initialize(); 14

34 } 35 36 public void setmainframe(gui_mainframe mainframe) { 37 this.mainframe = mainframe; 38 } 39 40 /** 41 * This method initializes this 4 * 43 * @return void 44 */ 45 private void initialize() { 46 FlowLayout owlayout = new FlowLayout(); 47 owlayout.sethgap(50); 48 owlayout.setvgap(30); 49 jlabel = new JLabel(); 50 51 jlabel.settext("please insert your card."); 5 jlabel.setfont(new Font("Dialog", Font.ITALIC, 14)); 53 jlabel.sethorizontalalignment(swingconstants.center); 54 this.setlayout(owlayout); 55 this.setsize(318, 195); 56 this.add(jlabel, null); 57 this.add(getjtextfield(), null); 58 this.add(getjbutton1(), null); 59 this.add(getjbutton(), null); 60 } 61 6 /** 63 * This method initializes jbutton 64 * 65 * @return javax.swing.jbutton 66 */ 67 private JButton getjbutton() { 68 if (jbutton == null) { 69 jbutton = new JButton(); 70 jbutton.settext("next"); 71 jbutton.setenabled(false); 7 jbutton.setpreferredsize(new Dimension(84, 6)); 73 jbutton.addactionlistener(new java.awt.event.actionlistener() { 74 public void actionperformed(java.awt.event.actionevent e) { 75 try { 76 id = Long.parseLong(jTextField.getText()); 77 mainframe.setcontentpane(mainframe.input_password); 78 mainframe.setvisible(true); 79 } catch (NumberFormatException e1) { 80 setjtextfield(); 81 System.out 8.println("There exists a number format exception!"); 83 } 84 } 85 }); 86 } 15

87 return jbutton; 88 } 89 90 /** 91 * This method initializes jtextfield 9 * 93 * @return javax.swing.jtextfield 94 */ 95 private JTextField getjtextfield() { 96 if (jtextfield == null) { 97 jtextfield = new JTextField(); 98 jtextfield.settext(""); 99 jtextfield.setpreferredsize(new Dimension(00, 0)); 100 jtextfield.addkeylistener(new java.awt.event.keyadapter() { 101 public void keyreleased(java.awt.event.keyevent e) { 10 try { 103 Long.parseLong(jTextField.getText()); 104 jbutton.setenabled(true); 105 } catch (NumberFormatException e1) { 106 jbutton.setenabled(false); 107 } 108 } 109 }); 110 } 111 return jtextfield; 11 } 113 114 public void setjtextfield() { 115 id = -1; 116 jtextfield.settext(""); 117 jbutton.setenabled(false); 118 } 119 10 /** 11 * This method initializes jbutton1 1 * 13 * @return javax.swing.jbutton 14 */ 15 private JButton getjbutton1() { 16 if (jbutton1 == null) { 17 jbutton1 = new JButton(); 18 jbutton1.settext("previous"); 19 jbutton1.addactionlistener(new java.awt.event.actionlistener() { 130 public void actionperformed(java.awt.event.actionevent e) { 131 setjtextfield(); 13 133 mainframe.setcontentpane(mainframe.jcontentpane); 134 mainframe.setvisible(true); 135 } 136 }); 137 } 138 return jbutton1; 139 } 16

140 141 public long getid() { 14 return id; 143 } 144 145 public void setid(long id) { 146 this.id = id; 147 } 148 } // @jve:decl-index=0:visual-constraint="10,10" * GUI_Withdraw Input_Password.java * 1 package ATM_Machine.GUI; 3 import javax.swing.jpanel; 4 import javax.swing.jlabel; 5 import javax.swing.jbutton; 6 import javax.swing.swingconstants; 7 import java.awt.font; 8 import java.awt.flowlayout; 9 import java.awt.dimension; 10 import javax.swing.jpasswordfield; 11 1 public class GUI_Withdraw Input_Password extends JPanel { 13 14 private static nal long serialversionuid = 1L; 15 16 private JLabel jlabel = null; 17 18 private JButton jbutton = null; 19 0 private JButton jbutton1 = null; 1 private JPasswordField jpasswordfield = null; 3 4 private int pass = -1; 5 6 private GUI_MainFrame mainframe; 7 8 /** 9 * This is the default constructor 30 */ 31 public GUI_Withdraw Input_Password() { 3 super(); 33 initialize(); 34 } 35 36 public void setmainframe(gui_mainframe mainframe) { 37 this.mainframe = mainframe; 38 } 39 40 /** 41 * This method initializes this 17

4 * 43 * @return void 44 */ 45 private void initialize() { 46 FlowLayout owlayout = new FlowLayout(); 47 owlayout.sethgap(50); 48 owlayout.setvgap(30); 49 jlabel = new JLabel(); 50 51 jlabel.settext("please input your password."); 5 jlabel.setfont(new Font("Dialog", Font.ITALIC, 14)); 53 jlabel.sethorizontalalignment(swingconstants.center); 54 this.setlayout(owlayout); 55 this.setsize(318, 195); 56 this.add(jlabel, null); 57 this.add(getjpasswordfield(), null); 58 this.add(getjbutton1(), null); 59 this.add(getjbutton(), null); 60 } 61 6 /** 63 * This method initializes jbutton 64 * 65 * @return javax.swing.jbutton 66 */ 67 private JButton getjbutton() { 68 if (jbutton == null) { 69 jbutton = new JButton(); 70 jbutton.settext("next"); 71 jbutton.setenabled(false); 7 jbutton.setpreferredsize(new Dimension(84, 6)); 73 jbutton.addactionlistener(new java.awt.event.actionlistener() { 74 public void actionperformed(java.awt.event.actionevent e) { 75 try { 76 pass = Integer.parseInt(new String(jPasswordField 77.getPassword())); 78 mainframe.setcontentpane(mainframe.input_amount); 79 mainframe.setvisible(true); 80 } catch (NumberFormatException e1) { 81 setjpasswordfield(); 8 System.out 83.println("There exists a number format exception!"); 84 } 85 86 } 87 }); 88 } 89 return jbutton; 90 } 91 9 /** 93 * This method initializes jbutton1 94 * 18

95 * @return javax.swing.jbutton 96 */ 97 private JButton getjbutton1() { 98 if (jbutton1 == null) { 99 jbutton1 = new JButton(); 100 jbutton1.settext("previous"); 101 jbutton1.addactionlistener(new java.awt.event.actionlistener() { 10 public void actionperformed(java.awt.event.actionevent e) { 103 setjpasswordfield(); 104 105 mainframe.setcontentpane(mainframe.insert_card); 106 mainframe.setvisible(true); 107 } 108 }); 109 } 110 return jbutton1; 111 } 11 113 /** 114 * This method initializes jpasswordfield 115 * 116 * @return javax.swing.jpasswordfield 117 */ 118 private JPasswordField getjpasswordfield() { 119 if (jpasswordfield == null) { 10 jpasswordfield = new JPasswordField(); 11 jpasswordfield.setpreferredsize(new Dimension(00, 0)); 1 jpasswordfield.addkeylistener(new java.awt.event.keyadapter() { 13 public void keyreleased(java.awt.event.keyevent e) { 14 try { 15 Integer.parseInt(new String(jPasswordField 16.getPassword())); 17 jbutton.setenabled(true); 18 } catch (NumberFormatException e1) { 19 jbutton.setenabled(false); 130 } 131 } 13 }); 133 } 134 return jpasswordfield; 135 } 136 137 public void setjpasswordfield() { 138 pass = -1; 139 jpasswordfield.settext(""); 140 jbutton.setenabled(false); 141 } 14 143 public int getpass() { 144 return pass; 145 } 146 147 public void setpass(int pass) { 19

148 this.pass = pass; 149 } 150 } // @jve:decl-index=0:visual-constraint="10,10" * GUI_Withdraw_3_Input_Amount.java * 1 package ATM_Machine.GUI; 3 import javax.swing.jpanel; 4 import javax.swing.jlabel; 5 import javax.swing.jbutton; 6 import javax.swing.swingconstants; 7 import java.awt.font; 8 import java.awt.flowlayout; 9 import javax.swing.jtextfield; 10 import java.awt.dimension; 11 1 public class GUI_Withdraw_3_Input_Amount extends JPanel { 13 14 private static nal long serialversionuid = 1L; 15 16 private JLabel jlabel = null; 17 18 private JButton jbutton = null; 19 0 private JTextField jtextfield = null; 1 private JButton jbutton1 = null; 3 4 private int withdraw_amount = -1; 5 6 private GUI_MainFrame mainframe; 7 8 /** 9 * This is the default constructor 30 */ 31 public GUI_Withdraw_3_Input_Amount() { 3 super(); 33 initialize(); 34 } 35 36 public void setmainframe(gui_mainframe mainframe) { 37 this.mainframe = mainframe; 38 } 39 40 /** 41 * This method initializes this 4 * 43 * @return void 44 */ 45 private void initialize() { 46 FlowLayout owlayout = new FlowLayout(); 47 owlayout.sethgap(50); 0

48 owlayout.setvgap(30); 49 jlabel = new JLabel(); 50 51 jlabel.settext("please input the amount to withdraw."); 5 jlabel.setfont(new Font("Dialog", Font.ITALIC, 14)); 53 jlabel.sethorizontalalignment(swingconstants.center); 54 55 this.setlayout(owlayout); 56 this.setsize(318, 195); 57 this.setbackground(null); 58 this.add(jlabel, null); 59 this.add(getjtextfield(), null); 60 this.add(getjbutton1(), null); 61 this.add(getjbutton(), null); 6 } 63 64 /** 65 * This method initializes jbutton 66 * 67 * @return javax.swing.jbutton 68 */ 69 private JButton getjbutton() { 70 if (jbutton == null) { 71 jbutton = new JButton(); 7 jbutton.settext("next"); 73 jbutton.setenabled(false); 74 jbutton.setpreferredsize(new Dimension(84, 6)); 75 jbutton.addactionlistener(new java.awt.event.actionlistener() { 76 public void actionperformed(java.awt.event.actionevent e) { 77 try { 78 withdraw_amount = Integer 79.parseInt(jTextField.getText()); 80 mainframe.start_withdraw 81.set_withdraw_amount(withdraw_amount); 8 mainframe.setcontentpane(mainframe.start_withdraw); 83 84 } catch (NumberFormatException e1) { 85 setjtextfield(); 86 System.out 87.println("There exists a number format exception!"); 88 } 89 90 } 91 }); 9 } 93 return jbutton; 94 } 95 96 /** 97 * This method initializes jtextfield 98 * 99 * @return javax.swing.jtextfield 100 */ 1

101 private JTextField getjtextfield() { 10 if (jtextfield == null) { 103 jtextfield = new JTextField(); 104 jtextfield.settext(""); 105 jtextfield.setpreferredsize(new Dimension(00, 0)); 106 jtextfield.addkeylistener(new java.awt.event.keyadapter() { 107 public void keyreleased(java.awt.event.keyevent e) { 108 try { 109 Integer.parseInt(jTextField.getText()); 110 jbutton.setenabled(true); 111 } catch (NumberFormatException e1) { 11 jbutton.setenabled(false); 113 } 114 } 115 }); 116 } 117 return jtextfield; 118 } 119 10 public void setjtextfield() { 11 withdraw_amount = -1; 1 jbutton.setenabled(false); 13 jtextfield.settext(""); 14 } 15 16 /** 17 * This method initializes jbutton1 18 * 19 * @return javax.swing.jbutton 130 */ 131 private JButton getjbutton1() { 13 if (jbutton1 == null) { 133 jbutton1 = new JButton(); 134 jbutton1.settext("previous"); 135 136 jbutton1.addactionlistener(new java.awt.event.actionlistener() { 137 public void actionperformed(java.awt.event.actionevent e) { 138 setjtextfield(); 139 140 mainframe.setcontentpane(mainframe.input_password); 141 mainframe.setvisible(true); 14 } 143 }); 144 } 145 return jbutton1; 146 } 147 148 public int getwithdrawamount() { 149 return withdraw_amount; 150 } 151 15 public void setwithdrawamount(int withdraw_amount) { 153 this.withdraw_amount = withdraw_amount;

154 } 155 156 } // @jve:decl-index=0:visual-constraint="10,10" * GUI_Withdraw_4_Start_Withdraw.java * 1 package ATM_Machine.GUI; 3 import javax.swing.jpanel; 4 import javax.swing.jlabel; 5 import javax.swing.jbutton; 6 import javax.swing.swingconstants; 7 8 import ATM_BasicClasses.Command_Withdraw; 9 import ATM_BasicClasses.Response_Withdraw; 10 import ATM_Machine.Operation; 11 1 import java.awt.font; 13 import java.awt.flowlayout; 14 import ATM_Machine.Resources.*; 15 16 public class GUI_Withdraw_4_Start_Withdraw extends JPanel { 17 18 private static nal long serialversionuid = 1L; 19 0 private JLabel jlabel = null; 1 private JButton jbutton = null; 3 4 private JButton jbutton1 = null; 5 6 private GUI_MainFrame mainframe; 7 8 /** 9 * This is the default constructor 30 */ 31 public GUI_Withdraw_4_Start_Withdraw() { 3 super(); 33 initialize(); 34 } 35 36 public void setmainframe(gui_mainframe mainframe) { 37 this.mainframe = mainframe; 38 } 39 40 /** 41 * This method initializes this 4 * 43 * @return void 44 */ 45 private void initialize() { 46 FlowLayout owlayout = new FlowLayout(); 47 owlayout.sethgap(50); 3

48 owlayout.setvgap(50); 49 jlabel = new JLabel(); 50 51 jlabel 5.setText("<html>You want to withdraw *** Japanese Yen,<br> are you sure?</html>"); 53 jlabel.setfont(new Font("Dialog", Font.ITALIC, 14)); 54 jlabel.sethorizontalalignment(swingconstants.center); 55 this.setlayout(owlayout); 56 this.setsize(318, 195); 57 this.add(jlabel, null); 58 this.add(getjbutton(), null); 59 this.add(getjbutton1(), null); 60 } 61 6 public void set_withdraw_amount(int amount) { 63 jlabel.settext("<html>you want to withdraw " + amount 64 + " Japanese Yen,<br> are you sure?</html>"); 65 } 66 67 /** 68 * This method initializes jbutton 69 * 70 * @return javax.swing.jbutton 71 */ 7 private JButton getjbutton() { 73 if (jbutton == null) { 74 jbutton = new JButton(); 75 jbutton.settext("yes"); 76 jbutton.addactionlistener(new java.awt.event.actionlistener() { 77 public void actionperformed(java.awt.event.actionevent e) { 78 long id; 79 int pass; 80 int withdraw_amount; 81 8 id = mainframe.insert_card.getid(); 83 pass = mainframe.input_password.getpass(); 84 withdraw_amount = mainframe.input_amount 85.getWithdrawAmount(); 86 87 // We may check the command here. 88 mainframe.command = new Command_Withdraw(id, pass, 89 withdraw_amount); 90 mainframe.response = Operation 91.start_operation(mainframe.command); 9 93 displayresponse(); 94 } 95 }); 96 97 } 98 return jbutton; 99 } 100 4

101 private void displayresponse() { 10 if (mainframe.response instanceof Response_Withdraw) { 103 104 String resultmsg; 105 switch (((Response_Withdraw) mainframe.response).success_or_fail) { 106 case 0: 107 int cash = ((ATM_BasicClasses.Command_Withdraw) mainframe.command).withdraw_amount; 108 resultmsg = "You successfully withdraw " + cash 109 + " Japanese Yen."; 110 break; 111 case 1: 11 resultmsg = Error_Msg.error_msg_001; 113 break; 114 case : 115 resultmsg = Error_Msg.error_msg_00; 116 break; 117 case 3: 118 resultmsg = Error_Msg.error_msg_003; 119 break; 10 default: 11 resultmsg = Error_Msg.error_msg_004; 1 } 13 mainframe.withdraw_result.set_text_for_jlabel(resultmsg); 14 mainframe.setcontentpane(mainframe.withdraw_result); 15 } 16 } 17 18 /** 19 * This method initializes jbutton1 130 * 131 * @return javax.swing.jbutton 13 */ 133 private JButton getjbutton1() { 134 if (jbutton1 == null) { 135 jbutton1 = new JButton(); 136 jbutton1.settext("no"); 137 jbutton1.addactionlistener(new java.awt.event.actionlistener() { 138 public void actionperformed(java.awt.event.actionevent e) { 139 mainframe.setcontentpane(mainframe.input_amount); 140 } 141 }); 14 } 143 return jbutton1; 144 } 145 146 } // @jve:decl-index=0:visual-constraint="10,10" * GUI_Withdraw_5_DisplayResult.java * 1 package ATM_Machine.GUI; 3 import javax.swing.jpanel; 4 import javax.swing.jlabel; 5

5 import javax.swing.jbutton; 6 import javax.swing.swingconstants; 7 8 import ATM_BasicClasses.Response_Withdraw; 9 10 import java.awt.font; 11 import java.awt.flowlayout; 1 13 public class GUI_Withdraw_5_DisplayResult extends JPanel { 14 15 private static nal long serialversionuid = 1L; 16 17 private JLabel jlabel = null; 18 19 private JButton jbutton = null; 0 1 private GUI_MainFrame mainframe; 3 /** 4 * This is the default constructor 5 */ 6 public GUI_Withdraw_5_DisplayResult() { 7 super(); 8 initialize(); 9 } 30 31 /** 3 * This method initializes this 33 * 34 * @return void 35 */ 36 public void setmainframe(gui_mainframe mainframe) { 37 this.mainframe = mainframe; 38 } 39 40 private void initialize() { 41 FlowLayout owlayout = new FlowLayout(); 4 owlayout.sethgap(50); 43 owlayout.setvgap(50); 44 jlabel = new JLabel(); 45 46 jlabel.settext("withdraw_result!"); 47 jlabel.setfont(new Font("Dialog", Font.ITALIC, 14)); 48 jlabel.sethorizontalalignment(swingconstants.center); 49 this.setlayout(owlayout); 50 this.setsize(318, 195); 51 this.add(jlabel, null); 5 this.add(getjbutton(), null); 53 } 54 55 /** 56 * This method initializes jbutton 57 * 6

58 * @return javax.swing.jbutton 59 */ 60 private JButton getjbutton() { 61 if (jbutton == null) { 6 jbutton = new JButton(); 63 jbutton.settext("ok"); 64 jbutton.addactionlistener(new java.awt.event.actionlistener() { 65 public void actionperformed(java.awt.event.actionevent e) { 66 switch (((Response_Withdraw) mainframe.response).success_or_fail) { 67 case 1: 68 case 3: 69 mainframe.settitle("withdraw_services"); 70 if (mainframe.getcontentpane()!= mainframe.input_amount) 71 mainframe.setcontentpane(mainframe.input_amount); 7 mainframe.input_amount.setjtextfield(); 73 break; 74 default: 75 mainframe.settitle("atm SERVICES"); 76 mainframe.insert_card.setjtextfield(); 77 mainframe.input_password.setjpasswordfield(); 78 mainframe.input_amount.setjtextfield(); 79 if (mainframe.getcontentpane()!= mainframe.jcontentpane) 80 mainframe.setcontentpane(mainframe.jcontentpane); 81 } 8 } 83 }); 84 } 85 return jbutton; 86 } 87 88 public void set_text_for_jlabel(string string) { 89 jlabel.settext(string); 90 } 91 9 } // @jve:decl-index=0:visual-constraint="10,10" * Operation.java * 1 package ATM_Machine; 3 import ATM_BasicClasses.Command; 4 import ATM_BasicClasses.Response; 5 6 public class Operation { 7 public static Response start_operation(command command) { 8 CallbackClientImpl callbackclient = new CallbackClientImpl(); 9 callbackclient.sendcommand(command); 10 11 try { 1 while (!callbackclient.isresponseavailable()) { 13 System.out 14.println("Response is not available yet; sleeping for seconds"); 15 Thread.sleep(000); 7

16 } 17 } catch (InterruptedException exc) { 18 } 19 0 return callbackclient.getresponse(); 1 } } * Display_Labels.java * 1 package ATM_Machine.Resources; 3 public enum Display_Labels { 4 5 } * Error_Msg.java * 1 package ATM_Machine.Resources; 3 public class Error_Msg { 4 5 public nal static String error_msg_001 = "Your requested amount is too large."; 6 7 public nal static String error_msg_00 = "Your id/pass is wrong."; 8 9 public nal static String error_msg_003 = "Your requested amount is over the limitation per day."; 10 11 public nal static String error_msg_004 = "You fail to withdraw your cash for unknown reasons!"; 1 } * Success_Msg.java * 1 package ATM_Machine.Resources; 3 public enum Success_Msg { 4 5 } * CallbackServer.java * 1 package ATM_Server; 3 import java.rmi.remote; 4 import java.rmi.remoteexception; 5 import ATM_BasicClasses.Command; 6 7 public interface CallbackServer extends Remote { 8 public void execcommand(command command, String callbackmachine, 9 String callbackobjectname) throws RemoteException; 10 } * CallbackServerDelegate.java * 8

1 package ATM_Server; 3 import java.net.malformedurlexception; 4 import java.rmi.naming; 5 import java.rmi.notboundexception; 6 import java.rmi.remoteexception; 7 import ATM_BasicClasses.*; 8 import ATM_Database.Accounts; 9 import ATM_Machine.CallbackClient; 10 import java.util.date; 11 import java.text.simpledateformat; 1 13 public class CallbackServerDelegate implements Runnable { 14 private Thread processingthread; 15 16 private Command command; 17 18 private String callbackmachine; 19 0 private String callbackobjectname; 1 public CallbackServerDelegate(Command newcommand, 3 String newcallbackmachine, String newcallbackobjectname) { 4 5 command = newcommand; 6 callbackmachine = newcallbackmachine; 7 callbackobjectname = newcallbackobjectname; 8 processingthread = new Thread(this); 9 processingthread.start(); 30 } 31 3 public void run() { 33 Response response = produceresponse(command); 34 sendresponsetoclient(response); 35 } 36 37 private Response produceresponse(command command) {// start operation and 38 // produce a response 39 if (command instanceof Command_Withdraw) { 40 Response_Withdraw response_withdraw; 41 4 Accounts accounts = new Accounts(); 43 44 FoundAccount R = accounts.search_account( 45 ((Command_Withdraw) command).id, 46 ((Command_Withdraw) command).password); 47 48 if (R.found) { 49 50 Date date = new Date(); 51 SimpleDateFormat date_with_format = new SimpleDateFormat( 5 "MM/dd/yyyy"); 9

{ 53 54 if (!date_with_format.format(date).equals( 55 date_with_format.format(r.account.date_))) { 56 accounts.update_account_withdraw(r.account);// update the 57 // withdrawlimitation 58 // and date 59 accounts.releaseconnection(); 60 response_withdraw = (Response_Withdraw) produceresponse(command); 61 } else if (R.account.balance >= ((Command_Withdraw) command).withdraw_amount 6 && R.account.withdraw_limitation_of_date_ >= ((Command_Withdraw) command).withdraw_amo 63 accounts.update_account_withdraw(r.account, 64 ((Command_Withdraw) command).withdraw_amount); 65 response_withdraw = new Response_Withdraw(0); 66 } else if (R.account.balance < ((Command_Withdraw) command).withdraw_amount) { 67 response_withdraw = new Response_Withdraw(1); 68 } else { 69 response_withdraw = new Response_Withdraw(3); 70 } 71 } else 7 response_withdraw = new Response_Withdraw(); 73 74 accounts.releaseconnection(); 75 76 return response_withdraw; 77 } else 78 return new Response(); 79 } 80 81 private void sendresponsetoclient(response response) { 8 try { 83 84 String url = "//" + callbackmachine + "/" + callbackobjectname; 85 Object remoteclient = Naming.lookup(url); 86 87 if (remoteclient instanceof CallbackClient) { 88 ((CallbackClient) remoteclient).receiveresponse(response); 89 } 90 } catch (RemoteException exc) { 91 } catch (NotBoundException exc) { 9 } catch (MalformedURLException exc) { 93 } 94 } 95 } * CallbackServerImpl.java * 1 package ATM_Server; 3 import java.rmi.naming; 4 import java.rmi.server.unicastremoteobject; 5 import ATM_BasicClasses.Command; 6 30

7 public class CallbackServerImpl implements CallbackServer { 8 private static nal String CALLBACK_SERVER_SERVICE_NAME = "callbackserver"; 9 10 public CallbackServerImpl() { 11 try { 1 UnicastRemoteObject.exportObject(this); 13 Naming.rebind(CALLBACK_SERVER_SERVICE_NAME, this); 14 } catch (Exception exc) { 15 System.err 16.println("Error using RMI to register the CallbackServerImpl " 17 + exc); 18 } 19 } 0 1 public void execcommand(command command, String callbackmachine, String callbackobjectname) { 3 new CallbackServerDelegate(command, callbackmachine, callbackobjectname); 4 } 5 } * Run_Server_and_Client.java * 1 package Main; 3 import java.io.ioexception; 4 import ATM_Server.CallbackServerImpl; 5 import ATM_Machine.GUI.GUI_MainFrame; 6 7 public class Run_Server_and_Client { 8 9 /** 10 * @param args 11 */ 1 13 public static void main(string[] args) { 14 // TODO Auto-generated method stub 15 16 System.out.println("Running the RMI compiler (rmic)"); 17 System.out.println(); 18 try { 19 Process p1 = Runtime 0.getRuntime() 1.exec( "C:nnProgram FilesnnJavannjdk1.5.0_09nnbinnnrmic ATM_Server.CallbackServerImpl"); 3 Process p = Runtime 4.getRuntime() 5.exec( 6 "C:nnProgram FilesnnJavannjdk1.5.0_09nnbinnnrmic ATM_Machine.CallbackClientImpl"); 7 p1.waitfor(); 8 p.waitfor(); 9 } catch (IOException exc) { 30 System.err 31.println("Unable to run rmic utility. Exiting application."); 31

3 System.exit(1); 33 } catch (InterruptedException exc) { 34 System.err 35.println("Threading problems encountered while using the rmic utility."); 36 } 37 38 System.out.println("Starting the rmiregistry"); 39 System.out.println(); 40 Process rmiprocess = null; 41 try { 4 rmiprocess = Runtime.getRuntime().exec("rmiregistry"); 43 Thread.sleep(3000); 44 } catch (IOException exc) { 45 System.err 46.println("Unable to start the rmiregistry. Exiting application."); 47 System.exit(1); 48 } catch (InterruptedException exc) { 49 System.err 50.println("Threading problems encountered when starting the rmiregistry."); 51 } 5 53 System.out.println("Creating the client and server objects"); 54 System.out.println(); 55 56 CallbackServerImpl callbackserver = new CallbackServerImpl(); 57 58 new GUI_MainFrame().setVisible(true); 59 } 60 61 } 3