Question

Java Programing 1 - 24206-CSC325-0 Project 3 Date Due: 2/28/2020 Bank Account – Part 2 Modify...

Java Programing 1 - 24206-CSC325-0

Project 3

Date Due: 2/28/2020

Bank Account – Part 2

Modify the Bank Account class you created to have the following additional functionality

  • When the object is created, it should create two types of account
    • Checking and Saving ( you can user Boolean variables to identify between these accounts)
    • Initialize balance on both accounts to $0
    • The constructor calls a method called setAccountPassWord()

setAccountPassWord ()

  1. This method asks the user to enter a pin number.
  2. It checks to make sure the Pin number is between 4-8 digit numerical value
  3. It calls another method called encryptData()
  4. the value return from enCryptData is stored as the user security pin number.

enCryptData()

  1. This method takes integer value as its argument
  2. It encrypts the integer value using mod21 encryption security.
  3. Returns the encrypted value to calling function.

Example

                                                12345 %21 - this returns 18 which is the remainder

                          

       656564 % 21 – this returns 20 which is the remainder

Add the following additional methods

Withdraw ()

  1. Asks for security pin.
  2. Checks if pin entered matches the user security
    1. If not, continue to ask user for security pin until valid pin is entered.
  3. Asks if withdraw from checking account or saving account
  4. Checks If withdraw amount is less than balance
  5. Withdraws the amount, and updates account balance

Deposit()

  1. Asks for security pin.
  2. Checks if pin entered matches the user security
    1. If not, continue to ask user for security pin until valid pin is entered.
  3. Asks if withdraw from checking account or saving account
  4. Updates account balance with new balance

Transfer()

  1.         Asks for security pin.
  2. Checks if pin entered matches the user security
    1. If not, continue to ask user for security pin until valid pin is entered.
  3. Asks from and to account to transfer money (checking to saving or saving to checking_
  4. Updates both accounts balance

DisplayBalance()

  1. Asks for security pin.
  2. Checks if pin entered matches the user security
    1. If not, continue to ask user for security pin until valid pin is entered.
  3. Prints the account balance on both checking and Saving

Test your code with the followings

  1. Create an account called myAccount
    1. Call DisplayBalance()
  2. Deposit $100 in saving account
  3. Deposit $150 in checking account
    1. Display Balance
  4. Transfer $50 from saving account into checking account
    1. Display balance
  5. Try to withdraw $200 from your saving account and see what happens.   You must properly display code and inform the end user if there is not funding in the account                  
  6. Withdraw $25 from saving account

     Display Balance

               

Homework Answers

Answer #1

/* Comment are placed for all functions and variables to help explain the code.

Main class consists of the main function that is used for testing our code.

Scanner class is used to take input from user.   */

//importing the necessary files and packages
import java.util.Scanner;
import java.io.*;
import java.util.*;

//This is the class account that form 2 accounts -savings account and checking account
class Account{
private int savingsBalance; //stores the savings account balance
private int checkingBalance; //stores the checkings account balance
private int securityPin; //stores the encrypted security pin

int encryptData(int n) //encrypt a number to mod21 form
{
return n%21;
}

int setAccountPassword() //used to set password when account is created (called by constructor)
{
Scanner s = new Scanner(System.in);
System.out.println("Enter new pin number:");
String pin = s.nextLine();
if(pin.length()>=4&&pin.length()<=8)
{
   for(int i=0;i<pin.length();i++)
   if(!(pin.charAt(i)>='0'&&pin.charAt(i)<='9'))
   return setAccountPassword();
}
else
{
return setAccountPassword();
}
return encryptData(Integer.parseInt(pin));
}

Account() // Account class constructor
{
savingsBalance = 0;
checkingBalance = 0;
securityPin = setAccountPassword();
}

void withdraw() // withdraw an amount from savings or checkings account. Display error for insufficient balance.
{
System.out.println("********* WITHDRAW AMOUNT *********");
Scanner s = new Scanner(System.in);
System.out.println("Enter account pin number:");
String pin = s.nextLine();
if(encryptData(Integer.parseInt(pin))!=securityPin)
withdraw();
System.out.println("press 1 to withdraw from savings account or 2 to withdraw from checking account");   
int option = s.nextInt();
if(option == 1) //withdraw from savings account
{
System.out.println("Enter amount to withdraw:");
int amount = s.nextInt();
if(savingsBalance>=amount)
{
   savingsBalance-=amount;
   System.out.println("Total amount of "+amount+" is withdrawn from savings account");
}
else
{
System.out.println("Insufficient balance to withdraw amount of "+amount+" from savings account");
}
}
else //withdraw from checkings account
{
System.out.println("Enter amount to withdraw:");
int amount = s.nextInt();
if(checkingBalance>=amount)
{
   checkingBalance-=amount;
   System.out.println("Total amount of "+amount+" is withdrawn from checking account");
}
else
{
System.out.println("Insufficient balance to withdraw amount of "+amount+" from checking account");
}
}
}

void deposit() // deposit an amount to savings or checkings account
{
System.out.println("********* DEPOSIT AMOUNT *********");
Scanner s = new Scanner(System.in);
System.out.println("Enter account pin number:");
String pin = s.nextLine();
if(encryptData(Integer.parseInt(pin))!=securityPin)
deposit();
System.out.println("press 1 to deposit to savings account or 2 to deposit to checking account");   
int option = s.nextInt();
System.out.println("Enter amount to deposit:");
int amount = s.nextInt();
if(option == 1) //deposit to savings account
{
  
   savingsBalance+=amount;
   System.out.println("Total amount of "+amount+" is deposited to savings account");
}
else //deposit to checking account
{
   checkingBalance+=amount;
   System.out.println("Total amount of "+amount+" is deposited to checking account");
}
}

void transfer() // transfer an amount from checking to savings or from savings to checking
{
System.out.println("********* TRANSFER AMOUNT *********");
Scanner s = new Scanner(System.in);
System.out.println("Enter account pin number:");
String pin = s.nextLine();
if(encryptData(Integer.parseInt(pin))!=securityPin)
transfer();
System.out.println("press 1 to transfer from checking to savings or 2 to transfer from savings to checking");   
int option = s.nextInt();
if(option==1)// transfer an amount from checking to savings
{
System.out.println("Enter amount to transfer from checking to savings:");
int amount = s.nextInt();
if(checkingBalance>=amount)
{
   checkingBalance-=amount;
savingsBalance+=amount;
   System.out.println("Total amount of "+amount+" is transferred from checking account to savings account");
}
else
{
System.out.println("Insufficient balance to transfer amount of "+amount+" from checking account to savings account");
}
}
else// transfer an amount from savings to checking
{
System.out.println("Enter amount to transfer from savings to checking:");
int amount = s.nextInt();
if(savingsBalance>=amount)
{
savingsBalance-=amount;
   checkingBalance+=amount;
   System.out.println("Total amount of "+amount+" is transferred from savings account to checking account");
}
else
{
System.out.println("Insufficient balance to transfer amount of "+amount+" from savings account to checking account");
}
}
}

void displayBalance() //Display balances of both savings and checking account
{
System.out.println("********* DISPLAY BALANCE *********");
Scanner s = new Scanner(System.in);
System.out.println("Enter account pin number:");
String pin = s.nextLine();
if(encryptData(Integer.parseInt(pin))!=securityPin)
displayBalance();
System.out.println("Savings account balance: "+savingsBalance);
System.out.println("checking account balance: "+checkingBalance);
}

}

//Testing our code
class Main{

   public static void main(String args[])
   {
   Account acc= new Account(); //creating the account
   acc.displayBalance();
   acc.deposit();
   acc.deposit();
   acc.displayBalance();
   acc.transfer();
   acc.displayBalance();
   acc.withdraw();
   acc.withdraw();
   acc.displayBalance();
   }
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
WITH JAVA Follow the instructions in the attached to complete Task#2 and submit work along with...
WITH JAVA Follow the instructions in the attached to complete Task#2 and submit work along with screenshots of your output. I have attached the class code for Task#1 that you can use while completing Task#2. Task#1 CODE /** SocSecException exception class */ public class SocSecException extends Exception { public SocSecException(String error) { super("Invalid the social security number, " + error); } } Task #2 Writing Code to Handle an Exception 1. In the main method: a. The main method should...
Create a client for your BankAccount classcalled BankAccountClient.java.    This a separate file from the BankAccount file....
Create a client for your BankAccount classcalled BankAccountClient.java.    This a separate file from the BankAccount file. Both files must be in the same directory to compile. Display all dollar amounts using the DecimalFormat class. Create an account Ask the user for the type of account, the bank account number, the amount that they will deposit to start the account. Set interest earned to 0. Print the account information using an implicit or explicit call to toString Update an account Use...
Create a simple Java class for a Month object with the following requirements:  This program...
Create a simple Java class for a Month object with the following requirements:  This program will have a header block comment with your name, the course and section, as well as a brief description of what the class does.  All methods will have comments concerning their purpose, their inputs, and their outputs  One integer property: monthNumber (protected to only allow values 1-12). This is a numeric representation of the month (e.g. 1 represents January, 2 represents February,...
CIST 2371 Introduction to Java Unit 03 Lab Due Date: ________ Part 1 – Using methods...
CIST 2371 Introduction to Java Unit 03 Lab Due Date: ________ Part 1 – Using methods Create a folder called Unit03 and put all your source files in this folder. Write a program named Unit03Prog1.java. This program will contain a main() method and a method called printChars() that has the following header: public static void printChars(char c1, char c2) The printChars() method will print out on the console all the characters between c1 and c2 inclusive. It will print 10...
Python: Simple Banking Application Project Solution: • Input file: The program starts with reading in all...
Python: Simple Banking Application Project Solution: • Input file: The program starts with reading in all user information from a given input file. The input file contains information of a user in following order: username, first name, last name, password, account number and account balance. Information is separated with ‘|’. o username is a unique information, so no two users will have same username. Sample input file: Username eaglebank has password 123456, account number of BB12 and balance of $1000....
a. Define the class bankAccount to store a bank customer’s account number and balance. Suppose that...
a. Define the class bankAccount to store a bank customer’s account number and balance. Suppose that account number is of type int, and balance is of type double. Your class should, at least, provide the following operations: set the account number, retrieve the account number, retrieve the balance, deposit and withdraw money, and print account information. Add appropriate constructors. b. Every bank offers a checking account. Derive the class checkingAccount from the class bankAccount (designed in part (a)). This class...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in Lab 2 to obtain a diameter value from the user and compute the volume of a sphere (we assumed that to be the shape of a balloon) in a new program, and implement the following restriction on the user’s input: the user should enter a value for the diameter which is at least 8 inches but not larger than 60 inches. Using an if-else...
Complete this in C++ and explain what is being done. 1      Introduction The functions in the...
Complete this in C++ and explain what is being done. 1      Introduction The functions in the following subsections can all go in one big file called pointerpractice.cpp. 1.1     Basics Write a function, int square 1(int∗ p), that takes a pointer to an int and returns the square of the int that it points to. Write a function, void square 2(int∗ p), that takes a pointer to an int and replaces that int (the one pointed to by p) with its...
Write a Python program named lastNameVolumes that finds the volumes of different 3 D objects such...
Write a Python program named lastNameVolumes that finds the volumes of different 3 D objects such as a cube, sphere, cylinder and cone. In this file there should be four methods defined. Write a method named cubeVolFirstName, which accepts the side of a cube in inches as an argument into the function. The method should calculate the volume of a cube in cubic inches and return the volume. The formula for calculating the volume of a cube is given below....
I NEED TASK 3 ONLY TASK 1 country.py class Country:     def __init__(self, name, pop, area, continent):...
I NEED TASK 3 ONLY TASK 1 country.py class Country:     def __init__(self, name, pop, area, continent):         self.name = name         self.pop = pop         self.area = area         self.continent = continent     def getName(self):         return self.name     def getPopulation(self):         return self.pop     def getArea(self):         return self.area     def getContinent(self):         return self.continent     def setPopulation(self, pop):         self.pop = pop     def setArea(self, area):         self.area = area     def setContinent(self, continent):         self.continent = continent     def __repr__(self):         return (f'{self.name} (pop:{self.pop}, size: {self.area}) in {self.continent} ') TASK 2 Python Program: File: catalogue.py from Country...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT