Java - Banking System
Questions/Tutorials for any programming language not covered in other sections.
5 posts
Page 1 of 1
This is one of the bigger ones...so I'll do it little by little. Still need to get it done before tomorrow midnight though
instructions
Create the following classes (keep in mind that only one class in your project should have the
main() method):
o Bank (this class will contain the main() method)
o User
o Account
• The User class must have the following class variables(make sure you pick correct data types
and correct visibility):
o User ID
o Last name
o Middle initial
o First name
o Date of birth
o Address (you will need to have multiple properties for this – street address, city, etc…)
o User type (customer, teller, manager, etc…)
o Social security number
• The User class must have the following methods:
o Getters and setters for each property
• The Account class must have the following class variables:
o Account number
o Account type (checking, savings, line of credit, money market, etc…)
o Account status (active, frozen, closed, etc…)
o Account balance
o Date opened (for date variables, research Java’s Date class on your own)
o Opened by (User ID of the bank employee who opened the account)
o Date of last transaction
• The Account class must have the following methods:
o Getters and setters for accountstatus
o Getters only for account number, account type, balance, date opened, opened by and
date of last transaction
o A method for creating an account. § This method will accept 2 arguments:
• Account type
• Initial deposit amount
§ This method will return account number
§ This method will perform the following actions:
• Assign a value to Account number property (come up with whatever
system you want for account numbers)
• Set account balance to initial deposit amount (passed to this method as
an argument)
• Set account type (passed to this method as an argument)
• Set account status to active (call the setter method for account status
property)
• Set account created date property to current date and time (make sure
to research Java’s Date class)
• Set date of last transaction property to current date and time
• Print a statement telling the user that the account wassuccessfully
opened and what the current balance is.
o A method for depositing money
§ This method will accept one argument:
• Deposit amount
§ This method will perform the following actions:
• Add deposit amount to account balance
• Print a statement telling the user that the deposit wassuccessful and
what the current balance is.
o A method for withdrawing money
§ This method will accept one argument:
• Withdrawal amount
§ This method will perform the following actions:
• Make sure that the account status is active and that user has sufficient
balance. Print appropriate warnings for inactive accounts and
insufficient balances
• Subtract withdrawal amount from account balance
• Print a statement telling the user that the withdrawal was successful
and what the current balance is.
• In the main() method of Bank class, create an instance of Account class (a variable of type
Account)
o Call create account method to create a new account
§ Set account type to “checking”
§ Set initial amount to $1000
o Call deposit method
§ Deposit $500
o Call withdraw method
§ Withdraw $700
Code: Select all
package edu.pitt.BankChen;
import java.util.Scanner;
import java.util.Date;
public class Account {
private int accountNumber;
public String accountType;
public String accountStatus;
public double accountBalance;
private Date dateOpened;
private int openedBy;
private Date lastTransaction;
// Getters and setters
public String getAccountStatus() {
return accountStatus;
}
public void setAccountStatus(String newAccountStatus) {
accountStatus = newAccountStatus;
}
public int getAccountNumber() {
return accountNumber;
}
public String getAccountType() {
return accountType;
}
public double getAccountBalance() {
return accountBalance;
}
public Date getDateOpened() {
return dateOpened;
}
public int getOpenedBy() {
return openedBy;
}
public Date getLastTransaction() {
return lastTransaction;
}
// method for creating an account
public int createAccount(String accountType, double depositAmountInitial) {
int accountNumber = 56995;
return accountNumber;
getAccountBalance(depositAmountInitial);
getAccountType();
accountStatus = "active";
dateOpened = Date();
lastTransaction = Date();
System.out.println("The account was successfully opened. The current balance is " +
accountBalance + ".");
}
private Date Date() {
// TODO Auto-generated method stub
return null;
}
// method for depositing money
public static void deposit(double depositAmt) {
System.out.println("The deposit was successful and the new current balance " +
"is " + (depositAmt + accountBalance) + ".");
}
// method for withdrawing money
public static void withdraw(double withdrawAmt) {
if (accountStatus.equals("active") && accountBalance >= withdrawAmt) {
System.out.println("The withdraw was successful and the new current balance " +
"is " + (accountBalance - withdrawAmt) + ".");
}
else if (accountBalance <= withdrawAmt){
System.out.println("Account balance is insufficient.");
}
else if (accountStatus.equals("inactive")){
System.out.println("Account is inactive.");
}
}
}
Code: Select all
package edu.pitt.BankChen;
import java.util.Scanner;
import java.util.Date;
public class User {
private int userID;
private String lastName;
private String middleInitial;
private String firstName;
private Date birthDate;
private String city;
private String state;
private int zipCode;
private String userType;
private int socialSN;
// Getters and setters
public int getUserID() {
return userID;
}
public void setUserID(int newUserID) {
userID = newUserID;
}
public String getCity() {
return city;
}
public void setCity(String newCity) {
city = newCity;
}
public String getState() {
return state;
}
public void setState(String newState) {
state = newState;
}
public int getZipCode() {
return zipCode;
}
public void setZipCode(int newZipCode) {
zipCode = newZipCode;
}
public String getUserType() {
return userType;
}
public void setUserType(String newUserType) {
userType = newUserType;
}
public int getSocialSN() {
return socialSN;
}
public void setSocialSN(int newSocialSN) {
socialSN = newSocialSN;
}
}
Code: Select all
still got a bunch of errors :/ some parts are really confusingpackage edu.pitt.BankChen;
public class Bank {
public static void main(String[] args) {
Account createAccount = new Account("checking", 1000.00);
Account.deposit(500);
Account.withdraw(700);
}
}
instructions
Create the following classes (keep in mind that only one class in your project should have the
main() method):
o Bank (this class will contain the main() method)
o User
o Account
• The User class must have the following class variables(make sure you pick correct data types
and correct visibility):
o User ID
o Last name
o Middle initial
o First name
o Date of birth
o Address (you will need to have multiple properties for this – street address, city, etc…)
o User type (customer, teller, manager, etc…)
o Social security number
• The User class must have the following methods:
o Getters and setters for each property
• The Account class must have the following class variables:
o Account number
o Account type (checking, savings, line of credit, money market, etc…)
o Account status (active, frozen, closed, etc…)
o Account balance
o Date opened (for date variables, research Java’s Date class on your own)
o Opened by (User ID of the bank employee who opened the account)
o Date of last transaction
• The Account class must have the following methods:
o Getters and setters for accountstatus
o Getters only for account number, account type, balance, date opened, opened by and
date of last transaction
o A method for creating an account. § This method will accept 2 arguments:
• Account type
• Initial deposit amount
§ This method will return account number
§ This method will perform the following actions:
• Assign a value to Account number property (come up with whatever
system you want for account numbers)
• Set account balance to initial deposit amount (passed to this method as
an argument)
• Set account type (passed to this method as an argument)
• Set account status to active (call the setter method for account status
property)
• Set account created date property to current date and time (make sure
to research Java’s Date class)
• Set date of last transaction property to current date and time
• Print a statement telling the user that the account wassuccessfully
opened and what the current balance is.
o A method for depositing money
§ This method will accept one argument:
• Deposit amount
§ This method will perform the following actions:
• Add deposit amount to account balance
• Print a statement telling the user that the deposit wassuccessful and
what the current balance is.
o A method for withdrawing money
§ This method will accept one argument:
• Withdrawal amount
§ This method will perform the following actions:
• Make sure that the account status is active and that user has sufficient
balance. Print appropriate warnings for inactive accounts and
insufficient balances
• Subtract withdrawal amount from account balance
• Print a statement telling the user that the withdrawal was successful
and what the current balance is.
• In the main() method of Bank class, create an instance of Account class (a variable of type
Account)
o Call create account method to create a new account
§ Set account type to “checking”
§ Set initial amount to $1000
o Call deposit method
§ Deposit $500
o Call withdraw method
§ Withdraw $700
Last edited by Jessica on Wed Oct 02, 2013 10:22 pm, edited 1 time in total.
Finally got it done. Would appreciate if I got a bit of help/replies before midnight today
Stuck on these instructions:
Also have no idea if I did the call __ method (in the last part, Bank class) correctly. Don't think I did, getting errors
Stuck on these instructions:
Set account balance to initial deposit amount (passed to this method asNot sure I did the third one correctly but the other two I know I did wrong as I'm getting errors from them
an argument)
• Set account type (passed to this method as an argument)
• Set account status to active (call the setter method for account status
property)
Also have no idea if I did the call __ method (in the last part, Bank class) correctly. Don't think I did, getting errors
I didn't do well on this project, and I'm supposed to add/improve/remove on it, which then I have to turn in again, due this Wed @ midnight :/ Can someone check this so it's accurate so then I could try to do the next assignment with new instructions? Project attached.
You do not have the required permissions to view the files attached to this post.
well I guess this is what you requested
Account.java
Bank.java
User.java
Account.java
Code: Select all
import java.util.Date;
public class Account {
private int accountNumber;
private String accountType;
private String accountStatus;
private double balance;
private Date dateOpened;
private int openedBy;
private Date lastTransaction;
public Account(String accountType, double balance) {
accountNumber = createAccount(accountType, balance);
}
public int createAccount(String accountType, double balance) {
int accNumber = 56995;
this.accountType = accountType;
this.balance = balance;
setAccountStatus("active");
dateOpened = new Date();
lastTransaction = new Date();
//set opendBy?
System.out.println("The account was successfully opened. The current balance is " + balance + ".");
return accNumber;
}
public void deposit(double amount) {
balance += amount;
System.out.println("The deposit was successful and the new current balance is " + balance + ".");
}
public void withdraw(double amount) {
if (accountStatus.equals("active") && balance >= amount) {
balance -= amount;
System.out.println("The withdraw was successful and the new current balance is " + balance + ".");
} else if (balance < amount) {
System.out.println("Account balance is insufficient.");
} else if (accountStatus.equals("inactive")) {
System.out.println("Account is inactive.");
}
}
public String getAccountStatus() {
return accountStatus;
}
public void setAccountStatus(String accountStatus) {
this.accountStatus = accountStatus;
}
public int getAccountNumber() {
return accountNumber;
}
public String getAccountType() {
return accountType;
}
public double getBalance() {
return balance;
}
public Date getDateOpened() {
return dateOpened;
}
public int getOpenedBy() {
return openedBy;
}
public Date getLastTransaction() {
return lastTransaction;
}
}
Bank.java
Code: Select all
public class Bank {
public static void main(String[] args) {
Account account = new Account("checking", 1000.00);
account.deposit(500);
account.withdraw(700);
}
}
User.java
Code: Select all
BTW are there any more instructions? I'm just asking because the excercise tells to create a lot of stuff you never need...import java.util.Date;
public class User {
private int userID;
private String lastName;
private String middleInitial;
private String firstName;
private Date birthDate;
private String city;
private String state;
private int zipCode;
private String userType;
private int socialSN;
public int getUserID() {
return userID;
}
public void setUserID(int userID) {
this.userID = userID;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getMiddleInitial() {
return middleInitial;
}
public void setMiddleInitial(String middleInitial) {
this.middleInitial = middleInitial;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public Date getBirthDate() {
return birthDate;
}
public void setBirthDate(Date birthDate) {
this.birthDate = birthDate;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public int getZipCode() {
return zipCode;
}
public void setZipCode(int zipCode) {
this.zipCode = zipCode;
}
public String getUserType() {
return userType;
}
public void setUserType(String userType) {
this.userType = userType;
}
public int getSocialSN() {
return socialSN;
}
public void setSocialSN(int socialSN) {
this.socialSN = socialSN;
}
}
Sorry for the late reply
I got my dad to help me...thank you so much anyways
I got my dad to help me...thank you so much anyways
5 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023