Question

In: Computer Science

Your objective is to write a well-documented simple program using classes, a loop, and nested ifs...

Your objective is to write a well-documented simple program using classes, a loop, and nested ifs to simulate an ATM using JAVA.

1. Create an ATM class with class variables name, pin, and balance, a constructor with parameters to assign values to the three instance variables, methods to get the name, pin, and balance, and methods to handle validated deposits and withdrawals ( deposit and withdrawal amounts cannot be negative, and withdrawal amount must not be greater than the existing balance).

2. In the ATMTest class, read the names, 4 digit pin numbers, and account balances of two customers into two instances of the ATM class. Display the two customers names, pins, and balances formatted.

3. Now that you have all your customers’ information start your ATM to accomplish the following within an infinite loop,

a). Display a welcome screen with your bank’s information and prompt for and read the customer entered pin.

b). Use a nested if to match the entered pin with one of the two customers’ pins. If the entered pin number matches that of one of the customers, then:

i. Welcome the customer by name and display the balance.

ii. Display option to 1. DEPOSIT, 2. WITHDRAW or 3. EXIT.

iii. If option 1 is selected, then use the instance deposit method to prompt for deposit amount, read, and add a valid deposit amount to the customer’s balance

iv. If option 2 is selected, then use the instance withdrawal method to subtract a valid withdrawal amount from the customers balance

v. If option 3 is selected, go to step a.

4. Should the entered pin number not match either of the two customers, notify the customer that the entered pin is not valid and go to step a.

5. Selection of the EXIT option must display welcome/login screen (step a).

6. Should an incorrect option be entered, notify the user and display the original welcome/login screen (step a).

Solutions

Expert Solution

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
_________________


// ATM.java

public class ATM {
   //Declaring instance variables
   private String name;
   private int pin;
   private double balance;

   //Parameterized constructor
   public ATM(String name, int pin, double balance) {
       this.name = name;
       this.pin = pin;
       this.balance = balance;
   }

   // getters and setters
   public String getName() {
       return name;
   }

   public void setName(String name) {
       this.name = name;
   }

   public int getPin() {
       return pin;
   }

   public void setPin(int pin) {
       this.pin = pin;
   }

   public double getBalance() {
       return balance;
   }

   public void setBalance(double balance) {
       this.balance = balance;
   }

   //This method will perform the deposit operation
   public void deposit(double amt)
   {
       this.balance+=amt;
   }

   //This method will perform the withdrawl operation
   public void withdrawl(double amt)
   {
       if(amt<=balance)
       {
           this.balance-=amt;
       }
       else
       {
           System.out.println("** Your balance is low **");
       }
   }
}

_________________________

// Test.java

import java.util.ArrayList;
import java.util.Scanner;

public class Test {
   /*
   * Creating an Scanner class object which is used to get the inputs
   * entered by the user
   */
   static Scanner sc = new Scanner(System.in);
   public static void main(String[] args) {
       String name;
       int pin,choice,flag=0,custIndx = 0;
       double balance;
       ArrayList<ATM> arl=new ArrayList<ATM>();
  

       for(int i=0;i<2;i++)
       {
           //Getting the input entered by the user
System.out.print("Enter User#"+(i+1)+" name :");
name=sc.nextLine();
System.out.print("Enter Pin :");
pin=sc.nextInt();
System.out.print("Enter balance $:");
balance=sc.nextDouble();
ATM atm=new ATM(name, pin, balance);
arl.add(atm);   
sc.nextLine();
       }
      
       while(true)
       {
           System.out.println("\n\n:: WELCOME TO THE LUCKY BANK ::");
             
           while(true)
           {
               flag=0;
               System.out.print("Enter PIN :");
               pin=sc.nextInt();
               for(int i=0;i<arl.size();i++)
               {
                   if(arl.get(i).getPin()==pin)
                   {
                       flag=1;
                       custIndx=i;
                   }
                 
               }
               if(flag==0)
               {
                   System.out.println("** Invalid Pin **");
               }
               else
               {
                   break;
               }
                 
           }

           while(true)
           {
               System.out.println("1.DEPOSIT\n2. WITHDRAW\n3. EXIT.");
           System.out.print("Enter Choice :");
           choice=sc.nextInt();
           switch(choice)
           {
           case 1:{
               System.out.print("Enter Amount to Deposit :$");
               double amt=getValidAmount();
               arl.get(custIndx).deposit(amt);
               System.out.println("Account balance after deposit :$"+arl.get(custIndx).getBalance());
               continue;
           }
           case 2:{
               System.out.print("Enter Amount to Withdrawl :$");
               double amt=getValidAmount();
               arl.get(custIndx).withdrawl(amt);
               System.out.println("Account balance after withdrawl :$"+arl.get(custIndx).getBalance());
               continue;
           }
           case 3:{
               break;
           }
           default :{
               System.out.println("** Invalid Choice **");
           }
          
          
           }
           break;
           }
           break;
           }
         

   }

   private static double getValidAmount() {
       double amt;
       while(true)
       {
           amt=sc.nextDouble();
           if(amt<0)
           {
               System.out.println("** Invalid.Must be positive **");
           }
           else
               break;
       }
       return amt;
   }

}
____________________________

Output:

Enter User#1 name :James
Enter Pin :1234
Enter balance $:45000
Enter User#2 name :Sachin
Enter Pin :3434
Enter balance $:56000


:: WELCOME TO THE LUCKY BANK ::
Enter PIN :4543
** Invalid Pin **
Enter PIN :3434
1.DEPOSIT
2. WITHDRAW
3. EXIT.
Enter Choice :1
Enter Amount to Deposit :$12000
Account balance after deposit :$68000.0
1.DEPOSIT
2. WITHDRAW
3. EXIT.
Enter Choice :2
Enter Amount to Withdrawl :$5000
Account balance after withdrawl :$63000.0
1.DEPOSIT
2. WITHDRAW
3. EXIT.
Enter Choice :3

_______________Could you plz rate me well.Thank You


Related Solutions

Your objective is to write a well-documented simple program using classes, a loop, and nested ifs...
Your objective is to write a well-documented simple program using classes, a loop, and nested ifs to simulate an ATM using JAVA. 1. Create an ATM class with class variables name, pin, and balance, a constructor with parameters to assign values to the three instance variables, methods to get the name, pin, and balance, and methods to handle validated deposits and withdrawals ( deposit and withdrawal amounts cannot be negative, and withdrawal amount must not be greater than the existing...
Write a program that produces the following output using nested for loop in Java. ****** ////////////...
Write a program that produces the following output using nested for loop in Java. ****** //////////// ****** ***** //////////\\ ***** **** ////////\\\\ **** *** //////\\\\\\ *** ** ////\\\\\\\\ ** * //\\\\\\\\\\ * \\\\\\\\\\\\
writing a well documented program with multiple classes and arrays.   Include a pledge and the IDE...
writing a well documented program with multiple classes and arrays.   Include a pledge and the IDE used in the descriptive header of the driver class Create a Student class with Private instance variables for first and last name, three integer scores, the average ,and letter grade A constructor with values Methods to set and get the values of the instance variables Methods to get the average and letter grade Method to calculate the average of the three scores and to...
Using Matlab Write a program that print the following matrix. (hint: use nested for-loop and if-statement)...
Using Matlab Write a program that print the following matrix. (hint: use nested for-loop and if-statement) mat = [2 -1 0 0 0 -1 2 -1 0 0 0 0 -1 2 -1 0 0 0 -1 2];
Write a java program: Write a nested loop program creating an array list of three positions.  The...
Write a java program: Write a nested loop program creating an array list of three positions.  The first loop terminates with a sentinel value of which user is prompted for input to continue of quit.   Inside loop to enter in each position a prompted input of person's first name.  After the inside loop, edit the second array location making its value "Boston". Print the array's contents.
must use python Write a nested for loop that displays the following output using the same...
must use python Write a nested for loop that displays the following output using the same integer from part a:                                                     1                                                 1   2   1                                             1   2   4   2   1                                         1   2   4   8   4   2   1                                     1   2   4   8 16   8   4   2   1                                 1   2   4   8 16 32 16   8   4   2   1                             1   2   4   8 16 32 64 32 16   8   4   2   1                         1   2   4  ...
Need this program Using Classes , Objects, Save to file, and Printbill Simple python assignment Write...
Need this program Using Classes , Objects, Save to file, and Printbill Simple python assignment Write a menu-driven program for Food Court. (You need to use functions!) Display the food menu to a user (Just show the 5 options' names and prices - No need to show the Combos or the details!) Ask the user what he/she wants and how many of it. (Check the user inputs) AND Use strip() function to strip your inputs. Keep asking the user until...
using c++ classes write program in which CString is used, and give simple and easy examples...
using c++ classes write program in which CString is used, and give simple and easy examples in the form of program, to show how to use different CString function, use comments to explain what happened at that function.
Introduction to Java Programing Using Loop Create a simple calculator program using loop Ask user to...
Introduction to Java Programing Using Loop Create a simple calculator program using loop Ask user to input two numbers using scanner class Print the instruction of the menu for the calculator program Ask user to press 0 to Quit Ask user to press 1 to Add Ask user to press 2 to Substract Ask user to press 3 to Multiply Ask user to press 4 to Divide Perform correct calcuation based on user inputs and print the result Print error...
IN JAVA Create a program that uses a nested for loop to display a rectangle of...
IN JAVA Create a program that uses a nested for loop to display a rectangle of #'s with a given number of rows and columns,. This should only display the # when the column is an odd number (see examples below). Get the number of rows and columns from the user, and display the result. Examples: If the user provided rows=4, and columns=7, the program should display a pattern as follows: # # # # # # # # #...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT