-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBankAccount.java
More file actions
147 lines (124 loc) · 4.57 KB
/
Copy pathBankAccount.java
File metadata and controls
147 lines (124 loc) · 4.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/* This code is my own work. I did not get any help from any online source
such as chegg.com; from a classmate, or any other person other than the instructor
or TA for this course. I understand that getting outside help from this course
other than from the instructor or TA will result in a grade of 0 in this
assignment and other disciplinary actions for academic dishonesty.
# Name : Cristian Z
# Class: CSET 1200
# Instructor: Dr. Jared Oluoch
# Programming Assignment: 10
# Problem: 1
# Date: 11/12/21
# Summary: Banking on real examples with possible sleep deprivation
# Problem 1
Write a Java program that accomplishes the following.
1. A superclass Bank Account that has the following: balance (attribute),
and the following methods:getBalance(),deposit(), withdraw().
2. A checking account that inherits from the Bank Account.
In addition, the checking account has monthly fee of $150.55.
The checking account also has the following methods: applyMonthlyfee()
and getMonthlyfee().
3. A savings account that inherits from the Bank Account.
In addition, the savings account has an interest rate of 2% and
the following methods: applyInterestRate(), SavingsAccount(),
and getInterestRate().
Based on the above:
1) write a simple Java program that shows the relationships of the above classes
and returns the savings amount based on the current amount in the savings account
and the interest rate.(15 points)
https://youtu.be/iHb7CDr0Pzk
*/
package BankAccount;
import java.util.Scanner;
/**
*
* @author giant
*/
//public class bank {
public class BankAccount
{
public double balance;
public BankAccount(double initialBalance)
{
balance = initialBalance;
}
public double getBalance()
{return balance;
}
public void deposit(double amount)
{
if(amount !=0)
{
balance = balance + amount;
}
}
public void withdraw(double amount)
{
if(amount !=0)
{
balance = balance - amount;
}
}
public static void main(String[] args)
{
//temp values for c and s accounts
double cM = 1.32;
double sM = 203.62;
//Give myself accounts though I could spawn them after i give a name.
CheckingAccount cAccount = new CheckingAccount(cM);
SavingsAccount sAccount = new SavingsAccount(sM);
//scanner in
Scanner input = new Scanner(System.in);
System.out.println("Hi, what is your name?");
String name = "";
name = input.nextLine();
//checking or savings
int num =0;
int num1=0;
double num2= 0;
//switch on num
do{ System.out.println("What would you like to do?\n1-See Your checking account?\n2-See your savings account\n3-exit\nWill not end till you use 3.");
num = input.nextInt();
//switch wether we want to check the checking, savings, or exit
switch(num)
{case 1: {
//checking route
System.out.println(cAccount.balance);
System.out.println("Would you like to make a \n1-deposit(amount)\n2-withdraw(amount)\n3-exit ");
num1 = input.nextInt();
//switch on num1 for deposit or withdraw
switch(num1){
case 1:System.out.println("How much?");
num2=input.nextDouble();
cAccount.deposit(num2);break;
case 2:System.out.println("How much?");
num2=input.nextDouble();
cAccount.withdraw(num2);break;
case 3:default:break; }
}
break;
case 2:{
//Savings route
System.out.println("The balance is : " +sAccount.balance + "\n"+ String.format("%.2f",(sAccount.getInterestRate(sM))) );
System.out.println("Would you like to make a\n1-deposit(amount)\n2-withdraw(amount)?\n3-exit ");
num1 = input.nextInt();
//switch on num1 for deposit or withdraw
switch(num1){
case 1: System.out.println("How much?");
num2=input.nextDouble();
sAccount.deposit(num2);break;
case 2: System.out.println("How much");
num2=input.nextDouble();
sAccount.withdraw(num2);break;
case 3:default:break; }
}
break;
case 3:{
}
default: System.out.println("Bye");
System.exit(0);
}
}while(num !=3);
}
}
//}