-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3838d24
commit f61c2d5
Showing
98 changed files
with
6,629 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
// ATM.java | ||
// Represents an automated teller machine | ||
|
||
public class ATM { | ||
private boolean userAuthenticated; // whether user is authenticated | ||
private int currentAccountNumber; // current user's account number | ||
private Screen screen; // ATM's screen | ||
private Keypad keypad; // ATM's keypad | ||
private CashDispenser cashDispenser; // ATM's cash dispenser | ||
private DepositSlot depositSlot; // ATM's deposit slot | ||
private BankDatabase bankDatabase; // account information database | ||
|
||
// constants corresponding to main menu options | ||
private static final int BALANCE_INQUIRY = 1; | ||
private static final int WITHDRAWAL = 2; | ||
private static final int DEPOSIT = 3; | ||
private static final int EXIT = 4; | ||
|
||
// no-argument ATM constructor initializes instance variables | ||
public ATM() { | ||
userAuthenticated = false; // user is not authenticated to start | ||
currentAccountNumber = 0; // no current account number to start | ||
screen = new Screen(); // create screen | ||
keypad = new Keypad(); // create keypad | ||
cashDispenser = new CashDispenser(); // create cash dispenser | ||
depositSlot = new DepositSlot(); // create deposit slot | ||
bankDatabase = new BankDatabase(); // create acct info database | ||
} | ||
|
||
// start ATM | ||
public void run() { | ||
// welcome and authenticate user; perform transactions | ||
while (true) { | ||
// loop while user is not yet authenticated | ||
while (!userAuthenticated) { | ||
screen.displayMessageLine("\nWelcome!"); | ||
authenticateUser(); // authenticate user | ||
} | ||
|
||
performTransactions(); // user is now authenticated | ||
userAuthenticated = false; // reset before next ATM session | ||
currentAccountNumber = 0; // reset before next ATM session | ||
screen.displayMessageLine("\nThank you! Goodbye!"); | ||
} | ||
} | ||
|
||
// attempts to authenticate user against database | ||
private void authenticateUser() { | ||
screen.displayMessage("\nPlease enter your account number: "); | ||
int accountNumber = keypad.getInput(); // input account number | ||
screen.displayMessage("\nEnter your PIN: "); // prompt for PIN | ||
int pin = keypad.getInput(); // input PIN | ||
|
||
// set userAuthenticated to boolean value returned by database | ||
userAuthenticated = | ||
bankDatabase.authenticateUser(accountNumber, pin); | ||
|
||
// check whether authentication succeeded | ||
if (userAuthenticated) { | ||
currentAccountNumber = accountNumber; // save user's account # | ||
} | ||
else { | ||
screen.displayMessageLine( | ||
"Invalid account number or PIN. Please try again."); | ||
} | ||
} | ||
|
||
// display the main menu and perform transactions | ||
private void performTransactions() { | ||
// local variable to store transaction currently being processed | ||
Transaction currentTransaction = null; | ||
|
||
boolean userExited = false; // user has not chosen to exit | ||
|
||
// loop while user has not chosen option to exit system | ||
while (!userExited) { | ||
// show main menu and get user selection | ||
int mainMenuSelection = displayMainMenu(); | ||
|
||
// decide how to proceed based on user's menu selection | ||
switch (mainMenuSelection) { | ||
// user chose to perform one of three transaction types | ||
case BALANCE_INQUIRY: | ||
case WITHDRAWAL: | ||
case DEPOSIT: | ||
|
||
// initialize as new object of chosen type | ||
currentTransaction = | ||
createTransaction(mainMenuSelection); | ||
|
||
currentTransaction.execute(); // execute transaction | ||
break; | ||
case EXIT: // user chose to terminate session | ||
screen.displayMessageLine("\nExiting the system..."); | ||
userExited = true; // this ATM session should end | ||
break; | ||
default: // user did not enter an integer from 1-4 | ||
screen.displayMessageLine( | ||
"\nYou did not enter a valid selection. Try again."); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
// display the main menu and return an input selection | ||
private int displayMainMenu() { | ||
screen.displayMessageLine("\nMain menu:"); | ||
screen.displayMessageLine("1 - View my balance"); | ||
screen.displayMessageLine("2 - Withdraw cash"); | ||
screen.displayMessageLine("3 - Deposit funds"); | ||
screen.displayMessageLine("4 - Exit\n"); | ||
screen.displayMessage("Enter a choice: "); | ||
return keypad.getInput(); // return user's selection | ||
} | ||
|
||
// return object of specified Transaction subclass | ||
private Transaction createTransaction(int type) { | ||
Transaction temp = null; // temporary Transaction variable | ||
|
||
// determine which type of Transaction to create | ||
switch (type) { | ||
case BALANCE_INQUIRY: // create new BalanceInquiry transaction | ||
temp = new BalanceInquiry( | ||
currentAccountNumber, screen, bankDatabase); | ||
break; | ||
case WITHDRAWAL: // create new Withdrawal transaction | ||
temp = new Withdrawal(currentAccountNumber, screen, | ||
bankDatabase, keypad, cashDispenser); | ||
break; | ||
case DEPOSIT: // create new Deposit transaction | ||
temp = new Deposit(currentAccountNumber, screen, | ||
bankDatabase, keypad, depositSlot); | ||
break; | ||
} | ||
|
||
return temp; // return the newly created object | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
/************************************************************************** | ||
* (C) Copyright 1992-2018 by Deitel & Associates, Inc. and * | ||
* Pearson Education, Inc. All Rights Reserved. * | ||
* * | ||
* DISCLAIMER: The authors and publisher of this book have used their * | ||
* best efforts in preparing the book. These efforts include the * | ||
* development, research, and testing of the theories and programs * | ||
* to determine their effectiveness. The authors and publisher make * | ||
* no warranty of any kind, expressed or implied, with regard to these * | ||
* programs or to the documentation contained in these books. The authors * | ||
* and publisher shall not be liable in any event for incidental or * | ||
* consequential damages in connection with, or arising out of, the * | ||
* furnishing, performance, or use of these programs. * | ||
*************************************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// ATMCaseStudy.java | ||
// Driver program for the ATM case study | ||
|
||
public class ATMCaseStudy { | ||
// main method creates and runs the ATM | ||
public static void main(String[] args) { | ||
ATM theATM = new ATM(); | ||
theATM.run(); | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
/************************************************************************** | ||
* (C) Copyright 1992-2018 by Deitel & Associates, Inc. and * | ||
* Pearson Education, Inc. All Rights Reserved. * | ||
* * | ||
* DISCLAIMER: The authors and publisher of this book have used their * | ||
* best efforts in preparing the book. These efforts include the * | ||
* development, research, and testing of the theories and programs * | ||
* to determine their effectiveness. The authors and publisher make * | ||
* no warranty of any kind, expressed or implied, with regard to these * | ||
* programs or to the documentation contained in these books. The authors * | ||
* and publisher shall not be liable in any event for incidental or * | ||
* consequential damages in connection with, or arising out of, the * | ||
* furnishing, performance, or use of these programs. * | ||
*************************************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Account.java | ||
// Represents a bank account | ||
|
||
public class Account { | ||
private int accountNumber; // account number | ||
private int pin; // PIN for authentication | ||
private double availableBalance; // funds available for withdrawal | ||
private double totalBalance; // funds available + pending deposits | ||
|
||
// Account constructor initializes attributes | ||
public Account(int theAccountNumber, int thePIN, | ||
double theAvailableBalance, double theTotalBalance) { | ||
accountNumber = theAccountNumber; | ||
pin = thePIN; | ||
availableBalance = theAvailableBalance; | ||
totalBalance = theTotalBalance; | ||
} | ||
|
||
// determines whether a user-specified PIN matches PIN in Account | ||
public boolean validatePIN(int userPIN) { | ||
if (userPIN == pin) { | ||
return true; | ||
} | ||
else { | ||
return false; | ||
} | ||
} | ||
|
||
// returns available balance | ||
public double getAvailableBalance() { | ||
return availableBalance; | ||
} | ||
|
||
// returns the total balance | ||
public double getTotalBalance() { | ||
return totalBalance; | ||
} | ||
|
||
// credits an amount to the account | ||
public void credit(double amount) { | ||
totalBalance += amount; // add to total balance | ||
} | ||
|
||
// debits an amount from the account | ||
public void debit(double amount) { | ||
availableBalance -= amount; // subtract from available balance | ||
totalBalance -= amount; // subtract from total balance | ||
} | ||
|
||
// returns account number | ||
public int getAccountNumber() { | ||
return accountNumber; | ||
} | ||
} | ||
|
||
|
||
|
||
/************************************************************************** | ||
* (C) Copyright 1992-2018 by Deitel & Associates, Inc. and * | ||
* Pearson Education, Inc. All Rights Reserved. * | ||
* * | ||
* DISCLAIMER: The authors and publisher of this book have used their * | ||
* best efforts in preparing the book. These efforts include the * | ||
* development, research, and testing of the theories and programs * | ||
* to determine their effectiveness. The authors and publisher make * | ||
* no warranty of any kind, expressed or implied, with regard to these * | ||
* programs or to the documentation contained in these books. The authors * | ||
* and publisher shall not be liable in any event for incidental or * | ||
* consequential damages in connection with, or arising out of, the * | ||
* furnishing, performance, or use of these programs. * | ||
*************************************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Fig. 36.30: AdditionProblemProvider.java | ||
// AdditionProblemProvider implementation of interface | ||
// ProblemProvider for the MathTutor app. | ||
package com.deitel.additionprovider; | ||
|
||
import java.util.Random; | ||
import com.deitel.mathtutor.spi.Problem; | ||
import com.deitel.mathtutor.spi.ProblemProvider; | ||
|
||
public class AdditionProblemProvider implements ProblemProvider { | ||
private static Random random = new Random(); | ||
|
||
// returns a new addition problem | ||
@Override | ||
public Problem getProblem() { | ||
return new Problem(random.nextInt(10), random.nextInt(10), "+") { | ||
// override getResult to add the operands | ||
@Override | ||
public int getResult() { | ||
return getLeftOperand() + getRightOperand(); | ||
} | ||
}; | ||
} | ||
} | ||
|
||
|
||
|
||
/************************************************************************** | ||
* (C) Copyright 1992-2018 by Deitel & Associates, Inc. and * | ||
* Pearson Education, Inc. All Rights Reserved. * | ||
* * | ||
* DISCLAIMER: The authors and publisher of this book have used their * | ||
* best efforts in preparing the book. These efforts include the * | ||
* development, research, and testing of the theories and programs * | ||
* to determine their effectiveness. The authors and publisher make * | ||
* no warranty of any kind, expressed or implied, with regard to these * | ||
* programs or to the documentation contained in these books. The authors * | ||
* and publisher shall not be liable in any event for incidental or * | ||
* consequential damages in connection with, or arising out of, the * | ||
* furnishing, performance, or use of these programs. * | ||
*************************************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package com.deitel.welcomerestjson; | ||
|
||
import java.util.Set; | ||
import javax.ws.rs.core.Application; | ||
|
||
/** | ||
* | ||
* @author Paul Deitel | ||
*/ | ||
@javax.ws.rs.ApplicationPath("webresources") | ||
public class ApplicationConfig extends Application { | ||
|
||
@Override | ||
public Set<Class<?>> getClasses() { | ||
Set<Class<?>> resources = new java.util.HashSet<>(); | ||
addRestResourceClasses(resources); | ||
return resources; | ||
} | ||
|
||
/** | ||
* Do not modify addRestResourceClasses() method. | ||
* It is automatically populated with | ||
* all resources defined in the project. | ||
* If required, comment out calling this method in getClasses(). | ||
*/ | ||
private void addRestResourceClasses(Set<Class<?>> resources) { | ||
resources.add(com.deitel.welcomerestjson.WelcomeRESTJSONResource.class); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package com.deitel.equationgeneratorxml; | ||
|
||
import java.util.Set; | ||
import javax.ws.rs.core.Application; | ||
|
||
/** | ||
* | ||
* @author Paul Deitel | ||
*/ | ||
@javax.ws.rs.ApplicationPath("webresources") | ||
public class ApplicationConfig extends Application { | ||
|
||
@Override | ||
public Set<Class<?>> getClasses() { | ||
Set<Class<?>> resources = new java.util.HashSet<>(); | ||
addRestResourceClasses(resources); | ||
return resources; | ||
} | ||
|
||
/** | ||
* Do not modify addRestResourceClasses() method. | ||
* It is automatically populated with | ||
* all resources defined in the project. | ||
* If required, comment out calling this method in getClasses(). | ||
*/ | ||
private void addRestResourceClasses(Set<Class<?>> resources) { | ||
resources.add(com.deitel.equationgeneratorxml.EquationGeneratorXMLResource.class); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* To change this template, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
|
||
package org.netbeans.rest.application.config; | ||
/** | ||
* This class is generated by the Netbeans IDE, | ||
* and registers all REST root resources created in the project. | ||
* Please, DO NOT EDIT this class ! | ||
*/ | ||
@javax.ws.rs.ApplicationPath("resources") | ||
public class ApplicationConfig extends javax.ws.rs.core.Application { | ||
} |
Oops, something went wrong.