Question

In: Computer Science

JAVA PROGRAM: Creates a Bank Account class with one checking account and methods to withdraw and...

JAVA PROGRAM: Creates a Bank Account class with one checking account and methods to withdraw and deposit. Test the methods in the main function.

Solutions

Expert Solution

//Hope this answer helps you

// In case u feel any doubt feel free to ask in comments

// I will be happy to solve them

// code in java to implement a BankAccount class
//Hope u like it
import java.util.*;
import java.util.Scanner;
class BankAccount
{
    public double bal;
    public String accountNumber; 
    public BankAccount(String accountNumber, double initialBalance)//Constructor
    {
        bal = initialBalance;
        accountNumber = accountNumber;
    }
    //Withdraw function
    public void withdraw(double amount)
    {
        double newBal = bal - amount;
        bal = newBal;           
    }
    //Deposit function with depositing balance to existing balance
    public void deposit(double amount)
    {
        double newBal = bal + amount;
        bal = newBal;                   
    }
    // function used to display the details of Account
    public void displayDetails()
    {
        System.out.println("Account Number is: "+accountNumber+" and Balance is: "+bal);
    }
    public static void main(String[] args)
    {
        // making two accounts object of BankAccount class
        BankAccount secondAccount = new BankAccount("3598896", 200000);
        BankAccount firstAccount = new BankAccount("3598895", 100000);
        // calling appropriate functions to test the above functions
        System.out.println("Initial Balance is:");
        firstAccount.displayDetails();
        secondAccount.displayDetails();
        firstAccount.deposit(30000);
        secondAccount.withdraw(10000);
        System.out.println("After operations Balance is:");
        firstAccount.displayDetails();
        secondAccount.displayDetails();
    }
}

SCREENSHOTS:


Related Solutions

This program is written in Java and should be modularized in methods in one class. This...
This program is written in Java and should be modularized in methods in one class. This program will calculate the Gross Earnings, FICA tax (Medicare and Social Security taxes), Federal Tax Withheld, and Net Amount of the payroll check for each employee of a company. The output must contain numbers with 2 decimal places. The user input must be validated – if incorrect data is entered, send an error message to the user. INPUT The application must be able to...
Java - Write a test program that creates an Account object with an account number of...
Java - Write a test program that creates an Account object with an account number of AC1111, a balance of $25,000, and an annual interest rate of 3.5. Use the withdraw method to withdraw $3,500, use the deposit method to deposit $3,500, and print the balance, the monthly interest, and the date when this account was created.
JAVA - Write a program that creates an ArrayList and adds an Account object, a Date...
JAVA - Write a program that creates an ArrayList and adds an Account object, a Date object, a ClockWithAudio object, a BMI object, a Day object, and a FigurePane object. Then display all elements in the list. Assume that all classes (i.e. Date, Account, etc.) have their own no-argument constructor.
Give an example of a program in java that creates a GUI with at least one...
Give an example of a program in java that creates a GUI with at least one button and several textfields. Some of the textfields should be for input and others for output. Make the output textfields uneditable. When the button is clicked, the input fields should be read, some calculation performed and the result displayed in the output textfield(s).
Using Java preferably with Eclipse Task: Write a program that creates a class Apple and a...
Using Java preferably with Eclipse Task: Write a program that creates a class Apple and a tester to make sure the Apple class is crisp and delicious. Instructions: First create a class called Apple The class Apple DOES NOT HAVE a main method Some of the attributes of Apple are Type: A string that describes the apple.  It may only be of the following types:  Red Delicious  Golden Delicious  Gala  Granny Smith Weight: A decimal value representing...
(In C++) Bank Account Program Create an Account Class Create a Menu Class Create a main()...
(In C++) Bank Account Program Create an Account Class Create a Menu Class Create a main() function to coordinate the execution of the program. We will need methods: Method for Depositing values into the account. What type of method will it be? Method for Withdrawing values from the account. What type of method will it be? Method to output the balance of the account. What type of method will it be? Method that will output all deposits made to the...
Write in Java the following: A.  A bank account class that has three protected attributes: account number...
Write in Java the following: A.  A bank account class that has three protected attributes: account number (string), customer name (string), and balance (float). The class also has a parameterized constructor and a method public void withDraw (float amount) which subtracts the amount provided as a parameter from the balance. B. A saving account class that is a child class of the bank account class with a private attribute: penality rate (float). This class also has a parameterized constructor and a...
write program that develop a Java class Dictionary to support the following public methods of an...
write program that develop a Java class Dictionary to support the following public methods of an abstract data type: public class Dictionary { // insert a (key, value) pair into the Dictionary, key value must be unique, the value is associated with the key; only the last value inserted for a key will be kept public void insert(String key, String value); // return the value associated with the key value public String lookup(String key); // delete the (key, value) pair...
CODE IN JAVA: Write a ProductTester class that creates one Product object named "Juicer" with a...
CODE IN JAVA: Write a ProductTester class that creates one Product object named "Juicer" with a price of $50.99, prints the name and price of the product, reduces its price by 4.0, and then prints its price again. public class Product { private String name; private double price; public Product(String productName, double productPrice) { name = productName; price = productPrice; } public String getName() { return name; } public double getPrice() { return price; } public void reducePrice(double amount) {...
Write a Java program to process the information for a bank customer.  Create a class to manage...
Write a Java program to process the information for a bank customer.  Create a class to manage an account, include the necessary data members and methods as necessary.  Develop a tester class to create an object and test all methods and print the info for 1 customer.  Your program must be able to read a record from keyboard, calculate the bonus and print the details to the monitor.  Bonus is 2% per year of deposit, if the amount is on deposit for 5 years...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT