Skip to content

Commit 2abea78

Browse files
committed
2 parents 0e74ed0 + 9d07d79 commit 2abea78

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1553
-0
lines changed

ATM/ATM.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
public class ATM extends OptionMenu {
3+
public static void main(String[] args) {
4+
OptionMenu options = new OptionMenu();
5+
options.getLogin();
6+
}
7+
}

ATM/Account.java

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
import java.text.DecimalFormat;
2+
import java.util.Scanner;
3+
4+
public class Account {
5+
6+
private int customerNumber;
7+
private int pinNumber;
8+
private double checkingBalance = 0;
9+
private double savingBalance = 0;
10+
11+
Scanner input = new Scanner(System.in);
12+
DecimalFormat moneyFormat = new DecimalFormat("'$'###,##0.00");
13+
14+
public void setCustomerNumber(int customerNumber){
15+
this.customerNumber = customerNumber;
16+
}
17+
18+
public int getCustomerNumber(){
19+
return customerNumber;
20+
}
21+
22+
public void setPinNumber(int pinNumber){
23+
this.pinNumber = pinNumber;
24+
}
25+
26+
public int getPinNumber(){
27+
return pinNumber;
28+
}
29+
30+
public double getCheckingBalance() {
31+
return checkingBalance;
32+
}
33+
34+
public double getSavingBalance(){
35+
return savingBalance;
36+
}
37+
38+
public void calcCheckingWithdraw(double amount){
39+
checkingBalance = (checkingBalance - amount);
40+
}
41+
42+
public void calcSavingWithdraw(double amount){
43+
savingBalance = (savingBalance - amount);
44+
}
45+
46+
public void calcCheckingDeposit(double amount){
47+
checkingBalance = (checkingBalance + amount);
48+
}
49+
50+
public void calcSavingDeposit(double amount){
51+
savingBalance = (savingBalance + amount);
52+
}
53+
54+
public void getCheckingWithdrawInput() {
55+
System.out.println("Checking Account balance: " + moneyFormat.format(checkingBalance));
56+
System.out.print("Amount you want to withdraw from Checking Account: ");
57+
double amount = input.nextDouble();
58+
59+
if(checkingBalance - amount >= 0){
60+
calcCheckingWithdraw(amount);
61+
System.out.println("New Checking Account Balance: " + moneyFormat.format(checkingBalance));
62+
}
63+
else{
64+
System.out.println("Not Enough Money to Withdraw");
65+
}
66+
}
67+
68+
public void getSavingWithdrawInput() {
69+
System.out.println("Saving Account balance: " + moneyFormat.format(savingBalance));
70+
System.out.print("Amount you want to withdraw from Saving Account: ");
71+
double amount = input.nextDouble();
72+
73+
if(savingBalance - amount >= 0){
74+
calcSavingWithdraw(amount);
75+
System.out.println("New Saving Account Balance: " + moneyFormat.format(savingBalance));
76+
}
77+
else{
78+
System.out.println("Not Enough Money to Withdraw");
79+
}
80+
}
81+
82+
public void getCheckingDepositInput(){
83+
System.out.println("Checking Account Balance: " + moneyFormat.format(checkingBalance));
84+
System.out.print("Amount you want to deposit to Checking Account: ");
85+
double amount = input.nextDouble();
86+
87+
if(checkingBalance + amount >= 0){
88+
calcCheckingDeposit(amount);
89+
System.out.println("New Checking Account Balance: " + moneyFormat.format(checkingBalance));
90+
}
91+
else{
92+
System.out.println("No Money to Deposit");
93+
}
94+
}
95+
96+
public void getSavingDepositInput(){
97+
System.out.println("Saving Account Balance: " + moneyFormat.format(savingBalance));
98+
System.out.print("Amount you want to deposit to Saving Account: ");
99+
double amount = input.nextDouble();
100+
101+
if(checkingBalance + amount >= 0){
102+
calcSavingDeposit(amount);
103+
System.out.println("New Saving Account Balance: " + moneyFormat.format(savingBalance));
104+
}
105+
else{
106+
System.out.println("No Money to Deposit");
107+
}
108+
}
109+
110+
}

ATM/OptionMenu.java

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
import java.text.DecimalFormat;
2+
import java.util.HashMap;
3+
import java.util.Scanner;
4+
5+
public class OptionMenu extends Account {
6+
7+
Scanner menuInput = new Scanner(System.in);
8+
DecimalFormat moneyFormat = new DecimalFormat("'$'###,##0.00");
9+
10+
HashMap<Integer, Integer> data = new HashMap<>();
11+
12+
public void getLogin() {
13+
int x = 1;
14+
do{
15+
try{
16+
data.put(952141, 191904);
17+
data.put(989947, 717976);
18+
19+
System.out.println("Welcome to ATM");
20+
System.out.println("Enter your Customer Number");
21+
setCustomerNumber(menuInput.nextInt());
22+
23+
System.out.println("Enter your PIN Number");
24+
setPinNumber(menuInput.nextInt());
25+
}
26+
catch(Exception e){
27+
System.out.println("\nInvalid Characters Only Numbers Allowed\n" + e);
28+
x = 2;
29+
}
30+
31+
int cn = getCustomerNumber();
32+
int pn = getPinNumber();
33+
if(data.containsKey(cn) && data.get(cn) == pn){
34+
getAccountType();
35+
}
36+
else{
37+
System.out.println("\nWrong Customer Number or Wrong PIN Number\n\n");
38+
}
39+
}while(x == 1);
40+
}
41+
42+
public void getAccountType() {
43+
System.out.println("Select Account Type you want to Access");
44+
System.out.println("Type 1 - Checking Account");
45+
System.out.println("Type 2 - Savings Account");
46+
System.out.println("Type 3 - Exit");
47+
48+
int selection = menuInput.nextInt();
49+
50+
switch (selection) {
51+
case 1 -> getChecking();
52+
case 2 -> getSaving();
53+
case 3 -> System.out.println("Thank you for using ATM, BYE\n");
54+
default -> System.out.println("\n Invalid Choice \n");
55+
}
56+
}
57+
58+
public void getChecking() {
59+
System.out.println("Checking Account");
60+
System.out.println("Type 1 - View Balance");
61+
System.out.println("Type 2 - Withdraw Money");
62+
System.out.println("Type 3 - Deposit Funds");
63+
System.out.println("Type 4 - Exit");
64+
65+
int selection = menuInput.nextInt();
66+
67+
switch (selection) {
68+
case 1 -> {
69+
System.out.println("Checking Account Balance: " + moneyFormat.format(getCheckingBalance()));
70+
getAccountType();
71+
}
72+
case 2 -> {
73+
getCheckingWithdrawInput();
74+
getAccountType();
75+
}
76+
case 3 -> {
77+
getCheckingDepositInput();
78+
getAccountType();
79+
}
80+
case 4 -> System.out.println("Thank you for using ATM, Bye");
81+
default -> {
82+
System.out.println("\nInvalid Choice\n");
83+
getChecking();
84+
}
85+
}
86+
}
87+
88+
public void getSaving() {
89+
System.out.println("Saving Account");
90+
System.out.println("Type 1 - View Balance");
91+
System.out.println("Type 2 - Withdraw Money");
92+
System.out.println("Type 3 - Deposit Funds");
93+
System.out.println("Type 4 - Exit");
94+
System.out.print("Choice: ");
95+
96+
int selection = menuInput.nextInt();
97+
98+
switch (selection) {
99+
case 1 -> {
100+
System.out.println("Saving Account Balance: " + moneyFormat.format(getSavingBalance()));
101+
getAccountType();
102+
}
103+
case 2 -> {
104+
getSavingWithdrawInput();
105+
getAccountType();
106+
}
107+
case 3 -> {
108+
getSavingDepositInput();
109+
getAccountType();
110+
}
111+
case 4 -> System.out.println("Thank you for using ATM, Bye\n");
112+
default -> {
113+
System.out.println("\nInvalid Choice\n");
114+
getChecking();
115+
}
116+
}
117+
}
118+
}

BMI Calculator

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
class Complex{
3+
int real;
4+
int img;
5+
Complex(){
6+
7+
}
8+
Complex(int real,int img){
9+
this.real=real;
10+
this.img=img;
11+
}
12+
void display() {
13+
System.out.println(real+" + i"+img);
14+
}
15+
Complex add(Complex c1,Complex c2) {
16+
Complex temp=new Complex();
17+
temp.real=c1.real+c2.real;
18+
temp.img=c1.img+c2.img;
19+
return temp;
20+
21+
22+
}
23+
24+
}
25+
public class q3 {
26+
27+
public static void main(String[] args) {
28+
Complex c=new Complex(10,20);
29+
Complex c1=new Complex(20,30);
30+
Complex c3=new Complex();
31+
c3=c1.add(c1, c);
32+
33+
c1.display();
34+
c.display();
35+
c3.display();
36+
37+
}
38+
39+
}

Calculator-OOPS/Add.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
public class Add implements Operate{
2+
@Override
3+
public Double getResult(Double... numbers){
4+
Double sum = 0.0;
5+
6+
for(Double num: numbers){
7+
sum += num;
8+
}
9+
return sum;
10+
}
11+
}

Calculator-OOPS/Calculator.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import java.util.Arrays;
2+
import java.util.LinkedList;
3+
import java.util.Objects;
4+
import java.util.Queue;
5+
6+
public class Calculator {
7+
public static void main(String[] args){
8+
final String inputExp = ReadInput.read();
9+
10+
Queue<String> operations;
11+
Queue<String> numbers;
12+
13+
String[] numbersArr = inputExp.split("[-+*/%]");
14+
// String[] operArr = inputExp.split("[0-9]+");
15+
String[] operArr = inputExp.split("\\d+");
16+
numbers = new LinkedList<>(Arrays.asList(numbersArr));
17+
operations = new LinkedList<>(Arrays.asList(operArr));
18+
19+
Double res = Double.parseDouble(Objects.requireNonNull(numbers.poll()));
20+
21+
while(!numbers.isEmpty()){
22+
String opr = operations.poll();
23+
24+
Operate operate;
25+
switch(Objects.requireNonNull(opr)){
26+
case "+":
27+
operate = new Add();
28+
break;
29+
case "-":
30+
operate = new Sub();
31+
break;
32+
case "*":
33+
operate = new Multiply();
34+
break;
35+
case "/":
36+
operate = new Divide();
37+
break;
38+
case "%":
39+
operate = new Modulus();
40+
break;
41+
default:
42+
continue;
43+
}
44+
Double num = Double.parseDouble(Objects.requireNonNull(numbers.poll()));
45+
res = operate.getResult(res, num);
46+
}
47+
48+
System.out.println(res);
49+
}
50+
}

Calculator-OOPS/Divide.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
public class Divide implements Operate {
2+
@Override
3+
public Double getResult(Double... numbers){
4+
Double div = numbers[0];
5+
6+
for(int i=1;i< numbers.length;i++){
7+
div /= numbers[i];
8+
}
9+
return div;
10+
}
11+
}

Calculator-OOPS/Modulus.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
public class Modulus implements Operate{
2+
@Override
3+
public Double getResult(Double... numbers){
4+
Double mod = numbers[0];
5+
6+
for (int i = 1; i < numbers.length; i++) {
7+
mod %= numbers[i];
8+
}
9+
return mod;
10+
}
11+
}

Calculator-OOPS/Multiply.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
public class Multiply implements Operate {
2+
@Override
3+
public Double getResult(Double... numbers){
4+
Double mul = 1.0;
5+
6+
for(Double num: numbers){
7+
mul *= num;
8+
}
9+
return mul;
10+
}
11+
12+
}

Calculator-OOPS/Operate.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
public interface Operate {
2+
Double getResult(Double... numbers);
3+
}

0 commit comments

Comments
 (0)