COMP2396
Loading...
Searching...
No Matches
SmithJob Class Reference
Inheritance diagram for SmithJob:
Collaboration diagram for SmithJob:

Public Member Functions

void run ()
 

Static Public Member Functions

static void main (String[] args)
 

Private Member Functions

String getName ()
 
void makeWithdrawal (int amount)
 

Private Attributes

BankAccount account = new BankAccount()
 

Detailed Description

Definition at line 1 of file SmithJob.java.

Member Function Documentation

◆ getName()

String SmithJob.getName ( )
inlineprivate

Definition at line 39 of file SmithJob.java.

39 {
40 return Thread.currentThread().getName();
41 }

Referenced by makeWithdrawal().

Here is the caller graph for this function:

◆ main()

static void SmithJob.main ( String[] args)
inlinestatic

Definition at line 4 of file SmithJob.java.

4 {
5 SmithJob theJob = new SmithJob();
6 Thread mrSmith = new Thread(theJob);
7 Thread mrsSmith = new Thread(theJob);
8 mrSmith.setName("Mr. Smith");
9 mrsSmith.setName("Mrs. Smith");
10 mrSmith.start();
11 mrsSmith.start();
12 }

◆ makeWithdrawal()

void SmithJob.makeWithdrawal ( int amount)
inlineprivate

Definition at line 20 of file SmithJob.java.

20 {
21 if (account.getBalance() >= amount) {
22 System.out.println(getName() + " is about to withdraw");
23 try {
24 System.out.println(getName() + " is going to sleep");
25 Thread.sleep(500);
26 } catch (Exception ex) { ex.printStackTrace(); }
27 System.out.println(getName() + " wakes up");
28 account.withdraw(amount);
29 System.out.println(getName() + " completes the withdrawal");
30 if (account.getBalance() < 0) {
31 System.out.println("Overdrawn!");
32 }
33 }
34 else {
35 System.out.println("Not enough money for " + getName());
36 }
37 }
void withdraw(int amount)
int getBalance()
String getName()
Definition SmithJob.java:39
BankAccount account
Definition SmithJob.java:2

References account, BankAccount.getBalance(), getName(), and BankAccount.withdraw().

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ run()

void SmithJob.run ( )
inline

Definition at line 14 of file SmithJob.java.

14 {
15 for (int x = 0; x < 2; x++) {
17 }
18 }
void makeWithdrawal(int amount)
Definition SmithJob.java:20

References makeWithdrawal().

Here is the call graph for this function:

Member Data Documentation

◆ account

BankAccount SmithJob.account = new BankAccount()
private

Definition at line 2 of file SmithJob.java.

Referenced by makeWithdrawal().


The documentation for this class was generated from the following file: