Question

this is for java programming Please use comments Use the Account class created in homework 8_2...

this is for java programming

Please use comments

Use the Account class created in homework 8_2 to simulate an ATM machine. Create ten checking accounts in an array with id 0, 1, …, 9, initial balance of $100, and annualInterestRate of 0. The system prompts the user to enter an id between 0 and 9, or 999 to exit the program. If the id is invalid (not an integer between 0 and 9), ask the user to enter a valid id. Once an id is accepted, display the main menu as shown in the sample run. You can enter a choice 1 for viewing the current balance, 2 for withdrawing money, 3 for depositing money, and 4 for exiting the main menu for the selected account. Once you exit, the system will prompt for an id (of an account) again.

*** Please read sections 7.1 and 7.2 of Revel on the basics of single dimensional arrays if needed.

Sample run

Welcome to the ATM machine game!

Enter an ID between 0 and 9, 999 to quit the game: 4 //Account with id 4 is selected

Main menu

1: check balance

2: withdraw

3: deposit

4: exit

Enter a choice: 1

The balance is 100.0

Main menu

1: check balance

2: withdraw

3: deposit

4: exit

Enter a choice: 2

Enter an amount to withdraw: 23

Main menu

1: check balance

2: withdraw

3: deposit

4: exit

Enter a choice: 1

The balance is 77.0

Main menu

1: check balance

2: withdraw

3: deposit

4: exit

Enter a choice: 3

Enter and amount to deposit: 10

Main menu

1: check balance

2: withdraw

3: deposit

4: exit

Enter a choice: 1

The balance is 87.0

Main menu

1: check balance

2: withdraw

3: deposit

4: exit

Enter a choice: 4

Enter an ID between 0 and 9, 999 to quit the game: 999

Game over. Good bye!


This is a test run but this a way the program needs to run, please try and keep it simple and nothing too complex if possible

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

Here is code:

import java.util.Scanner;

public class AtmAccount {

public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int[] balance = { 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 };
int choice = 0, id;
double amount;
System.out.println("Welcome to the ATM machine game!");
while (true) {
System.out.print("Enter an ID between 0 and 9, 999 to quit the game: ");
id = input.nextInt();
while ((id < 0 || id >= balance.length) && id != 999) {
System.out.print("Please Enter an ID between 0 and 9, 999 to quit the game: ");
id = input.nextInt();
}
if (id == 999)
break;
do {
System.out.println("\t\t1. = View your Balance");
System.out.println("\t\t2. = Withdraw Cash");
System.out.println("\t\t3. = Deposit Cash");
System.out.println("\t\t4. = Exit");
System.out.print("\nEnter your selection: ");
choice = input.nextInt();
if (choice < 1 || choice > 4) {
System.out.println("Invalid choice, Try again");
} else {
if (choice == 1) {
System.out.println("\nYour current balance is " + balance[id] + "\n");
} else if (choice == 2) {
System.out.print("\nEnter the amount your want to withdraw : ");
amount = input.nextDouble();
balance[id] -= amount;
} else if (choice == 3) {
System.out.print("\nEnter the amount your want to deposit : ");
amount = input.nextDouble();
balance[id] += amount;
} else if (choice == 4) {
break;
}
}

} while (choice != 4);
}

}

}

Output:

Add a comment
Know the answer?
Add Answer to:
this is for java programming Please use comments Use the Account class created in homework 8_2...
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
  • Create a class named UserAccounts that defines an array of 8 accounts as an instance variable....

    Create a class named UserAccounts that defines an array of 8 accounts as an instance variable. In the default constructor of this class, write a loop that creates 8 accounts with ids 1 through 7 and initial balance of $50 for each account. Store these accounts in the array. When the program runs, it asks the use to enter a specific id. When the user enters a correct id, the system displays a menu as shown in the sample run...

  • answer in c++ code. use comments when writing the code to know what's your thinking. there is three pictures with information Write a C++ console program that defines and utilizes a cl...

    answer in c++ code. use comments when writing the code to know what's your thinking. there is three pictures with information Write a C++ console program that defines and utilizes a class named ATM. This program will demonstrate a composition relationship among classes because an ATM can contain many Accounts. You will need to reuse/modify the Account class you created in Assignment 10. The default constructor for the ATM class should initialize a private vector of 10 accounts, each with...

  • Banking System (Java Programming) 1 bank (Bank) has 5 accounts holder (Account) also designing te...

    Banking System (Java Programming) 1 bank (Bank) has 5 accounts holder (Account) also designing textbased menu (switch case): Main Menu: 1. Admin Login 2. User Login 3. Exit Admin Menu: 1. Add an Account 2. Remove an Account 3. Print total balance 4. Print total balance per city 5. Go back to main menu User Login 1. Withdraw //also redo last withdraw 2. Deposit //also redo last deposit 3. print account 4. Go back to main menu Designing class Account...

  • This is for java programming Please Show plenty of comments so I can follow the steps...

    This is for java programming Please Show plenty of comments so I can follow the steps Design a class named Account that contains: • A private int data field named id for the account (default 0) • A private double data field named balance for the account (default 0) • A private double data field named annualInterestRate that stores the current interest rate (default 0). Assume all accounts have the same interest rate. • A private Date data field named...

  • JAVA PLEASE Create a class called Account with the following instance data Integer id Double balance...

    JAVA PLEASE Create a class called Account with the following instance data Integer id Double balance Provides the following methods Default constructor (defaults balance to 100) Constructor with parameters for the ID and the starting balance Accessor and mutator methods for id and balance Method to perform a withdrawal Method to perform a deposit Create a class called Bank which has an array of Account objects. This class will manage the accounts. It must provide methods Do withdrawal Do deposits...

  • I need to write a java program call atm machine. Simulate An Atm Machine. create 10...

    I need to write a java program call atm machine. Simulate An Atm Machine. create 10 accounts in an array with id,…,9 and an initial balance of $100. The Systems Prompts the user to enter an id. If the id is entered incorrectly it will ask the user to enter a correct id. Once an id is accepted, the main menu is displayed as shown in the sample run. You can choice 1 for viewing the current balance, 2 for...

  • Design a class that contains: we have to make 3 files header file , one .cpp...

    Design a class that contains: we have to make 3 files header file , one .cpp file for function and one more main cpp file 9.3 (The Account class) Design a class named Account that contains: An int data field named id for the account. A double data field named balance for the account. A double data field named annualInterestRate that stores the current interest rate. A no-arg constructor that creates a default account with id 0, balance 0, and...

  • Consider the following Account class and main function: class Account: acct_num=1000 #Constructor for Account class (default...

    Consider the following Account class and main function: class Account: acct_num=1000 #Constructor for Account class (default values for balance #and annual interest rate are 100 and e, respectively). #INITIALIZER METHOD HEADER GOES HERE #MISSING CODE def getId(self): return self._id def getBalance(self): #MISSING CODE def getAnnualInterestRate(self): return self.___annualInterestRate def setBalance(self, balance): self. balance - balance def setAnnualInterestRate(self,rate): #MISSING CODE def getMonthlyInterestRate(self): return self. annualInterestRate/12 def getMonthlyInterest (self): #MISSING CODE def withdraw(self, amount): #MISSING CODE det getAnnualInterestRate(self): return self. annualInterestRate def setBalance(self,...

  • Textual menus work by showing text items where each item is numbered. The menu would have...

    Textual menus work by showing text items where each item is numbered. The menu would have items 1 to n. The user makes a choice, then that causes a function to run, given the user made a valid choice. If the choice is invalid an error message is shown. Whatever choices was made, after the action of that choice happens, the menu repeats, unless the menu option is to quit. Such kind of menus are displayed from the code under...

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

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