Question

in java

instructions

Assignment 2 Complete Exercise E9.3 (checking account problem). What to turn in: A zip file containing ONLY 3 java source code.files (BankAccount.java, BudgetCheckingAccount.java, and CheckingAccount.java). NO FOLDERS may be included in your zip file, or l will simply reject it. You are not giving me the AccountDemo.java file, because I have my own copy, and you are not permitted to modify it. Also, the package statement must be correct, as explained later in the assignment description. You have to do it a bit differently from the way described in the book. Create a new subclass named BudgetCheckingAccount that extends CheckingAccount, and override the withdrawal method to implement the penalty mentioned in the exercise specification. Also, prevent the actual withdrawal from creating a negative balance. (The penalty, on the other hand CAN create a negative balance.) YOU ARE NOT PERMITTED TO MODIFY THE CheckingAccount class. (Companies often sell you their code library without giving you access to the source code.) Of course, you will have to make appropriate changes to the startup class, named AccountDemo. DO NOT MODIFY IT, not even the package statemen! Right-click to download a ZIP file (named Asg 2 start.zip) containing the classes you need for this assignment. Make sure all our.java files have this statement on the first line package che9.exercises E93 This is your programs required output. Notice how the first overdraft has a penalty of $20, but the second and third overdrafts have penalties of $30 each. Account 1 balance - 5e0.0e Attempting to withdraw 50.00 from Account 1 Account 1 balance 450.00 Attempting to withdraw 40.00 from Account 1 Account 1 balance 410.00 Attempting to withdraw 500.00 from Account 1 Account 1 balance 390.0 Attempting to withdraw 391.00 from Account 1 Account 1 balance 369.00 Attempting to withdraw 370.00 from Account 1 Account 1 balance 338.00

0 0
Add a comment Improve this question Transcribed image text
Answer #1

java code:


package accountdemo;

import java.util.Date;
import java.util.Scanner;

//account class
class BankAccount
{
private int id;
private double balance;
private Date dateCreated;
private static int nextId=1;
  
BankAccount()
{}
//constructor
BankAccount(double balance){
id=nextId;
this.balance=balance;
nextId++;
dateCreated=new Date();
}
  
//getter
public int getId()
{
return id;
}
  
public double getBalance()
{
return balance;
}
  
public Date getDateCreated()
{
return dateCreated;
}
  
//withdraw
public void withdraw(double amount)
{
  
balance -= amount;
  
}
  
//deposit
public void deposit(double amount)
{
balance += amount;
}
  
//return string
public String toString()
{
return "Account ID: "+id +
" Balance: " + balance +
" Date Created: "+ dateCreated;
}

  
}

//CheckingAccount class
class CheckingAccount extends BankAccount
{
double fee;
int withdrawals;
  
//constructor
public CheckingAccount(double balance,double fee) {
//super(balance-fee);
//this.fee=fee;
}

public CheckingAccount() {
withdrawals=0;
}
public void withdraw(double amount)
{
final int FREE_WITHDRAWALS =3;
final int WITHDRAWALS_FEE =1;
  

if(super.getBalance()>amount)
super.withdraw(amount);
else
{
withdrawals++;
  
  
if(withdrawals<3)
super.withdraw(20);
if(withdrawals>2){
super.withdraw(30);
if(withdrawals>1)
super.withdraw(WITHDRAWALS_FEE);
}
}

}
//deduct fee
public void deductFee(double fee)
{
this.fee=fee;
}
//setter
public void setFee(double fee)
{
this.fee=fee;
}
  
//getter
public double getFee()
{
return fee;
}
  
//return string
public String toString()
{
return (super.toString()+ " Monthly Fee: "+fee);
}
  
}

//SavingsAccount class
class SavingsAccount extends BankAccount
{
double interest;
  
//constructor
public SavingsAccount(double balance,double interest) {
  
super(balance+(balance*interest/100));
this.interest=interest/100;
}
  
//setter
public void setInterest(double interest)
{
this.interest=interest;
}
  
//getter
public double getInterest()
{
return interest;
}
  
//interest caluclate function
public double calculateInterest()
{
return interest/100;
}
  
//rerurn string
public String toString()
{
return (super.toString()+ " Interest Rate: "+interest);
}
  
}

public class AccountDemo {

  
public static void main(String[] args) {
final int ACCOUNTS_SIZE =5;
  
BankAccount[] accounts =new BankAccount[ACCOUNTS_SIZE];
for(int i=0; i<accounts.length; i++)
{
accounts[i]=new CheckingAccount();
}
  
int id;
double amount;
  
id=1;
amount =50.0;
accounts[id].deposit(500);
System.out.println("Account "+id+" balance = "+accounts[id].getBalance()+"\n\n" );
System.out.println("Attempting to withdraw "+amount+" from Account "+id);
accounts[id].withdraw(amount);
System.out.println("Account "+id+" balance = "+ accounts[id].getBalance());
  
amount =40;
  
System.out.println("\nAttempting to withdraw "+amount+" from Account "+id);
accounts[id].withdraw(amount);
System.out.println("Account "+id+" balance = "+ accounts[id].getBalance());
  
  
amount =500;
  
System.out.println("\nAttempting to withdraw "+amount+" from Account "+id);
accounts[id].withdraw(amount);
System.out.println("Account "+id+" balance = "+ accounts[id].getBalance());
  
amount =391;
  
System.out.println("\nAttempting to withdraw "+amount+" from Account "+id);
accounts[id].withdraw(amount);
System.out.println("Account "+id+" balance = "+ accounts[id].getBalance());
  
amount =370;
  
System.out.println("\nAttempting to withdraw "+amount+" from Account "+id);
accounts[id].withdraw(amount);
System.out.println("Account "+id+" balance = "+ accounts[id].getBalance());
  
  
  
}
  
}

output:

Output-AccountDemo (run) X Account 1 balance500.0 Attempting to withdraw 50.0 from Account 1 Account 1 balance450.0 Attemptin

//for any clarification, please do comments

Add a comment
Know the answer?
Add Answer to:
in java instructions Assignment 2 Complete Exercise E9.3 (checking account problem). What to turn in: A...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Use the Java codes below (Checking Account and Checking Account Demo), and work on these problems....

    Use the Java codes below (Checking Account and Checking Account Demo), and work on these problems. You have to do both of your java codes based on the two provided Java codes. Create one method for depositing and one for withdrawing. The deposit method should have one parameter to indicate the amount to be deposited. You must make sure the amount to be deposited is positive. The withdraw method should have one parameter to indicate the amount to be withdrawn...

  • The Checking account is interest free and charges transaction fees. The first two monthly transactions are...

    The Checking account is interest free and charges transaction fees. The first two monthly transactions are free. It charges a $3 fee for every extra transaction (deposit, withdrawal). The Gold account gives a fixed interest at 5% while the Regular account gives fixed interest at 6%, less a fixed charge of $10. Whenever a withdrawal from a Regular or a Checking account is attempted and the given value is higher than the account's current balance, only the money currently available...

  • code must be in java. Assignment 5 Purpose In this assignment, you will implement a class...

    code must be in java. Assignment 5 Purpose In this assignment, you will implement a class hierarchy in Java. Instructions The class hierarchy you will implement is shown below account Package Account manager Package SavingAccount CheckingAccount AccountManager The descriptions of each class and the corresponding members are provided below. Please note that the Visibility Modifiers (public, private and protected) are not specified and you must use the most appropriate modifiers Class AccountManager is a test main program. Create it so...

  • The objectives of this assignment are to: Further enhance your knowledge and skill in Java. Gain...

    The objectives of this assignment are to: Further enhance your knowledge and skill in Java. Gain an understanding and experience with stacks. Gain further experience using generics. Continue to practice good programming techniques. Create a stack class named MyStack that stores generics with the methods shown below. Write a test program that thoroughly tests your stack implementation. void push(E item) push item onto top of stack E peek() return item on top of stack E pop() return item on top...

  • [JAVA] < Instruction> You are given two classes, BankAccount and ManageAccounts ManageAccounts is called a Driver...

    [JAVA] < Instruction> You are given two classes, BankAccount and ManageAccounts ManageAccounts is called a Driver class that uses BankAccount. associate a member to BankAcount that shows the Date and Time that Accounts is created. You may use a class Date. To find API on class Date, search for Date.java. Make sure to include date information to the method toString(). you must follow the instruction and Upload two java files. BankAccount.java and ManageAccounts.java. -------------------------------------------------------------------------- A Bank Account Class File Account.java...

  • You are to write a Java program using the following instructions to build a bank-ATM server...

    You are to write a Java program using the following instructions to build a bank-ATM server system with sockets. A bank holds accounts that can have deposits, withdrawals, or retrievals of balance. The bank server provides the account for transactions when a client uses and ATM machine. The ATM asks for the type of transaction and the amount (if needed), then creates a socket connection to the bank to send the transaction for processing. The bank performs the transaction on...

  • need help with this assignment, please. Part 1 - Java program named MemoryCalculator In your Ubuntu...

    need help with this assignment, please. Part 1 - Java program named MemoryCalculator In your Ubuntu VM (virtual machine), using terminal mode ONLY, do the following: Create the folder program2 In this folder place the text file located on my faculty website in Module 2 called RAMerrors (Do not rename this file, it has no extension.) It is down below. Ths is the file RAMErrors 3CDAEFFAD ABCDEFABC 7A0EDF301 1A00D0000 Each record in this file represents the location of an error...

  • Project 9-2: Account Balance Calculator Create an application that calculates and displays the starting and ending...

    Project 9-2: Account Balance Calculator Create an application that calculates and displays the starting and ending monthly balances for a checking account and a savings account. --->Console Welcome to the Account application Starting Balances Checking: $1,000.00 Savings:  $1,000.00 Enter the transactions for the month Withdrawal or deposit? (w/d): w Checking or savings? (c/s): c Amount?: 500 Continue? (y/n): y Withdrawal or deposit? (w/d): d Checking or savings? (c/s): s Amount?: 200 Continue? (y/n): n Monthly Payments and Fees Checking fee:              $1.00 Savings...

  • pls write psuedocode write UML CODE ALSO example 3 files 1 for abstract 1 for bank...

    pls write psuedocode write UML CODE ALSO example 3 files 1 for abstract 1 for bank account and 1 for savings accounts due in 12 hours Lab Assignment 4a Due: June 13th by 9:00 pm Complete the following Programming Assignment. Use good programming style and all the concepts previously covered. Submit the java files electronically through Canvas by the above due date in 1 Zip file Lab4.Zip. (This is from the chapter on Inheritance.) 9. BankAccount and SavingsAccount Classes Design...

  • Java Programming assignment. 1. Create a class called Square that takes a width parameter in the...

    Java Programming assignment. 1. Create a class called Square that takes a width parameter in the constructor. The Square class should have a draw() method that will draw the square on the screen. Create a class called TestSquare that will take width from the user, create an object of Square, and invoke the draw() method on the square object. Below is a UML diagram for the Square and Rectangle class: 3. Create a zip file that contains your Java programs....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT