Question

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.

  1. Create one method for depositing and one for withdrawing.
    1. 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.
    2. The withdraw method should have one parameter to indicate the amount to be withdrawn and use Boolean return type to show the success of the operation. If the amount to be withdrawn is negative or one tries to over-withdraw (i.e the withdrawing amount is more than the balance), make no change on the balance and return false. If the withdrawn amount is allowed, update the balance by subtracting this withdrawing amount from it and then return true.
  2. Create a displayAccount() method.
    1. Print a nice head that includes the customer’s name (similar to the Employee class example)
    2. Display the account number, owner’s name, and current balance, each at a separate line
  3. Modify the main method in the CheckingAccountDemo class
    1. Ask for the name, account number, and initial balance for one account from the keyboard input. Create a CheckingAccount object and initialize it using the constructor and the keyboard input values on name, account number, and initial balance. Call the displayAccount() method to print the summary of this account.
    2. Ask user to input the deposit amount from keyboard, then deposit it into the account you created by calling the deposit method of the CheckingAccount object you have created. Call the displayAccount() method to print the summary of this account.
    3. Ask user to input the withdraw amount from keyboard, then try to withdraw that amount from the account object. If the operation is successful, call the displayAccount() method to print the summary of this account. Otherwise print the error information that the withdrawing operation failed.

CHECKING ACCOUNT JAVA:

public class CheckingAccount {
   private int AccNumber;
   private String Owner;
   private double Balance;
  
   CheckingAccount(int AccNumber, String Owner, double Balance)
   {
   if(Balance<0)
   {
   System.err.println("Error. The Balance can't be negative");
   this.Balance = 0.0;
   }
   else
   this.Balance = Balance;
   this.AccNumber = AccNumber;
   this.Owner = Owner;
  
  
   }
   // setter functions
   void setAccNumber(int AccNumber)
   {
   this.AccNumber = AccNumber;
   }
   void setOwner(String Owner)
   {
   this.Owner = Owner;
   }
   void setBalance(double Balance)
   {
   if(Balance<0)
   {
   System.err.println("Error. The Balance can't be negative");
   this.Balance = 0.0;
   }
   else
   this.Balance = Balance;
   }
   //getter functions
   int getAccNumber()
   {
   return this.AccNumber;
   }
   String getOwner()
   {
   return this.Owner;
   }
   double getBalance()
   {
   return this.Balance;
   }
}

CHECKING ACCOUNT DEMO.JAVA

import java.util.*;
public class CheckingAccountDemo {
public static void main(String[] args)
{
double balance;
String ownerName;
int accountNumber;
Scanner input = new Scanner(System.in);
System.out.println("Enter the name of owner of account: ");
ownerName = input.nextLine();
System.out.println("Enter the account Number: ");
accountNumber = input.nextInt();
System.out.println("Enter the account balance: ");
balance = input.nextDouble();
CheckingAccount object1 = new CheckingAccount(accountNumber,ownerName,balance);
//calling getter functions
System.out.println("Name : "+object1.getOwner());
System.out.println("Account number : "+ object1.getAccNumber());
System.out.println("Available balance : "+object1.getBalance());
}

}

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

CheckingAccount.java

public class CheckingAccount {
private int AccNumber;
private String Owner;
private double Balance;
  
CheckingAccount(int AccNumber, String Owner, double Balance)
{
if(Balance<0)
{
System.err.println("Error. The Balance can't be negative");
this.Balance = 0.0;
}
else
this.Balance = Balance;
this.AccNumber = AccNumber;
this.Owner = Owner;
  
  
}
// setter functions
void setAccNumber(int AccNumber)
{
this.AccNumber = AccNumber;
}
void setOwner(String Owner)
{
this.Owner = Owner;
}
void setBalance(double Balance)
{
if(Balance<0)
{
System.err.println("Error. The Balance can't be negative");
this.Balance = 0.0;
}
else
this.Balance = Balance;
}
//getter functions
int getAccNumber()
{
return this.AccNumber;
}
String getOwner()
{
return this.Owner;
}
double getBalance()
{
return this.Balance;
}

//method for display account details
void displayAccount(){
System.out.println("Name : "+getOwner());
System.out.println("Account number : "+ getAccNumber());
System.out.println("Available balance : "+getBalance());
}

//method for deposit
void depositAmount(double value){
if(value<0){
System.out.println("Amount should be positive");
}
else{
this.Balance+=value;
}
}

//method for withdraw
boolean withdrawAmount(double value){
if(value<0 || this.Balance<value){
return false;
}
else
{
this.Balance-=value;
return true;
}
}
}

CheckingAmountDemo.java

import java.util.*;

public class CheckingAccountDemo {
public static void main(String[] args){
double balance;
String ownerName;
int accountNumber;
Scanner input = new Scanner(System.in);
System.out.println("Enter the name of owner of account: ");
ownerName = input.nextLine();
System.out.println("Enter the account Number: ");
accountNumber = input.nextInt();
System.out.println("Enter the account balance: ");
balance = input.nextDouble();
CheckingAccount object1 = new CheckingAccount(accountNumber,ownerName,balance);
  
//calling displayAccount method
object1.displayAccount();


System.out.println("Enter amount to be Deposit:");
double deposit_amount=input.nextDouble();
//calling deposit account
object1.depositAmount(deposit_amount);
object1.displayAccount();
System.out.println("Enter amount to be Withdraw:");
double withdraw_amount=input.nextDouble();

//calling withdrawAmount method
if(object1.withdrawAmount(withdraw_amount)){
System.out.println("Amount withdrawn successfully");
}
else{
System.out.println("Please check enter amount with current balance");
}
object1.displayAccount();
}

}

Add a comment
Know the answer?
Add Answer to:
Use the Java codes below (Checking Account and Checking Account Demo), and work on these problems....
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
  • NOTE: Use the Account class codes in the section below these questions. Modify the main method...

    NOTE: Use the Account class codes in the section below these questions. Modify the main method in the CheckingAccountDemo class: Take out all previous code. Declare an object array with 10 accounts. Create a for loop to ask user to input each account’s information (name, account number, and initial balance) from keyboard and then initialize for each account object. Create a while loop to allow one to work on depositing and withdrawing operations on any account till one want to...

  • /* * To change this license header, choose License Headers in Project Properties. * To change...

    /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package checkingaccounttest; // Chapter 9 Part II Solution public class CheckingAccountTest { public static void main(String[] args) {    CheckingAccount c1 = new CheckingAccount(879101,3000); c1.deposit(350); c1.deposit(220); c1.withdraw(100); c1.deposit(1100); c1.deposit(700); c1.withdraw(350); c1.withdraw(220); c1.withdraw(100); c1.deposit(1100); c1.deposit(700); c1.deposit(1000); System.out.println(c1); System.out.println("After calling computeMonthlyFee()"); c1.computeMonthlyFee(); System.out.println(c1); } } class BankAccount { private int...

  • Point out errors in the following codes and correct them public class CheckingAccount {       //...

    Point out errors in the following codes and correct them public class CheckingAccount {       // Create attributes accountNum, Balance       private int accountNum; // Account Number       private double balance; // Account balance       // Constructor       public void CheckingAccount(int aNum, double balance) {             // Call setters to initialize attribute values             setAccountNumber(aNum);             setBalance;       }       // Setters       public void setAccountNumber(int aNum) {             if (accountNum >= 100) {                   accountNum = aNum;             }...

  • TASK 1 Create a new class called CheckingAccount that extends BankAccount. It should contain a static...

    TASK 1 Create a new class called CheckingAccount that extends BankAccount. It should contain a static constant FEE that represents the cost of clearing onecheck. Set it equal to 15 cents. Write a constructor that takes a name and an initial amount as parameters. Itshould call the constructor for the superclass. It should initializeaccountNumber to be the current value in accountNumber concatenatedwith -10 (All checking accounts at this bank are identified by the extension -10). There can be only one...

  • *Step1: -Create UML of data type classes: reuse from lab3 for class Account, CheckingAccount and SavingAccount...

    *Step1: -Create UML of data type classes: reuse from lab3 for class Account, CheckingAccount and SavingAccount -Read the requirement of each part; write the pseudo-code in a word document by listing the step by step what you suppose to do in main() and then save it with the name as Lab4_pseudoCode_yourLastName *Step2: -start editor eClipse, create the project→project name: FA2019_LAB4PART1_yourLastName(part1) OR FA2019_LAB4PART2_yourLastName (part2) -add data type classes (You can use these classes from lab3) Account_yourLastName.java CheckingAccount_yourLastName.java SavingAccount_yourLastName.java -Add data structure...

  • 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...

  • The code is attached below has the Account class that was designed to model a bank account.

    IN JAVAThe code is attached below has the Account class that was designed to model a bank account. An account has the properties account number, balance, annual interest rate, and date created, and methods to deposit and withdraw funds. I need creat program using the 2 java programs.Create two subclasses for checking and savings accounts. A checking account has an overdraft limit, but a savings account cannot be overdrawn.I need to write a test program that creates objects of Account,...

  • According to the following information, define Account, CheckingAccount, and TestPart1 classes. 1. Account and CheckingAccount classes...

    According to the following information, define Account, CheckingAccount, and TestPart1 classes. 1. Account and CheckingAccount classes Account - number: int - openDate: String - name: String - balance: double + Account(int, String, String, double) + deposit(double): void + withdraw (double): boolean + transferTo(Account, double): int + toString(): String CheckingAccount + CheckingAccount(int, String, String, double) + transferTo(Account, double): int Given the above UML diagam, define Account and CheckingAccount classes as follow: Account (8 points) • public Account(int nu, String op, String...

  • WHERE in this code should you put the main method so that the code will compile...

    WHERE in this code should you put the main method so that the code will compile WITHOUT changing anything else in the code? Simply adding the main method only? public class Account { private String name; private double balance;    public Account(String name, double balance) { this.name = name; if (balance > 0.0) this.balance = balance; } public void deposit(double depositAmount) { if (depositAmount > 0.0) balance += depositAmount; }    public double getBalance() { return balance; } public String...

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