Skip to content

Commit 477be33

Browse files
shannoncantechshannoncantech
shannoncantech
authored and
shannoncantech
committed
Initial commit
0 parents  commit 477be33

File tree

8 files changed

+151
-0
lines changed

8 files changed

+151
-0
lines changed

.idea/description.html

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/project-template.xml

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Java-Bank-Account.iml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
</component>
11+
</module>
12+

src/com/company/BankAccount.java

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package com.company;
2+
3+
import java.util.Random;
4+
5+
public class BankAccount {
6+
private int acctNum;
7+
private int balance;
8+
private int prevBalance = -1;
9+
Random rand;
10+
Person person;
11+
12+
public BankAccount() {
13+
}
14+
15+
public BankAccount(int acctNum, int balance) {
16+
this.acctNum = acctNum;
17+
this.balance = balance;
18+
}
19+
20+
public int getAcctNum() {
21+
return acctNum;
22+
}
23+
24+
public void setAcctNum(int acctNum) {
25+
this.acctNum = acctNum;
26+
}
27+
28+
public int getBalance() {
29+
return balance;
30+
}
31+
32+
public void setBalance(int balance) {
33+
this.balance = balance;
34+
}
35+
36+
37+
public void deposit(int addMoney){
38+
if(addMoney < 0){
39+
System.out.println("You cannot deposit a negative amount.");
40+
} else {
41+
this.balance = this.balance + addMoney;
42+
System.out.println("$" + addMoney + " deposited into the account number " + this.acctNum);
43+
}
44+
}
45+
46+
public void withdraw(int removeMoney){
47+
if (removeMoney > this.balance){
48+
System.out.println("Not enough money in account");
49+
} else {
50+
this.prevBalance = this.balance;
51+
this.balance = this.balance - removeMoney;
52+
System.out.println("Previous balance: " + prevBalance + "\nWithdrawn amount: " + removeMoney + "\nYour current balance is: " + this.balance);
53+
}
54+
}
55+
56+
//The method below creates a new account number and assigns it to the String person
57+
// This method doesn't take an integer as an argument because we don't want to assign an account number to an account number
58+
// The String person argument is perfect, so when we set Person using the person object in the main method, we'll be able to
59+
// store the person object and assign them to an account number
60+
public int createNewAcctNum(String person) {
61+
rand = new Random();
62+
// The code below generates no more than 12 random numbers and stores them into the account number
63+
for (int i = 0; i < 12; i++){
64+
this.acctNum = this.rand.nextInt() & Integer.MAX_VALUE;
65+
}
66+
person = Integer.toString(this.acctNum);
67+
return this.acctNum;
68+
}
69+
}

src/com/company/Main.java

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.company;
2+
3+
import java.util.Scanner;
4+
5+
public class Main {
6+
7+
public static void main(String[] args) {
8+
Scanner scan = new Scanner(System.in);
9+
Person person = new Person();
10+
BankAccount newAccount = new BankAccount();
11+
12+
System.out.println("Enter your name: ");
13+
person.setFullName(scan.nextLine());
14+
15+
newAccount.createNewAcctNum(person.getFullName());
16+
System.out.println(newAccount.getAcctNum());
17+
18+
System.out.println("Add balance: ");
19+
newAccount.deposit(scan.nextInt());
20+
scan.nextLine();
21+
22+
System.out.println("Account balance: " + newAccount.getBalance());
23+
24+
System.out.println("Withdrawal amount: ");
25+
newAccount.withdraw(scan.nextInt());
26+
scan.nextLine();
27+
28+
System.out.println("Account balance: " + newAccount.getBalance());
29+
}
30+
}

src/com/company/Person.java

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.company;
2+
3+
public class Person {
4+
private String fullName;
5+
6+
public Person() {
7+
}
8+
9+
public String getFullName() {
10+
return fullName;
11+
}
12+
13+
public void setFullName(String fullName) {
14+
this.fullName = fullName;
15+
}
16+
}

0 commit comments

Comments
 (0)