Java inheritance exercise Pursose: This exercise allows you to implement inherit
ID: 3819936 • Letter: J
Question
Java inheritance exercise Pursose: This exercise allows you to implement inheritance and polymorphism. Description Write a bank a Bank Account project according to the following specifications: Bank Account: Every bank account has an identifier, a PIN, and a balance. Every bank account should have a way to deposit an amount, withdraw an amount(abstract method), and display the current balance. Ensure that any class that inherits from this class has a withdraw() method that overrides the abstract withdraw() method. Savings: The withdraw method will only let the owner withdraw if the funds are sufficient. If the owner attempts to withdraw an amount higher than the balance, print an error message and do not process the withdraw. Checking: The withdraw method should withdraw the amount only if the funds are availible, and apply a service fee of $0.25 for each withdrawal to the balance. If the owner. if the owner attempts to withdraw more than the balance of the account, print an error message and do not process the withdraw. CheckingPlus: The withdraw method will allow the owner to withdraw more than the balance up to a predefined limite(the limit is a field in the class, the numer I used was 1000) If the amount requested is approved the fee is applied. The fee is a percentage of the amount overdrawn(ex: 10%). If the limit is exceeded, throw and catch the error. Testing: In main() create an array of five BankAccounts objects and each account will have a unique ID. Then allow the user to enter the BankAccount ID and PIN to either deposit or withdraw an amount. After each transaction, display the current balance. if the account ID with the PIN number is wrong, print an error message to the user and ask for another ID and PIN.
Explanation / Answer
public String name;
public String socSecNum;
public String type;
public double balance;
public String address;
public double date;
public double interest;
private double total;
public double days;
public double daysa;
public double rate;
public double month;
public double montha;
public double datea;
public double checking;
public Person(String n, String soc, String t,
double b, String add, double d, double in, double da, double mo,double rat, double moa,
double daa, double daya, double check){
name = n;
socSecNum = soc;
type = t;
balance = b;
address = add;
date = d;
interest = in;
days = da;
daysa = daya;
month = mo;
rate = rat;
montha = moa;
datea = daa;
checking = check;
}
public Person() {
}
public void setN(String n) {
name = n;
}
public void setSoc(String soc) {
socSecNum = soc;
}
public void setT(String t) {
type = t;
}
public void setB(double b) {
balance = b;
}
public void setAdd(String add) {
address = add;
}
public void setD(double d) {
date = d;
}
public void setDaa(double daa){
datea = daa;
}
public void setDa (double da){
days = da;
}
public void setDaya (double daya){
daysa = daya;
}
public void setMo (double mo){
month = mo;
}
public void setRat (double rat){
rate = rat;
}
public void setIntr (double intr){
interest = intr;
}
public void setMoa (double moa){
montha = moa;
}
public void setCheck (double check){
checking = check;
}
public String getN(){
return name;
}
public String getSoc(){
return socSecNum;
}
public String getT(){
return type;
}
public double getB(){
return balance - checking;
}
public String getAdd(){
return address;
}
public double getD(){
return days + month;
}
public double getDaa(){
return (montha + daysa)- (month + days) ;
}
public double getDa(){
return days;
}
public double getDaya(){
return daysa;
}
public double getMo(){
return month;
}
public double getMoa(){
return montha;
}
public double getCheck(){
return checking;
}
public double getInterest()
{
return (balance * rate * datea )/365;
}
public double getRat(){
return rate;
}
}
TEST CLASS:
import javax.swing.JOptionPane;
import java.swing.Scanner;
public class customer {
public static void main(String[] args)
{
String namei;
String soci;
String typei;
String input;
double inputi;
String inputii;
String addressi;
String daysi;
String daysa;
double interesti;
String monthi;
double inter;
int test;
int testi;
String monthb;
char repeat;
Person cus = new Person();
{
namei =
JOptionPane.showInputDialog("What is" +
"the customers name?");
cus.setN(namei);
soci =
JOptionPane.showInputDialog("What is the customers"+
"social security number?");
cus.setSoc(soci);
double typeii;
typei =
JOptionPane.showInputDialog("What type of account is it, 1 for checking 2 for savings?");
typeii = Double.parseDouble(typei);
if (typeii == 1)
cus.setCheck (-6);
inputii =
JOptionPane.showInputDialog("How old is the customer?");
cus.nowBday(Integer.parseInt(inputii));
input =
JOptionPane.showInputDialog("What is the balance of the customer?");
cus.setB(Integer.parseInt(input));
if (input > 4999 && inputi > 54)
cus.setCheck (0);
cus.setRat(++.01);
addressi =
JOptionPane.showInputDialog("What is the address of the customer?");
cus.setAdd(addressi);
monthi = JOptionPane.showInputDialog("What is the Month?");
cus.setD (Integer.parseInt(monthi));
test = Integer.parseInt(monthi);
switch (test)
{
case 1:
cus.setRat(.06);
break;
case 2:
cus.month = 31;
cus.setRat(.06);
break;
case 3:
cus.month = 59;
cus.setRat(.06);
break;
case 4:
cus.month = 90;
cus.setRat(.05);
break;
case 5:
cus.month = 120;
cus.setRat(.05);
break;
case 6:
cus.month = 151;
cus.setRat(.05);
break;
case 7:
cus.month = 181;
cus.setRat(.04);
break;
case 8:
cus.month = 212;
cus.setRat(.04);
break;
case 9:
cus.month = 243;
cus.setRat(.04);
break;
case 10:
cus.month = 273;
cus.setRat(.03);
break;
case 11:
cus.month = 304;
cus.setRat(.03);
break;
case 12:
cus.month = 334;
cus.setRat(.03);
break;
}
daysi =
JOptionPane.showInputDialog("What is the day of the month?");
double da = Double.parseDouble(daysi);
monthb = JOptionPane.showInputDialog("What is the Month now?");
cus.setDaa (Integer.parseInt(monthb));
testi = Integer.parseInt(monthb);
switch (testi)
{
case 1:
cus.montha = 0;
break;
case 2:
cus.montha = 31;
break;
case 3:
cus.montha = 59;
break;
case 4:
cus.montha = 90;
break;
case 5:
cus.montha = 120;
break;
case 6:
cus.montha = 151;
break;
case 7:
cus.montha = 181;
break;
case 8:
cus.montha = 212;
break;
case 9:
cus.montha = 243;
break;
case 10:
cus.montha = 273;
break;
case 11:
cus.montha = 304;
break;
case 12:
cus.montha = 334;
break;
default:
JOptionPane.showInputDialog("You did not enter a valid number");
break;
}
daysa =
JOptionPane.showInputDialog("What is the day of the month now?");
double daya = Double.parseDouble(daysa);
interesti = (int)cus.getInterest();
JOptionPane.showMessageDialog(null, "Name: " + namei +
" social security #:" + soci + " type:" + typei + " balance:" +
input + " address:" + addressi + " date:" + daysi + " inteterst:" + interesti);
System.out.println("Would you like to calculate another customers interest?");
System.out.println("Enter Y for yes or N for no:");
input = keyboard.nextLine();
repeat = input.charAt(0);
}while (repeat == 'y' || repeat == 'Y');
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.