Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

// GIC Class partial template // Very similar to the Savings account except the // withdraw method is different. public class GIC // inherits from

image text in transcribed

// GIC Class partial template // Very similar to the Savings account except the // withdraw method is different.

public class GIC // inherits from Account { // class data (only some is here, you may need more) //interest rate and penalty rate // dates (investment and maturity date //default constructor public GIC(){ // constructor to create a Chequing Account // should call the parent constructor } // overloaded constructor that takes in a customer object and initializes data public boolean withdraw (double amt){ // uses methods from Account // checks if balance is sufficient // adds interest owed and charges a penalty if withdrawn before the maturity // must use the withdraw from Account to actually change the balance // returns true if successful and false if not } // getters and setters as needed // other useful methods might be method to change the fee and others. // toString method public static void main (String args[]){ // Self Testing Main } }

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Account

import java.util.Random;

import javax.swing.JOptionPane;

/** * */

/** * @author * Date: January 18th 2022 * Description: keeps the customers balance, account number and the Customer object * as private data and must enable other classes to deposit, withdraw and * update its balance. It should generate account numbers of twelve randomly * generated digits once Savings and GIC account objects are created. It * must prevent the user from withdrawing more funds than the balance allows. */ public class Account {

/* * Instance Data */ public double balance; public long accountNumber; private Customer record;

/** * Constructor */ public Account() { this.balance = 0; this.accountNumber = 0; this.record = new Customer(); //empty record }

/* * overloaded constructor */ public Account (Customer theOwner, double balance){ //initializes balance this.balance = balance;

//GENERATE A RANDOM 12 DIGIT ACCOUNT NUMBER //create new random Random random = new Random(); StringBuilder sb = new StringBuilder(); //first digit sb.append(random.nextInt(9)+1); //rest of 11 digits for(int i = 0; i

//assign a random 12 digit number to value long value = Long.valueOf(sb.toString()).longValue(); this.accountNumber = value;

// initializes customer object with theOwner this.record = theOwner; }

/* * deposits money into user's account */ public void deposit(double deposit) { this.balance = this.balance + deposit; }

/* * withdrawal method */ public boolean withdraw (double amount){ // Checks if the amount can be withdrawn // and returns true if it is possible if (this.balance > amount) { this.balance = this.balance - amount; return true; }

// returns false if it is not (balance amount

// updates balance??????? }

/** * @return the accountNumber */ public long getAccountNumber() { return accountNumber; }

/** * @param accountNumber the accountNumber to set */ public void setAccountNumber(long accountNumber) { this.accountNumber = accountNumber; }

/** * @return the record */ public Customer getRecord() { return record; }

/** * @param record the record to set */ public void setRecord(Customer record) { this.record = record; }

/** * @return the balance */ public double getBalance() { return balance; }

/* * to String method */ public String toStringAccount() { return "Account Info: " + this.getAccountNumber()+ ", $" + this.getBalance() + " " + this.getRecord(); }

/** * @param args */ public static void main(String[] args) {

//test the constructor Account a = new Account(); System.out.println("Constuctor test: " + a.toStringAccount()); System.out.println(" >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");

Customer c = new Customer("Aliyah Abboobakar/101 Sunny Lane/9054765431");

Account d = new Account(c, 2478);

//test getters long num = d.getAccountNumber(); double bal = d.getBalance(); Customer customer = d.getRecord();

//test the overloaded constructor System.out.println(" Overloaded Constructor Test:" + " " + d.toStringAccount());

System.out.println(" >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");

//test setter for customer record Customer c2 = new Customer("Aliyah Abboobakar/CandyCaneLane/7848379876"); d.setRecord(c2);

System.out.println(" Customer record setter: " + d.getRecord()); System.out.println(" >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");

//testing for the remaining setter d.setAccountNumber(287362739076L);

//testing for deposit and withdrawal methods d.deposit(2000); System.out.println(" Balance after deposit: $" + d.getBalance()); System.out.println(" >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");

double withdrawal = Double.parseDouble(JOptionPane.showInputDialog("How much would you like to " + "withdraw from your account?"));

if(d.withdraw(withdrawal)) { //method returns true: JOptionPane.showMessageDialog(null, "Successful withdrawal of: $" + withdrawal + ". Balance: $" + d.getBalance()); } else { //method returns false: JOptionPane.showMessageDialog(null, "Failed. Balance is insufficient for withdrawal"); }

//display all bank and account record info System.out.println(" all bank and record info after changing account number, " + "changing customer info, depositing and " + "withdrawing money: " + d.toStringAccount());

}//end of main

}//end of class

The GIC (Guaranteed Investment Certificate) class which inherits the data and methods of the "Account" class. It is an Account class with the following additional data and rules: 1. An investment date - the date when the account is opened. 2. A maturity date - the date when the investment comes due and the customer can withdraw funds without any penalties. 3. An interest rate to be added when the account is opened, which determines what will be allowed to be withdrawn (i.e. new balance) when the withdrawal happens. 4. A withdrawal penalty of 20% of the new balance if the customer withdraws funds before the maturity date

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database System

Authors: Elmasri Ramez And Navathe Shamkant

7th Edition

978-9332582705

More Books

Students also viewed these Databases questions