Question

I need to update the code listed below to meet the criteria listed on the bottom....

I need to update the code listed below to meet the criteria listed on the bottom. I worked on it a little bit but I could still use some help/corrections!

import java.util.Scanner;
public class BankAccount {
private int accountNo;
private double balance;
private String lastName;
private String firstName;
public BankAccount(String lname, String fname, int acctNo) {
lastName = lname;
firstName = fname;
accountNo = acctNo;
balance = 0.0;
}
public void deposit(int acctNo, double amount) { // This method is to check that account number is valid, and amount if positive before performing deposit
balance = balance + amount;
}
public void withdraw(int acctNo, double amount) { //This method should check that account number is valid, and balance in account before performing withdrawl
balance = balance - amount;
}
public double getBalance() {
return balance;
}
public String getLastName() {
return lastName;
}
public String getFirstName() {
return firstName;
}
public int getAcctNo() {
return accountNo;
}
public static void main (String [] args) {
String last, first; //name and account number for new object
int acct;
Scanner in = new Scanner(System.in); //create Scanner for input
BankAccount one;
// create bank account object
System.out.println("Enter last name");
last = in.nextLine();
System.out.println("Enter first name");
first = in.nextLine();
System.out.println("Enter account number");
acct = in.nextInt();
one = new BankAccount(last, first, acct);
/* PRINTS OUT THE INFORMATION IN both objects */
System.out.println( BankAccount );
/* ALLOWS THE USER TO enter an account number, and an ammount to deposit */
public void deposit(double depositAmount)
{
balance += depositAmount;
}
System.out.println("Enter account number");
acct = in.nextInt();
System.out.println("Enter deposit ammount");
depositAmount = in.nextDouble();
/* ALLOWS THE USER TO enter an account number, and an amount to withdraw */
public boolean withdraw(double withdrawAmount)
{
if (withdrawAmount > balance){
System.out.println("Insufficient Funds!!!");
return false;
} else {
balance -= withdrawAmount;
return true;
}
}
System.out.println("Enter account number");
acct = in.nextInt();
System.out.println("Enter withdrawal ammount");
withdrawAmount = in.nextDouble();
/* PRINTS OUT THE INFORMATION IN both objects */
System.out.println( acct , depositAmount );
System.out.println( acct , withdrawAmount );
}
}

* bank deposits should only be performed if the account number is accurate and the amount is positive, otherwise an error message should be given

* bank withdrawls should only be performed if the account number is accurate and the account contains enough money to handle the amount of money withdrawn, otherwise an error message should be given

This criterion is linked to a Learning Outcomeaccount number and amount is verified prior to a deposit

This criterion is linked to a Learning Outcomeaccount number and amount are verified prior to making a withdrawl

This criterion is linked to a Learning OutcomeMain program creates a BankAccount answer

This criterion is linked to a Learning OutcomePRINTS OUT THE INFORMATION IN both objects

This criterion is linked to a Learning OutcomeALLOWS THE USER TO enter an account number, and an amount to deposit

This criterion is linked to a Learning OutcomeALLOWS THE USER TO enter an account number, and an amount to withdraw

This criterion is linked to a Learning OutcomePRINTS OUT THE INFORMATION IN both objects

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

I tried to make as little modification as possible. please verify if all the requirements are fulfilled.

# If you have a query/issue with respect to the answer, please drop a comment. I will surely try to address your query ASAP and resolve the issue

# # Please consider providing a thumbs up to this question if it helps you. by doing that, you will help other students who are facing a similar issue.

//--------------OUTPUT----------------------------

Enter last name doug Enter first name james Enter account number 123 Name: james doug Account number: 123 Balance: 0.0 --DEPO

//---------------------------------------------------------------

import java.util.Scanner;

public class BankAccount {

    private int accountNo;

    private double balance;

    private String lastName;

    private String firstName;

    public BankAccount(String lname, String fname, int acctNo) {

        lastName = lname;

        firstName = fname;

        accountNo = acctNo;

        balance = 0.0;

    }

    public void deposit(int acctNo, double amount) { // This method is to check that account number is valid, and amount

        //checks if account number is same

        if (accountNo == acctNo) {

            //if account is valid

            if (amount > 0) {

                //add balance

                balance = balance + amount;

            } else {

                System.out.println("ERROR: Invalid amount");

            }

        } else {

            System.out.println("ERROR: Invalid account number");

        }

    }

    public void withdraw(int acctNo, double amount) { // This method should check that account number is valid, and

        // balance in account before performing withdrawl

        if (accountNo == acctNo) {

            //positive amount

            if (amount > 0) {

                //amount more than balance

                if (amount > balance) {

                    System.out.println("Insufficient Funds!!!");

                } else {

                    balance -= amount;

                }

            } else {

                System.out.println("ERROR: Invalid amount");

            }

        } else {

            System.out.println("ERROR: Invalid account number");

        }

    }


    public double getBalance() {

        return balance;

    }

    public String getLastName() {

        return lastName;

    }

    public String getFirstName() {

        return firstName;

    }

    public int getAcctNo() {

        return accountNo;

    }

    public String toString(){

        return "Name: "+firstName+" "+lastName+"\nAccount number: "+accountNo+"\nBalance: "+balance;

    }

    public static void main(String[] args) {

        String last, first; // name and account number for new object

        int acct;

        Scanner in = new Scanner(System.in); // create Scanner for input

        BankAccount one;

        // create bank account object

        System.out.println("Enter last name");

        last = in.nextLine();

        System.out.println("Enter first name");

        first = in.nextLine();

        System.out.println("Enter account number");

        acct = in.nextInt();

        one = new BankAccount(last, first, acct);

        /* PRINTS OUT THE INFORMATION IN both objects */

        System.out.println(one);

        /* ALLOWS THE USER TO enter an account number, and an ammount to deposit */

        System.out.println("--DEPOSIT--");

        System.out.println("Enter account number");

        acct = in.nextInt();

        System.out.println("Enter deposit ammount");

        double depositAmount = in.nextDouble();

        /* ALLOWS THE USER TO enter an account number, and an amount to withdraw */

        one.deposit(acct, depositAmount);

        System.out.println("--WITHDRAWL--");

        System.out.println("Enter account number");

        acct = in.nextInt();

        System.out.println("Enter withdrawal ammount");

        double withdrawAmount = in.nextDouble();

        one.withdraw(acct, withdrawAmount);

        /* PRINTS OUT THE INFORMATION IN both objects */

        System.out.println(one);

        

    }

}

Add a comment
Know the answer?
Add Answer to:
I need to update the code listed below to meet the criteria listed on the bottom....
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
  • Requirements:  Your Java class names must follow the names specified above. Note that they are...

    Requirements:  Your Java class names must follow the names specified above. Note that they are case sensitive. See our template below.  BankAccount: an abstract class.  SavingAccount: a concrete class that extends BankAccount. o The constructor takes client's firstname, lastname and social security number. o The constructor should generate a random 6-digit number as the user account number. o The initial balance is 0 and the annual interest rate is fixed at 1.0% (0.01).o The withdraw method signature...

  • (Reading & Writing Business Objects) I need to have my Classes be able to talk to...

    (Reading & Writing Business Objects) I need to have my Classes be able to talk to Files. How do I make it such that I can look in a File for an account number and I am able to pull up all the details? The file should be delimited by colons (":"). The Code for testing 'Select' that goes in main is: Account a1 = new Account(); a1.select(“90001”); a1.display(); Below is what it should look like for accounts 90000:3003:SAV:8855.90 &...

  • please rewrite this code as Pseudo-Code,.. basically rewrite the code but in english language , Thank...

    please rewrite this code as Pseudo-Code,.. basically rewrite the code but in english language , Thank you so much! public abstract class BankAccount {    //declare the required class variables    private double balance;    private int num_deposits;    private int num_withdraws;    private double annualInterest;    private double serviceCharges;       //constructor that takes two arguments    // one is to initialize the balance and other    // to initialize the annual interest rate       public BankAccount(double balance,...

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

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

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

  • How would I alter this code to have the output to show the exceptions for not...

    How would I alter this code to have the output to show the exceptions for not just the negative starting balance and negative interest rate but a negative deposit as well? Here is the class code for BankAccount: /** * This class simulates a bank account. */ public class BankAccount { private double balance; // Account balance private double interestRate; // Interest rate private double interest; // Interest earned /** * The constructor initializes the balance * and interestRate fields...

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

  • If I enter a negative value the program throws an error and the withdrawal amount is...

    If I enter a negative value the program throws an error and the withdrawal amount is added to the balance please help me find why? public abstract class BankAccount { private double balance; private int numOfDeposits; private int numOfwithdrawals; private double apr; private double serviceCharge; //Create getter and setter methods public double getBalance() { return balance; } public void setBalance(double balance) { this.balance = balance; } public int getNumOfDeposits() { return numOfDeposits; } public void setNumOfDeposits(int numOfDeposits) { this.numOfDeposits =...

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