-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ1_Account.java
More file actions
126 lines (120 loc) · 2.57 KB
/
Q1_Account.java
File metadata and controls
126 lines (120 loc) · 2.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
import java.util.*;
class Account{
private int id;
private double balance;
static double AnnualInteresetRate;
//Default constructor with no args
Account()
{
this.id = 0;
this.balance = 0;
System.out.println("Acccount Created with inital values 0");
}
Account (int Id, int bal)
{
this.id = Id;
this.balance = bal;
System.out.println("Account Created and your id is : "+this.id);
}
boolean setId(int id)
{
this.id = id;
return true;
}
boolean setBalance(int amount)
{
this.balance = amount;
return true;
}
boolean setAnnualInterestRate(int rate)
{
this.AnnualInteresetRate = rate;
return true;
}
//getter
int getId()
{
return this.id;
}
double getBalance()
{
return this.balance;
}
double getAnnualInterest()
{
return (((this.AnnualInteresetRate/12)*this.balance)/100);
}
double getAnnualInteresetRate()
{
return this.AnnualInteresetRate;
}
boolean withdraw(double amount)
{
if(this.balance>=amount)
{
this.balance-=amount;
return true;
}
return false;
}
boolean deposit(double amount)
{
this.balance+=amount;
return true;
}
}
public class Q1_Account {
public static void main(String[] args)
{
String s ="1. Check Balance\n2. Deposit Money\n3. Withdraw Money\n4.Check Interest\n5.Exit";
int opt;
int id;
int balance;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Id: ");
id = sc.nextInt();
System.out.println("Enter the amount: ");
balance = sc.nextInt();
Account a = new Account(id,balance);
a.setAnnualInterestRate(5);
while(true)
{
System.out.println(s);
System.out.println("Enter an option to perform: ");
opt = sc.nextInt();
if(opt ==1)
{
System.out.println("Balance is you account is :"+a.getBalance());
}
else if(opt ==2)
{
double amount;
System.out.println("Enter the amount to deposit: ");
amount = sc.nextInt();
double c = a.getBalance();
System.out.println("Amount Deposited: "+a.deposit(amount));
System.out.println("Amount Before Deposit: "+c+"\nAmount After Deposit: "+a.getBalance());
}
else if(opt ==3)
{
double amount = sc.nextInt();
double c = a.getBalance();
System.out.println("Amount Deposited: "+a.withdraw(amount));
System.out.println("Amount Before Deposit: "+c+"\nAmount After Withdraw: "+a.getBalance());
}
else if(opt ==4)
{
System.out.println("Interest of you account balance is :"+a.getAnnualInterest());
}
else if(opt ==5)
{
System.out.println("Thank you");
break;
}
else
{
System.out.println("Make a valid choice");
}
}
}
}