2. Write a class called ATMTransaction. This class has a
variable balance and
account number.
It has three methods, checkBalance, deposit and withdraw along with
constructors
getters and setters and a toString. Write a program that
creates an object of this class. I should be able to deposit and
withdraw from
my account number based on my balance , but i shouldnt be able to
change my
account number. Look for loopholes in your program, test it
correctly, your
balance cannot be negative.

class ATMTransaction {
private int accountNumber;
private double balance;
public ATMTransaction(int aAccountNumber, double
aBalance) {
super();
accountNumber =
aAccountNumber;
balance = aBalance;
}
public ATMTransaction(int aAccountNumber) {
super();
accountNumber =
aAccountNumber;
}
public double checkBalance() {
return balance;
}
public void deposit(double am) {
balance += am;
}
public void withdraw(double am) {
if (balance >= am) {
balance -=
am;
} else {
System.out.println("Low balance..can not withdraw");
}
}
public double getBalance() {
return balance;
}
public int getAccountNumber() {
return accountNumber;
}
@Override
public String toString() {
return "AccountNumber : " +
accountNumber + ", Balance=" + balance;
}
}
public class TestATMTransaction {
public static void main(String[] args) {
ATMTransaction atm = new
ATMTransaction(123, 500);
atm.deposit(100);
System.out.println("Balance : " +
atm.checkBalance());
atm.deposit(200);
System.out.println("Balance : " +
atm.checkBalance());
atm.withdraw(500);
System.out.println("Balance : " +
atm.checkBalance());
atm.withdraw(500);
System.out.println("Balance : " +
atm.checkBalance());
System.out.println(atm);
}
}
![«terminated> TestATMTransaction [Java Application] C:\SoftPegaEclipse-win64-4.5.2.29 Balance: 600.0 Balance : 800.0 Balance 3](http://img.homeworklib.com/questions/87d89620-9f57-11ec-b334-fd40ffffef2d.png?x-oss-process=image/resize,w_560)
2. Write a class called ATMTransaction. This class has a variable balance and account number. It...
1. Write a Java program to count all words in a string. User inputs a string sentence and your program should count the number of words in that string. Test Data: Input the string: The quick brown fox jumps over the lazy dog. Expected Output: Number of words in the string: 9 2. Write a class called ATMTransaction. This class has a variable balance and account number. It has three methods, checkBalance, deposit and withdraws along with constructors getters and...
/*Design a class BankAccount that has the following properties: * Account Number (should be static and increased every time an account is created. * An array of holders max 5 and a holder is a Person object * A int to rember how many holders * Balance (float) * Date opened * interest rate * Constructors * addHolder will add one more Person as a holder, if you reach 5 don't add. * Setters getters * method payInterest that add...
Write a Java class called BankAccount (Parts of the code is given below), which has two fields name (String) and balance (double), two constructors and five methods getName(), getBalance(), deposit (double amount), withdraw(double amount) and toString(). The first constructor should initialize name to null and balance to 0. The second constructor initializes name and balance to the parameters passed. deposit method deposits the amount to the account causing the current balance to increase, withdraw method withdraws the amount causing the...
Write a Java class called BankAccount (Parts of the code is given below), which has two fields name (String) and balance (double), two constructors and five methods getName(), getBalance(), deposit (double amount), withdraw(double amount) and toString(). The first constructor should initialize name to null and balance to 0. The second constructor initializes name and balance to the parameters passed. deposit method deposits the amount to the account causing the current balance to increase, withdraw method withdraws the amount causing the...
The Account class Create a class named Account, which has the following private properties: number: long balance: double Create a no-argument constructor that sets the number and balance to zero. Create a two-parameter constructor that takes an account number and balance. First, implement getters and setters: getNumber(), getBalance(), setBalance(double newBalance). There is no setNumber() -- once an account is created, its account number cannot change. Now implement these methods: void deposit(double amount) and void withdraw(double amount). For both these methods,...
Look at the Account class below and write a main method in a different class to briefly experiment with some instances of the Account class.Using the Accountclass as a base class, write two derived classes called SavingsAccountand CurrentAccount.ASavingsAccountobject, in addition to the attributes of an Account object, should have an interest variable and a method which adds interest to the account. ACurrentAccount object, in addition to the instance variables of an Account object, should have an overdraft limit variable. Ensure...
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,...
java. Question 2: Practice Polymorphism- Food A Assume you have a parent class called Food with one instance data variable: private String name. The class has one constructor that takes the name as a parameter, getters and setters for name, and a toString that outputs the name. Write a child class called Vegetable with one additional variable describing whether or not the vegetable is green. Write two constructors: one that takes in all information about a vegetable and one that...
JAVA Create a class called SavingsAccount. The class should have a static variable named, annualInterestRate, to store the annual interest rate for all account holders. Each object of the class should contain a private instance variable named, savingsBalance, indicating the amount the saver currently has on deposit. Write methods to perform the following: calculateMonthlyInterest – calculates the monthly interest by multiplying the savingsBalance by annualInterestRate divided by 12. This interest should be added to the balance. depositAmount – allows the...
Bank Accounts Look at the Account class Account.java and write a main method in a different class to briefly experiment with some instances of the Account class. • Using the Account class as a base class, write two derived classes called SavingsAccount and CheckingAccount. A SavingsAccount object, in addition to the attributes of an Account object, should have an interest variable and a method which adds interest to the account. A CheckingAccount object, in addition to the attributes of an...