Question

In: Computer Science

Design the Class Diagram (UML) for a banking system with its clients’ accounts and an ATM...

Design the Class Diagram (UML) for a banking system with its clients’ accounts and an ATM machine. Each client account holds the user’s name (String of Full Name), account number (int) and balance (int). All client account details should be hidden from other classes but the system should provide tools/methods to access, change, and display (toString for account) each of these details.

The ATM machine holds the available money inside it (double) and the maximum money it can hold (double).

A user can request to withdraw, deposit or display balance through their account after checking the possibility of the action based on the ATM machine attributes. The balance display can be directly sent to the ATM. However, the withdraw request needs checking the user’s balance before checking the cash availability in the ATM machine. Also the deposit requires ensuring that the amount of cash will not exceed the maximum of the ATM.

For example, if the machine is full with cash then a user cannot deposit his money and a message should be displayed to the client that the machine is full and money cannot be deposited. In addition, if the machine has lower amount than what the withdraw request requires, the operation will be cancelled with an appropriate message on the standard output.

Use a default constructor (no formal parameters) and a full constructor (all class variables are initialized from formal parameters) for the client account.

object oriented programming "" Eclipse java"

Solutions

Expert Solution

AccountType.java

// enumeration for account type
public enum AccountType {
   SAVING,CHECKING
}

Account.java


public class Account {
   // instance variables
   private int accountNo;
   private String name;
   private String username;
   private String password;
   private double savingAccount;
   private double checkingAccount;
   // default constructor
   public Account() {
       super();
   }
   // parameterized constructor
   public Account(int accountNo, String name, String username, String password, double savingAccount,
           double checkingAccount) {
       super();
       this.accountNo = accountNo;
       this.name = name;
       this.username = username;
       this.password = password;
       this.savingAccount = savingAccount;
       this.checkingAccount = checkingAccount;
   }
   // method to deposit amount
   public boolean deposit(AccountType type,double amount) {
       if(type.equals(AccountType.SAVING))
           savingAccount+=amount;
       else
           checkingAccount+=amount;
       return true;
   }
   // method to withdraw amount
   public boolean withdraw(AccountType type,double amount) {
       if(type.equals(AccountType.SAVING)) {
           if(savingAccount>=amount)
               savingAccount-=amount;
           else
               return false;
       }
       else {
           if(checkingAccount>=amount)
               checkingAccount-=amount;
           else
               return false;
       }
       return true;
   }
   // method for balance inquiry
   public double balanceEnquiry(AccountType type){
       if(type.equals(AccountType.SAVING))
           return savingAccount;
       else
           return checkingAccount;
   }
   // method for transfer balance
   public boolean transferBalance(Account toAccount,AccountType type,double amount) {
       if(withdraw(type, amount))
           if(toAccount.deposit(type, amount))
               return true;
       return false;
   }
   // setter and getter methods
   public int getAccountNo() {
       return accountNo;
   }
   public void setAccountNo(int accountNo) {
       this.accountNo = accountNo;
   }
   public String getName() {
       return name;
   }
   public void setName(String name) {
       this.name = name;
   }
   public String getUsername() {
       return username;
   }
   public void setUsername(String username) {
       this.username = username;
   }
   public String getPassword() {
       return password;
   }
   public void setPassword(String password) {
       this.password = password;
   }
}

ATM.java

import java.util.ArrayList;
import java.util.Scanner;
// ATM
public class ATM {
   // method to display menu for operation provided by ATM machine
   public static void operationMenu() {
       System.out.println("*************************************************");
       System.out.println("1. Deposit");
       System.out.println("2. Withdrawal");
       System.out.println("3. Balance Inquiry");
       System.out.println("4. Transfer Balance");
       System.out.println("5. Log Out");
       System.out.println("*************************************************");
       System.out.print("Enter your choice: ");
   }
   // method to show currently logged in account details
   public static void showLoggedAccount(Account loggedAccount) {
       System.out.println("---------------------------------------------------------------------------------------");
       System.out.println("| Customer | Username | Password | Saving Account | Checking Account |");
       System.out.println("---------------------------------------------------------------------------------------");
       System.out.println("| "+loggedAccount.getName()+" | "+loggedAccount.getUsername()+" | "+loggedAccount.getPassword()+" | $"
               +loggedAccount.balanceEnquiry(AccountType.SAVING)+" | $"+loggedAccount.balanceEnquiry(AccountType.CHECKING)+" |");
       System.out.println("---------------------------------------------------------------------------------------");
   }
   // method to get account type
   public static AccountType getAccountType() {
       System.out.println("Select account type:");
       System.out.println("1. Saving Account");
       System.out.println("2. Checking Account");
       System.out.print("Enter your choice: ");
       @SuppressWarnings("resource")
       int choice=new Scanner(System.in).nextInt();
       if(choice==1)
           return AccountType.SAVING;
       else
           return AccountType.CHECKING;
   }
   // main method
   public static void main(String[] args) {
       // create array list with Account type to store accounts
       ArrayList<Account> bank=new ArrayList<>();
       // create and add account into array list
       bank.add(new Account(1001, "Robert Brown", "rbrown", "blue123", 2500.00, 35.00));
       bank.add(new Account(1002, "Steve Rogers", "rsteve", "cap123", 1750.00, 851.25));
       @SuppressWarnings("resource")
       // Scanner class object to get the input from user
       Scanner sc=new Scanner(System.in);
       Account loggedAccount=null; // Account class reference
       System.out.println("*** Log In ***");
       while(true) {
           System.out.print("Enter username: ");
           String user=sc.next(); // get username from user
           System.out.print("Enter password: ");
           String pass=sc.next(); // get password from user
           // logging in with credentials
           for (Account account : bank) {
               if(account.getUsername().equals(user))
                   if(account.getPassword().equals(pass))
                       loggedAccount=account;
           }
           if(loggedAccount!=null)
               break; // if credentials are correct
           else
               // if credentials are wrong
               System.out.println("Invalid username password..try again...!!!\n");
       }
       // show account details
       showLoggedAccount(loggedAccount);
       while(true) {
           double amount=0;
           System.out.println();
           //. display operations menu
           operationMenu();
           int choice=sc.nextInt(); // get choice from user
           // working on user's choice
           switch (choice) {
           case 1:
               System.out.print("Enter amount to deposit: ");
               amount=sc.nextDouble(); // get amount to deposit from user
               // deposit amount
               if(!loggedAccount.deposit(getAccountType(), amount))
                   System.out.println("Deposit failed");
               else
                   System.out.println("Amount deposited successfully...!!!");
               break;
           case 2:
               System.out.print("Enter amount to withdraw: ");
               amount=sc.nextDouble(); // get amount to withdraw from user
               if(!loggedAccount.withdraw(getAccountType(), amount))
                   System.out.println("Insufficient account balance...!!!");
               else
                   System.out.println("Amount withdrawn successfully...!!!");
               break;
           case 3:
               // get account balance
               amount=loggedAccount.balanceEnquiry(getAccountType());
               System.out.println("Account Balance is: $"+amount);
               break;
           case 4:
               System.out.print("Enter to account number: ");
               int toAccountNo=sc.nextInt(); // get to-account number
               Account toAccount=null;
               for (Account account : bank) {
                   if(account.getAccountNo()==toAccountNo)
                       toAccount=account;
               }
               System.out.print("Enter amount to transfer: ");
               amount=sc.nextDouble(); // get amount to transfer
               if(toAccount!=null) {
                   // transfer amount
                   if(!loggedAccount.transferBalance(toAccount, getAccountType(), amount))
                       System.out.println("Insufficient account balance...!!!");
                   else
                       System.out.println("Amount transferred successfully...!!!");
               }else
                   System.out.println("Wrong to account number...!!!");
               break;
           case 5:
               showLoggedAccount(loggedAccount);
               System.out.println("\n\n*** LOgged Out ***\nThank you for banking with us...!!!");
               System.exit(0); // exit from program
               break;
           default:
               System.out.println("Wrong choice...!!!");
               break;
           }
       }
   }
}

Output


Related Solutions

Complete the following class UML design class diagram by filling in all the sections based on...
Complete the following class UML design class diagram by filling in all the sections based on the information given below.         The class name is Boat, and it is a concrete entity class. All three attributes are private strings with initial null values. The attribute boat identifier has the property of “key.” The other attributes are the manufacturer of the boat and the model of the boat. Provide at least two methods for this class. Class Name: Attribute Names: Method...
draw a uml diagram for a class
draw a uml diagram for a class
In Java Design a Triangle class (Triangle.java) that extends GeometricObject. Draw the UML diagram for both...
In Java Design a Triangle class (Triangle.java) that extends GeometricObject. Draw the UML diagram for both classes and implement Triangle. The Triangle class contains: ▪ Three double data fields named side1, side2, and side3 with default values 1.0 to denote three sides of the triangle. ▪ A no-arg constructor that creates a default triangle. ▪ A constructor that creates a triangle with the specified side1, side2, side3, color, and filled arguments. ▪ The accessor methods for all three data fields....
create the UML Diagram to model a Movie/TV viewing site. Draw a complete UML class diagram...
create the UML Diagram to model a Movie/TV viewing site. Draw a complete UML class diagram which shows: Classes (Only the ones listed in bold below) Attributes in classes (remember to indicate privacy level, and type) No need to write methods Relationships between classes (has is, is a, ...) Use a program like Lucid Cart and then upload your diagram. Each movie has: name, description, length, list of actors, list of prequals and sequals Each TV Show has: name, description,...
Draw a UML diagram for the classes. Code for UML: // Date.java public class Date {...
Draw a UML diagram for the classes. Code for UML: // Date.java public class Date {       public int month;    public int day;    public int year;    public Date(int month, int day, int year) {    this.month = month;    this.day = day;    this.year = year;    }       public Date() {    this.month = 0;    this.day = 0;    this.year = 0;    } } //end of Date.java // Name.java public class Name...
A UML class diagram can be used to model UML by considering each graphical component of...
A UML class diagram can be used to model UML by considering each graphical component of the notation to be a class. For example, a class diagram contains a collection of classes. Your problem is to construct and draw one class diagram with the below UML elements. That is, there will be a class for each of the elements listed. You must also provide ALL of the relationships between each of these classes. The elements to model in the class...
Draw a UML diagram that describes a class that will be used to describe a product...
Draw a UML diagram that describes a class that will be used to describe a product for sale on Glamazon.com. The product has a name, a description, a price, ratings by many customers (1 to 5 stars), and a group of customer comments. New products have no ratings or comments by customers, but do have a name, description and price. The price can be changed and more customer ratings and comments can be added. A global average rating of all...
What would the pseudocode look like for this UML class diagram? Class - oranges: String -...
What would the pseudocode look like for this UML class diagram? Class - oranges: String - bananas: String - grapes: String - apples: String + Class(String bananas, String grapes, String apples) + oranges( ): void + isValidGrapes( ): boolean + isValidApples( ): boolean + getOranges( ): String + getBananas( ): String + setBananas(String bananas): void + getGrapes( ): String + setGrapes(String grapes): void + getApples( ): String + setApples(String apples): void
Given the following UML class diagram, implement the class as described by the model. Use your...
Given the following UML class diagram, implement the class as described by the model. Use your best judgment when implementing the code inside of each method. +---------------------------------------------------+ | Polygon | +---------------------------------------------------+ | - side_count : int = 3 | | - side_length : double = 1.0 | +---------------------------------------------------+ | + Polygon() | | + Polygon(side_count : int) | | + Polygon(side_count : int, side_length : double) | | + getSides() : int | | + setSides(side_count : int) | |...
Given the following specification, design a class diagram using PlantUML. To design the class diagram, use...
Given the following specification, design a class diagram using PlantUML. To design the class diagram, use abstract, static, package, namespace, association, and generalization on PlantUML Specification: A school has a principal, many students, and many teachers. Each of these persons has a name, birth date, and may borrow and return books. The book class must contain a title, abstract, and when it is available. Teachers and the principal are both paid a salary. A school has many playgrounds and rooms....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT