Task - Inheritance - Class Inheritance - Bank Account #92
Replies: 8 comments
-
class Account1 {
double accBalance;
String accHolder;
final int accNumber;
static double rateOfInterest = 5;
String PAN;
Account1(double accBalance, String accHolder, int accNumber, String PAN) {
this.accBalance = accBalance;
this.accHolder = accHolder;
this.accNumber = accNumber;
this.PAN = PAN;
}
public double getAccBalance() {
return accBalance;
}
public double withdraw(double debitAmt) {
if (debitAmt > accBalance) {
System.out.println("Debit amount exceeded account balance.");
return accBalance;
}
accBalance -= debitAmt;
transactSMS(debitAmt, 2);
return accBalance;
}
public double deposit(double creditAmt) {
accBalance += creditAmt;
transactSMS(creditAmt, 1);
return accBalance;
}
public void calcInterest() {
double interestAmount = rateOfInterest * accBalance / 100;
accBalance += interestAmount;
transactSMS(interestAmount, 3);
}
public void transactSMS(double amt, int i) {
switch (i) {
case 1:
System.out
.println(
"\nFor user: " + accHolder + " Amounted credited in account:" + amt
+ "\nBalance after transaction is "
+ accBalance);
break;
case 2:
System.out
.println("\nFor user: " + accHolder + " Amounted debited from account:" + amt
+ "\nBalance after transaction is "
+ accBalance);
break;
case 3:
System.out
.println("\nFor user: " + accHolder + " Interest credited for current year: Rs." + amt
+ "\nBalance after transaction is "
+ accBalance);
break;
default:
System.out.println("An invalid transaction was attempted from your account on ");
break;
}
}
}
class SBIAccount extends Account1 {
public SBIAccount(double accBalance, String accHolder, int accNumber, String PAN) {
super(accBalance, accHolder, accNumber, PAN);
updateBalance();
}
private void updateBalance() {
if (!PAN.isEmpty())
accBalance += 1000;
}
public void linkPan(String PAN) {
this.PAN = PAN;
accBalance += 500;
}
public void displayFeatures() {
System.out.println("Opening an account with SBI always comes handy as it has lots of benefits:");
System.out.println(
" Facility to make online payment for every government exam or at any government sites. \n Easy, fast and secure internet banking services. \n Easy to reach an SBI branch(largest bank of India). \n Maximum number of ATMs. \n No minimum balance charges.");
}
@Override
public String toString() {
calcInterest();
displayFeatures();
return "Account [PAN=" + PAN + ", accBalance=" + accBalance + ", accHolder=" + accHolder + ", accNumber="
+ accNumber + "]";
}
}
class ICICIAccount extends Account1 {
final int additionalInterestRate = 2;
public ICICIAccount(double accBalance, String accHolder, int accNumber, String PAN) {
super(accBalance, accHolder, accNumber, PAN);
if (accBalance < 25000) {
System.out.println("BALANCE LESS THAN 25000!");
System.exit(0);
}
}
public void additionalInterest() {
accBalance += additionalInterestRate * accBalance / 100;
}
public double withdraw(double debitAmt) {
if (accBalance - debitAmt > 25000) {
System.out.println("Account balance will be below 25000!");
return accBalance;
}
accBalance -= debitAmt;
transactSMS(debitAmt, 2);
return accBalance;
}
public void calcInterest() {
double interestAmount = (rateOfInterest + additionalInterestRate) * accBalance / 100;
accBalance += interestAmount;
transactSMS(interestAmount, 3);
}
public void displayFeatures() {
System.out.println("Opening an account with SBI always comes handy as it has lots of benefits:");
System.out.println(
" Facility to make online payment for every government exam or at any government sites. \n Easy, fast and secure internet banking services. \n Easy to reach an SBI branch(largest bank of India). \n Maximum number of ATMs. \n No minimum balance charges.");
}
@Override
public String toString() {
calcInterest();
displayFeatures();
return "Account [PAN=" + PAN + ", accBalance=" + accBalance + ", accHolder=" + accHolder + ", accNumber="
+ accNumber + "]";
}
}
public class discussion92 {
public static void main(String[] args) {
SBIAccount account1 = new SBIAccount(1000, "Rohit", 98644587, "CFKPJS");
System.out.println(account1);
System.out.println("\n Account Balance :" + account1.getAccBalance() + "\n");
SBIAccount account3 = new SBIAccount(1000, "Sahil", 98643587, "");
System.out.println(account3);
account3.linkPan("SJDP9086");
System.out.println("\n Account Balance :" + account3.getAccBalance() + "\n");
ICICIAccount account2 = new ICICIAccount(1000, "Mahesh", 989695587, "CFKPJS");
System.out.println(account2);
}
} |
Beta Was this translation helpful? Give feedback.
-
import java.util.*;
import java.lang.*;
public class task92 {
public static void main(String[] args) {
// Scanner scn = new Scanner(System.in);
Acc a1 = new Acc("Joey", 75990, "ABC101");
Acc a2 = new Acc("Phoebe", 90000, null);
Acc a3 = new Acc("Joe", 245000, "BDF109");
Acc a4 = new Acc("Ross", 26000, "TYU657");
System.out.println(a1);
boolean check = true;
check = a1.panLinked();
if (check == false) {
System.out.println("PAN card not linked.");
} else {
System.out.println("PAN card linked.");
}
a1.deposit(1000);
System.out.println(a1);
a1.withdraw(5000);
System.out.println(a1);
System.out.println(a1.getBalance());
a1.calculateYearlyInterest();
System.out.println(a1);
SBIAcc s = new SBIAcc(null, 0, null);
s.displayFeatures();
s.panLinked();
System.out.println(s.openingBalance(a1));
s.linkPan(a2);
ICICIAcc i = new ICICIAcc(null, 0, null);
System.out.println(a3);
double res = i.InterestCalc(a3);
System.out.println(a4);
double ans = i.withdraw(1500, a4);
// System.out.println(res);
i.displayFeatures();
}
}
class Acc {
public Acc(String accHolder, double accBalance, String pAN) {
this.accHolder = accHolder;
this.accBalance = accBalance;
PAN = pAN;
}
Scanner scn = new Scanner(System.in);
String accHolder;
double accBalance;
int accNumber;
double rateOfInterest = 5;
String PAN;
double getBalance() {
return accBalance;
}
double withdraw(double amount) {
if (amount > 0 && amount <= accBalance) {
accBalance -= amount;
}
return accBalance;
}
double deposit(double amount) {
if (amount > 0) {
accBalance = accBalance + amount;
}
return accBalance;
}
double calculateYearlyInterest() {
double interest;
interest = (accBalance * rateOfInterest) / 100;
System.out.println("amount : " + accBalance);
System.out.println("rate of interest : " + rateOfInterest);
System.out.println("interest amount at the end of the year is " + interest);
double tot = interest + accBalance;
System.out.println("total amount with interest to be paid : " + tot);
return interest;
}
boolean panLinked() {
if (PAN == null) {
return false;
} else {
return true;
}
}
public String toString() {
return "Acc [AccHolder=" + accHolder + ", AccBalance=" + accBalance + ", PAN Card Number=" + PAN + "]";
}
}
class SBIAcc extends Acc {
public SBIAcc(String accHolder, double accBalance, String pAN) {
super(accHolder, accBalance, pAN);
// TODO Auto-generated constructor stub
}
double accOpeningBalance = 1000;
double openingBalance(Acc a1) {
if (a1.panLinked() == true) {
accBalance = accBalance + accOpeningBalance;
}
return accBalance;
}
String addPAN;
void linkPan(Acc a2) {
int bonus = 500;
if (a2.panLinked() == false) {
System.out.println(a2);
boolean check3 = true;
check3 = a2.panLinked();
if (check3 == false) {
System.out.println("PAN card not linked.");
} else {
System.out.println("PAN card linked.");
}
System.out.println("Do you want to link your PAN Card? Enter the pan number");
addPAN = scn.next();
System.out.println(a2);
System.out.println("Your pan card is linked. A bonus of Rs. 500 will be credited");
double totBal = a2.accBalance + bonus;
System.out.println("Existing balance: " + accBalance);
System.out.println("Updated balance: " + totBal);
}
}
void displayFeatures() {
System.out.println("SBI FEATURES");
System.out.println("SBI Gold Loan");
System.out.println("SBI Credit Card");
System.out.println("SBI Education Loan");
}
}
class ICICIAcc extends Acc {
public ICICIAcc(String accHolder, double accBalance, String pAN) {
super(accHolder, accBalance, pAN);
// TODO Auto-generated constructor stub
}
int additionalROI;
double withdraw(double amount, Acc obj) {
if (amount <= 25000) {
System.out.println("Current Balance: " + obj.accBalance);
System.out.println("Amount to be withdrawn: " + amount);
System.out.println("Minimum balance in the account should be Rs. 25000. Amount cannot be debited");
System.out.println(obj);
}
return accBalance;
}
double InterestCalc(Acc obj) {
additionalROI = 2;
if (obj.accBalance > 100000) {
System.out.println("current balance is " + obj.accBalance);
obj.accBalance = obj.accBalance + (obj.accBalance * additionalROI / 100);
System.out.println("Account balance is more than 100000. Additional ROI will be added. ");
System.out.println("updated balance is " + obj.accBalance);
}
return obj.accBalance;
}
void displayFeatures() {
System.out.println("ICICI FEATURES");
System.out.println("Reward points");
System.out.println("INOX");
System.out.println("Culnary Treats");
System.out.println("Airport Lounge Access");
System.out.println("Visa benifits");
}
} |
Beta Was this translation helpful? Give feedback.
-
import java.util.Scanner;
import java.text.SimpleDateFormat;
import java.util.Date;
class Account {
double accBalance;
String accHolder;
static final double rateOfinterest = 0.03;
boolean panLinked;
String PAN;
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
SimpleDateFormat formater = new SimpleDateFormat("HH:mm:ss");
Date date = new Date();
public Account(double accBalance, String accHolder) {
this.accBalance = accBalance;
this.accHolder = accHolder;
}
Account(double accBalance, String accHolder, String PAN, boolean panLinked) {
this.accBalance = accBalance;
this.accHolder = accHolder;
this.PAN = PAN;
}
public void getStatus(double amount, double accBalance, int x) {
if (x == 1) {
System.out.println("Amount Successfully Deposited ."
+ "\nAmount Deposited: " + amount + "\n At: " + formatter.format(date) + "\n Time: "
+ formater.format(date));
} else if (x == 0) {
System.out.println("Amount Successfully Withdrawn ."
+ "\nAmount Withdrawn: " + amount + "\n At: " + formatter.format(date) + "\n Time: "
+ formater.format(date));
}
}
public double getBalance() {
return accBalance;
}
boolean panlinked(String pan) {
return true;
}
public double deposit(double amount) {
if (amount > 0) {
accBalance += amount;
}
getStatus(amount, accBalance, 1);
return accBalance;
}
public double withdraw(double amount) {
if (amount > 0 && amount <= accBalance) {
accBalance -= amount;
}
getStatus(amount, accBalance, 0);
return accBalance;
}
public double calculateInterest() {
return (accBalance * rateOfinterest + accBalance);
}
@Override
public String toString() {
return "Account [PAN=" + PAN + ", accBalance=" + accBalance + ", accHolder=" + accHolder + "]";
}
}
// sbi
class Sbi extends Account {
public Sbi(double accBalance, String accHolder, String PAN, boolean panLinked) {
super(accBalance, accHolder, PAN, panLinked);
update();
linkPAN();
}
public void linkPAN() {
if (panLinked == true)
accBalance += 500;
}
public void update() {
if (this.PAN != null) {
accBalance += 1000;
}
}
public String toString() {
return "SBI Account [PAN=" + PAN + ", accBalance=" + accBalance + ", accHolder=" + accHolder + "]";
}
}
// icici
class Icici extends Account {
public Icici(double accBalance, String accHolder) {
super(accBalance, accHolder);
if (accBalance < 25000) {
System.out.println("Account balance can't be less than 25000");
System.exit(0);
}
update();
}
void update() {
if (accBalance >= 100000)
accBalance += accBalance * 0.02;
}
public String toString() {
return "ICICI Account [ accBalance=" + accBalance + ", accHolder=" + accHolder + "]";
}
}
public class Bank {
public static void main(String[] args) {
Sbi s = new Sbi(1000, "John", "101uio", true);
System.out.println(s);
Sbi s1 = new Sbi(20000, "Jun", null, false);
System.out.println(s1);
Icici i1 = new Icici(100000, "James");
System.out.println(i1);
Icici i = new Icici(20000, "Jack");
}
} |
Beta Was this translation helpful? Give feedback.
-
import java.util.*;
import java.time.format.DateTimeFormatter;
import java.time.LocalDateTime;
public class D8 {
public static void main(String[] args) {
Account account1 = new Account(10000, "Jack", 1234567890, false, false,
"ABCDE00001");
sbiAccount acc1 = new sbiAccount(10000, "Maya", 1231231230, false, false,
"QWERTY123");
sbiAccount acc2 = new sbiAccount(50000, "Ronald", 1212134343, false, false,
"");
iciciAccount iciciacc2 = new iciciAccount(200000, "Jane", 1231243234, false,
false, "PQRST6543");
System.out.println(account1);
System.out.println();
System.out.println(acc1);
System.out.println();
System.out.println(acc2);
acc2.linkPan("TYGHU12345");
System.out.println(acc2);
System.out.println();
iciciacc2.CalculateInterest();
System.out.println();
acc1.displayFeatures();
System.out.println();
iciciacc2.displayFeatures();
System.out.println();
iciciacc2.debit(195000);
iciciAccount iciciacc1 = new iciciAccount(5000, "John", 1111122222, false, false, "ZXCVB123");
System.out.println(iciciacc1);
}
}
class Account {
double accBalance;
String accHolder;
final int accountNumber;
double rateOfInterest = 5;
boolean optedForMobileBanking = false;
boolean optedForNetBanking = false;
String panNumber;
public Account(double accBalance, String accHolder, int accountNumber, boolean optedForMobileBanking,
boolean optedForNetBanking, String panNumber) {
this.accBalance = accBalance;
this.accHolder = accHolder;
this.accountNumber = accountNumber;
this.optedForMobileBanking = optedForMobileBanking;
this.optedForNetBanking = optedForNetBanking;
this.panNumber = panNumber;
}
double CalculateInterest() {
accBalance = accBalance + ((accBalance * rateOfInterest) / 100);
System.out.println("Interest earned in a year : " + (accBalance * rateOfInterest) / 100);
return accBalance;
// System.out.println("Updated Account Balance after addition of interest is " +
// accBalance);
}
double debit(int amount) {
if (amount > 0 && amount <= accBalance) {
accBalance = accBalance - amount;
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd ");
DateTimeFormatter obj = DateTimeFormatter.ofPattern(" HH:mm:ss");
LocalDateTime now = LocalDateTime.now();
sendTransactionMessage(amount, accBalance, 1, dtf.format(now), obj.format(now));
}
return accBalance;
}
void sendTransactionMessage(double amount, double accBalance, int c, String date, String time) {
System.out.printf("Hello %s\n", accHolder);
if (c == 1) {
System.out.println(
amount + " amount has been withdrawn , Remaining balance is " + accBalance
+ " on this date " + date + "at this time "
+ time
+ "\n");
} else {
System.out.println(
amount + " amount has been credited, Updated balance is " + accBalance
+ " on this date " + date + " at this time "
+ time + "\n");
}
}
double credit(int amount) {
if (amount > 0) {
accBalance = accBalance + amount;
}
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd");
DateTimeFormatter obj = DateTimeFormatter.ofPattern(" HH:mm:ss");
LocalDateTime now = LocalDateTime.now();
sendTransactionMessage(amount, accBalance, 2, dtf.format(now), obj.format(now));
return accBalance;
}
public double getAccBalance() {
return accBalance;
}
boolean panLinked() {
if ((panNumber.equals(""))) {
return false;
}
return true;
}
@Override
public String toString() {
return "Account [accBalance=" + accBalance + ", accHolder=" + accHolder + ", accountNumber=" + accountNumber
+ ", optedForMobileBanking=" + optedForMobileBanking + ", optedForNetBanking=" + optedForNetBanking
+ ", panNumber=" + panNumber + ", rateOfInterest=" + rateOfInterest + "]";
}
}
class sbiAccount extends Account {
Scanner sc = new Scanner(System.in);
public sbiAccount(double accBalance, String accHolder, int accountNumber, boolean optedForMobileBanking,
boolean optedForNetBanking, String panNumber) {
super(accBalance, accHolder, accountNumber, optedForMobileBanking, optedForNetBanking, panNumber);
updateBalance();
}
void updateBalance() {
if (!panNumber.isEmpty())
accBalance += 1000;
}
void linkPan(String panNumber) {
this.panNumber = panNumber;
accBalance = accBalance + 500;
}
void displayFeatures() {
System.out.println("SBI is almost wholly owned by the RBI");
System.out.println(" It is a public sector bank and the largest bank in India with a 23% market share");
}
}
class iciciAccount extends Account {
public iciciAccount(double accBalance, String accHolder, int accountNumber, boolean optedForMobileBanking,
boolean optedForNetBanking, String panNumber) {
super(accBalance, accHolder, accountNumber, optedForMobileBanking, optedForNetBanking, panNumber);
checkAccountBalance(accBalance);
}
private void checkAccountBalance(double accBalance) {
if (accBalance < 25000) {
System.out.println("Account can not be created if acc balance is less than 25k");
System.exit(0);
}
}
@Override
double CalculateInterest() {
if (accBalance > 100000) {
rateOfInterest = 7;
System.out.println("You are eligible for additional 2% rate of interest");
}
accBalance = accBalance + ((accBalance * rateOfInterest) / 100);
System.out.println("Interest earned in a year : " + (accBalance * rateOfInterest) / 100);
return accBalance;
}
@Override
double debit(int amount) {
if (accBalance - amount > 25000 && amount > 0 && amount <= accBalance) {
accBalance = accBalance - amount;
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd ");
DateTimeFormatter obj = DateTimeFormatter.ofPattern(" HH:mm:ss");
LocalDateTime now = LocalDateTime.now();
sendTransactionMessage(amount, accBalance, 1, dtf.format(now), obj.format(now));
} else {
System.out.println(
"Minimum account balance should be 25000 or debit amount should be greater than account Balance");
}
System.out.println();
return accBalance;
}
void displayFeatures() {
System.out.println("ICICI is the best Retail Bank in India");
System.out.println("The Asian Banker Excellence in Retail Financial Services International Awards 2022");
}
} |
Beta Was this translation helpful? Give feedback.
-
import java.util.Scanner;
class Accounts {
String accHolder;
double accBalance ;
final int accNumber ;
static double rateOfInterest = 0.05;
String PAN;
Accounts(String accHolder, double accBalance, int accNumber, String PAN) {
this.accHolder = accHolder;
this.accBalance = accBalance;
this.PAN = PAN;
}
void debit(double amount) {
if (amount <= accBalance) {
System.out.println("Amount debited " + amount);
accBalance = accBalance - amount;
showbalance();
} else {
System.out.println("Debit amount exceeded account balance");
}
}
void credit(int amount) {
accBalance = accBalance + amount;
showbalance();
}
void showbalance() {
System.out.println("Account Name " + accHolder);
System.out.println("Current balance " + accBalance);
}
boolean PanLinked() {
Scanner sc = new Scanner(System.in);
System.out.println("Do you want to link the PAN?[true/false]");
boolean bn = sc.nextBoolean();
if (bn == true)
return true;
else
return false;
}
}
class ICICIAccount extends Accounts {
ICICIAccount(String accHolder, double accBalance, int accNumber, String PAN) {
super(accHolder, accBalance, accNumber, PAN);
}
Scanner obj = new Scanner(System.in);
void openAccount() {
System.out.println("Enter the amount to be deposited:");
int balance = obj.nextInt();
if (balance >= 25000 && balance < 100000)
System.out.println("Your account have been created successfully and your ROI will be 5%");
if (balance < 25000)
System.out.println("Min Acccount balance should be 25000");
if (balance > 100000)
System.out.println("Your account have been created successfully and your ROI will be 7%");
}
void displayfeatures() {
System.out.println(
"Available at all branches /n Minimum balance amount Nil /n Maximum balance /amount No upper limit");
}
}
class SBIAccount extends Accounts {
SBIAccount(String accHolder, double accBalance, int accNumber, String PAN) {
super(accHolder, accBalance, accNumber, PAN);
}
void openAccount() {
accBalance = accBalance + 1000;
System.out.println("Your opening balance is :" + accBalance);
if (PanLinked())
linkPAN();
}
void linkPAN() {
accBalance = accBalance + 500;
System.out.println(
"Your PAN have been linked successfully and your account balance after linking PAN is:" + accBalance);
}
void displayfeatures() {
System.out.println(
"Available at all branches /n Minimum balance amount Nil /n Maximum balance /amount No upper limit");
}
}
class d92 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Accounts ac = new Accounts("ABC", 100000, 8560, "AT5009345");
SBIAccount sbi = new SBIAccount("XYZ", 400000, 8450, "A3GF09345");
ICICIAccount ic = new ICICIAccount("PQR", 800000, 9806, "AT5999345");
int choice;
do {
System.out.println(
"Select an operation: 1. deposit /n 2. withdraw /n 3.showbalance /n 4.Open SBI Account /n 5. Open ICICI Account");
choice = scanner.nextInt();
switch (choice) {
case 1:
System.out.println("Enter amount to be deposited");
ac.credit(scanner.nextInt());
break;
case 2:
System.out.println("Enter amount to be withdrawn");
ac.debit(scanner.nextInt());
break;
case 3:
ac.showbalance();
break;
case 4:
sbi.openAccount();
break;
case 5:
ic.openAccount();
break;
default:
break;
}
System.out.println("press 1 to continue 0 to exit");
choice = scanner.nextInt();
} while (choice != 0);
scanner.close();
}
} |
Beta Was this translation helpful? Give feedback.
-
public class Accounts {
String accholder;
double accbalance;
final int accnumber;
static double interest = 5;
String pan;
public Accounts(String accholder, double accbalance, int accnumber, String pan) {
this.accholder = accholder;
this.accbalance = accbalance;
this.accnumber = accnumber;
this.pan = pan;
}
public double getaccbalance() {
return accbalance;
}
public double withdraw(double d) {
if (d < accbalance) {
accbalance = accbalance - d;
}
return accbalance;
}
public double deposit(double m) {
if (m > 0) {
accbalance += m;
}
return accbalance;
}
public double calculateYearlyinterest(double amt) {
return (accbalance + ((accbalance * interest) / 100));
}
boolean panLinked() {
if (pan.equals(" ")) {
return false;
} else {
return true;
}
}
@Override
public String toString() {
return "Accounts [accbalance=" + accbalance + ", accholder=" + accholder + ", accnumber=" + accnumber
+ ", interest=" + interest + ", pan=" + pan + "]";
}
}
class sbi extends Accounts {
public sbi(String accholder, double accbalance, int accnumber, String pan) {
super(accholder, accbalance, accnumber, pan);
}
public double accopeningBonus() {
if (pan.isEmpty()) {
return accbalance;
}
return accbalance + 1000;
}
public double linkpan(String pan) {
this.pan = pan;
return accbalance + 500;
}
public void displayfeatures() {
System.out.println("Low Monthly Average Balance: Rs 5,000.");
System.out.println("Free Cash Deposit upto Rs 5,00,000/- per Month.");
System.out.println("Free access to the Safest, Securest, Fastest Corporate Internet Banking.");
}
@Override
public String toString() {
return "Accounts [accbalance=" + accbalance + ", accholder=" + accholder + ", accnumber=" + accnumber
+ ", interest=" + interest + ", pan=" + pan + "]";
}
}
class icici extends Accounts {
public icici(String accholder, double accbalance, int accnumber, String pan) {
super(accholder, accbalance, accnumber, pan);
if (checkamount(accbalance) == false) {
System.out.println("Account cant be created, because balance is less than 25k");
System.exit(0);
}
}
@Override
public double calculateYearlyinterest(double amt) {
if (amt > 100000) {
interest = 7;
return (amt + ((amt * interest) / 100));
}
return (accbalance + ((accbalance * interest) / 100));
}
@Override
public double withdraw(double d) {
double checkamt = accbalance - d;
if (checkamt < 25000) {
System.out.println("Balance is less than 25000, so can't withdraw the given amount");
return accbalance;
}
return accbalance - d;
}
public boolean checkamount(double d) {
if (d < 25000) {
return false;
}
return true;
}
public void features() {
System.out.println("Free Cash Withdrawal from Home Branch.");
System.out.println("Free 50 Multicity Cheque Leaves per Month.");
System.out.println("Free NEFT/RTGS through Internet Banking & Mobile Banking.");
}
}
class banks {
public static void main(String[] args) {
Accounts a = new Accounts("Raj", 20000, 1234, "LEQ8790");
sbi s = new sbi("Priya", 25000, 3456, "PSQ8790");
sbi s2 = new sbi("Riya", 5000, 8907, "");
System.out.println(a);
System.out.println(s);
System.out.println(s2.accopeningBonus());
System.out.println(s);
System.out.println(s.calculateYearlyinterest(s.accbalance));
System.out.println(s.accopeningBonus());
icici i = new icici("Saumya", 5000, 9008, "UTQ8790");
icici i2 = new icici("Shruti", 35000, 8783, "");
System.out.println(i2);
System.out.println(i);
System.out.println(i2);
// System.out.println(i2.withdraw(15000));
// System.out.println(s2.linkpan("JHKLOIUN"));
}
} |
Beta Was this translation helpful? Give feedback.
-
package task92;
public class Account {
private String accHolder;
private double accBalance;
private final int accNumber;
private static double rateOfInterest = 5.00;
private final String PAN;
public Account(String accHolder, double accBalance, int accNumber, String pAN) {
super();
this.accHolder = accHolder;
this.accBalance = accBalance;
this.accNumber = accNumber;
PAN = pAN;
}
public String getAccHolder() {
return accHolder;
}
public void setAccHolder(String accHolder) {
this.accHolder = accHolder;
}
public double getAccBalance() {
return accBalance;
}
public double withdraw(double amount) throws IllegalArgumentException {
if (this.accBalance < amount)
throw new IllegalArgumentException("Account Balance less than Withdrawl Amount");
System.out.println(amount + "Withdrawn from Account " + this.accNumber);
accBalance -= amount;
return accBalance;
}
public double deposit(double amount) {
System.out.println(amount + "Credited to Account " + this.accNumber);
this.accBalance += amount;
return accBalance;
}
public static double getRateOfInterest() {
return rateOfInterest;
}
public static void setRateOfInterest(double rateOfInterest) {
Account.rateOfInterest = rateOfInterest;
}
public int getAccNumber() {
return accNumber;
}
public String getPAN() {
return PAN;
}
double calculateYearlyInterest() {
return (this.accBalance / 100) * rateOfInterest;
}
public boolean PANLinked() {
if (PAN == null || PAN.equals("")) {
return false;
}
return true;
}
}
class SBIAccount extends Account {
public SBIAccount(String accHolder, double accBalance, int accNumber, String pAN) {
super(accHolder, accBalance, accNumber, pAN);
if(PANLinked()==true)
{
deposit(1000.00);
}
}
public void displayFeatures() {
System.out.println(
"accOpeningBonus - an opening balance of Rs. 1000 credited to a new account in SBI if the new account has PAN.\r\n"
+ "linkPan() - a bonus of Rs. 500 will be credited if PAN is linked after opening the account");
}
public void linkPan(String Pan) {
if (super.PANLinked() == true) {
super.deposit(500.00);
}
}
}
class ICICIAccount extends Account{
public ICICIAccount(String accHolder, double accBalance, int accNumber, String pAN) {
super(accHolder, accBalance, accNumber, pAN);
}
private final Double minBalance=25000.00;
@Override
public double withdraw(double amount) throws IllegalArgumentException {
if((super.getAccBalance()-amount)<minBalance)
throw new IllegalArgumentException("Amount after withdrawl will be less than 25000");
return super.withdraw(amount);
}
public double calculateAdditionalInterest() {
if (super.getAccBalance()<100000)
return 0.0;
return (getAccBalance()/100)*2;
}
}
``` |
Beta Was this translation helpful? Give feedback.
-
import java.text.SimpleDateFormat;
import java.util.Date;
class Account {
double accBalance;
String accHolder;
static final double rateOfinterest = 0.03;
boolean panLinked;
String PAN;
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
SimpleDateFormat formater = new SimpleDateFormat("HH:mm:ss");
Date date = new Date();
public Account(double accBalance, String accHolder) {
this.accBalance = accBalance;
this.accHolder = accHolder;
}
Account(double accBalance, String accHolder, String PAN, boolean panLinked) {
this.accBalance = accBalance;
this.accHolder = accHolder;
this.PAN = PAN;
}
public void getStatus(double amount, double accBalance, int x) {
if (x == 1) {
System.out.println("Amount Successfully Deposited ."
+ "\nAmount Deposited: " + amount + "\n At: " + formatter.format(date) + "\n Time: "
+ formater.format(date));
} else if (x == 0) {
System.out.println("Amount Successfully Withdrawn ."
+ "\nAmount Withdrawn: " + amount + "\n At: " + formatter.format(date) + "\n Time: "
+ formater.format(date));
}
}
public double getBalance() {
return accBalance;
}
boolean panlinked(String pan) {
return true;
}
public double deposit(double amount) {
if (amount > 0) {
accBalance += amount;
}
getStatus(amount, accBalance, 1);
return accBalance;
}
public double withdraw(double amount) {
if (amount > 0 && amount <= accBalance) {
accBalance -= amount;
}
getStatus(amount, accBalance, 0);
return accBalance;
}
public double calculateInterest() {
return (accBalance * rateOfinterest + accBalance);
}
@Override
public String toString() {
return "Account [PAN=" + PAN + ", accBalance=" + accBalance + ", accHolder=" + accHolder + "]";
}
}
// sbi
class Sbi extends Account {
public Sbi(double accBalance, String accHolder, String PAN, boolean panLinked) {
super(accBalance, accHolder, PAN, panLinked);
update();
linkPAN();
}
public void linkPAN() {
if (panLinked == true)
accBalance += 500;
}
public void update() {
if (this.PAN != null) {
accBalance += 1000;
}
}
public String toString() {
return "SBI Account [PAN=" + PAN + ", accBalance=" + accBalance + ", accHolder=" + accHolder + "]";
}
}
// icici
class Icici extends Account {
public Icici(double accBalance, String accHolder) {
super(accBalance, accHolder);
if (accBalance < 25000) {
System.out.println("Account balance can't be less than 25000");
System.exit(0);
}
update();
}
void update() {
if (accBalance >= 100000)
accBalance += accBalance * 0.02;
}
public String toString() {
return "ICICI Account [ accBalance=" + accBalance + ", accHolder=" + accHolder + "]";
}
}
public class Bank {
public static void main(String[] args) {
Sbi s = new Sbi(1000, "John", "101uio", true);
System.out.println(s);
Sbi s1 = new Sbi(20000, "Jun", null, false);
System.out.println(s1);
Icici i1 = new Icici(100000, "James");
System.out.println(i1);
Icici i = new Icici(20000, "Jack");
System.out.println(i);
}
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Define a class
Accountwith the following data members and member methods:Define two child classes
SBIAccountandICICIAccountwhich extend theAccountclass with the following additional details:The
SBIAccountclass has the following extra details:The
ICICIAccountclass has the following extra details:Beta Was this translation helpful? Give feedback.
All reactions