ATM Class
Write an ATM class to test your Account Class. The ATM class will prompt for a user name, if there is no account with that user name it will prompt out an error statement and start over. If there is an account with that user name, then it will prompt the user for a password. If the password does not match the user name then another error message and the program will restart and prompt for another user name. If the user name and password match then the user gets a menu of four options:
1. Balance Inquiry
2. Withdrawal
3. Deposit
4. Quit
The user is allowed to select as many options in a row as needed. When the user quits, the code resets and prompts for the next user name. So the ATM section of code really has two parts to it. The first is user validation, getting the proper user name and password. The second is the basic ATM behavior with withdrawal, deposit, etc. options.
My Account Class
import java.security.SecureRandom;
public class Account {
private String name;
private int pword;
private double balance;
private boolean validated;
private static int numOfAccounts = 0;
//********constructor
public Account(){
// assign password equal to account number
pword = numOfAccounts;
// set balance equal to random number between 0 and 1000
SecureRandom rng = new SecureRandom();
balance = rng.nextDouble()*1000;
// initially account is not validated
validated = false;
// assign name starting with A, B, C, ..., A1, B1, C1, ....
if(numOfAccounts < 25) name = Character.toString((char)(numOfAccounts+ 65));
else{
int multiple = numOfAccounts/26;
name = Character.toString((char)((numOfAccounts - 26*multiple)+65)) + multiple;
}
numOfAccounts++;
}
//public methods
public boolean validate(int pword_guess){
if(pword_guess == pword) validated = true;
else validated = false;
return validated;
}
public boolean withdraw(double d) {
if(validated){
if(d > balance) return false;
else{
balance -= d;
return true;
}
}else return false;
}
public void deposit(double d){
if(validated) balance += d;
}
public double getBalance(){
if(validated) return balance;
else return 0;
}
public String getName(){
return name;
}
// have to add this get method so that the subclass, SilverAccount can access the "validated" field
public boolean getValidated(){
return validated;
}
@Override
public String toString(){
if(validated)
return "\n\tName: " + name + "\tPassword: " + pword +"\tbalance: " + "$" + String.format("%.2f", balance)+ "\tValidated: " + validated;
else return "";
}
}
In the file Atm.java write the following code
import java.security.SecureRandom;
import java.util.*;
class Atm
{
static String username;
public static void reset()
{
Scanner sc = new
Scanner(System.in);
System.out.println("enter
username:\t");
username = sc.nextLine();
double amount;
int password;
Account a1 = new Account();
System.out.println("enter
password:\t");
password = sc.nextInt();
if(a1.validate(password))
{
int ch;
do
{
System.out.println("************ Menu
*************\n");
System.out.println("1.Balance Inquiry\n");
System.out.println("2.WithDrawl\n");
System.out.println("3.Deposit\n");
System.out.println("4.Quit\n");
System.out.println("enter your
choice:\t");
ch = sc.nextInt();
switch(ch)
{
case 1:
double
balance = a1.getBalance();
System.out.println("your account balance: "+balance);
System.out.println(a1.toString());
break;
case 2:
System.out.println("enter the amount to withdraw:\t");
amount =
sc.nextDouble();
if(a1.withdraw(amount))
{
System.out.println("collect the
amount\n");
System.out.println(a1.toString());
}
else
{
System.out.println("insufficient
funds\n");
}
break;
case 3:
System.out.println("enter the amount to deposit:\t");
amount =
sc.nextDouble();
a1.deposit(amount);
System.out.println("successfullly deposited\n");
System.out.println(a1.toString());
break;
case 4:
reset();
break;
default:
System.out.println("Invalid Option\n");
}
}while(ch!=4);
}
else
{
reset();
}
}
public static void main(String[] args)
{
reset();
}
}


If you have any doubts please
comment and please don't dislike.
ATM Class Write an ATM class to test your Account Class. The ATM class will prompt...
ATM Revisited In Java, design a subclass of the Account class called GoldAccount. It is still an Account class, however it has an additional field and some additional functionality. But it will still retain all the behavior of the Account class. Write a class called GoldAccount. This class will have an additional private field called bonusPoints. This field will require no get or set methods. But it will need to be initialized to 100 in the constructor. Thereafter, after a...
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...
Assignment (to be done in Java):
Person Class:
public class Person extends Passenger{
private int numOffspring;
public Person() {
this.numOffspring = 0;
}
public Person (int numOffspring) {
this.numOffspring = numOffspring;
}
public Person(String name, int birthYear, double weight, double
height, char gender, int numCarryOn, int numOffspring)
{
super(name, birthYear, weight, height, gender,
numCarryOn);
if(numOffspring < 0) {
this.numOffspring = 0;
}
this.numOffspring = numOffspring;
}
public int getNumOffspring() {
...
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...
NETBEANS JAVA BANK PROGRAM (TAKE SCREENSHOTS FROM NETBEANS INCLUDING OUTPUT PLEASE) Display the accounts for the current displayed customer PLEASEEEEEEEEEE package bankexample; import java.util.UUID; public class Customer { private UUID id; private String email; private String password; private String firstName; private String lastName; public Customer(String firstName, String lastName, String email, String password) { this.id = UUID.randomUUID(); this.firstName = firstName; this.lastName = lastName; this.email = email; this.password = password; } public String getFirstName() { return firstName; } public void setFirstName(String...
Write a unit test to test the following class. Using Java : //Test only the debit method in the BankAccount. : import java.util.*; public class BankAccount { private String customerName; private double balance; private boolean frozen = false; private BankAccount() { } public BankAccount(String Name, double balance) { customerName = Name; this.balance = balance; } public String getCustomerName() { return customerName; } public double getBalance() { return balance; } public void setDebit(double amount) throws Exception { if (frozen) { throw...
Need help debugging. first class seems fine. second class is shooting an error on s = super.getString(prompt); third class is giving me an error in the while loop where int num = console.getInt("Enter an integer:"); //-------------------------------------------------------------------------- import java.util.Scanner; public class Console { private Scanner sc; boolean isValid; int i; double d; public Console() { sc = new Scanner(System.in); } public String getString(String prompt) { System.out.print(prompt); return sc.nextLine();...
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...
JAVA public static String generatePassword(String gp) { String password=""; boolean b= false; for (int i =0;i { char ch = gp.charAt(i); if (i == 0) { password += Character.toUpperCase(ch); } if (ch == 'S' || ch == 's') ...
Can someone tell me how to create a test for the following Hotel classes that test all of the methods? public class Bed { private String type; private static final String[] TYPES ={"Single", "Double", "King Size"}; public Bed(String type) { this.type = type; } public boolean isSingle() { return type.equals(TYPES[0]); } public boolean isDouble() { return type.equals(TYPES[1]); } public boolean isKingSize() { return type.equals(TYPES[2]); } } public class Guest { private String name; public Guest (String name) { this.name...