Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

program it using Java Upon starting the program, the user should be asked if the

ID: 3844596 • Letter: P

Question

program it using Java

Upon starting the program, the user should be asked if they are an existing member of the "bank".
- If the user indicates that they are not a member, they should be prompted to enter their information for registration.
- If the user is a member they should be prompted to enter their login credentials (username and password).
- If the credentials are incorrect, they should be prompted again or kicked back to the main menu (after three tries?).
- If the credentials are correct, they should be taken to the members' menu where they have the options of
    1. view a list of their accounts
    2. make a deposit
    3. make a withdrawal
    4. open a new account
    5. close an existing account
    6. logout (return to main menu)
    After completing one of the actions (except logging out), they should be returned to the members' menu.

Design:
When the program starts, it should load members and accounts from a save file.
When the program exits, it should save members and accounts to a save file.
The program should contain a class for accounts and a class for members.

The account class should contain:
- an id number
- a balance
- a type (String)
- a link to the owner's object
- methods to deposit and withdraw money
- any other variables/methods necessary to the function of the program

The member class should contain:
- an id number
- a username (String)
- a password (String)
- a name
- an array of accounts owned by the member
- any other variables/methods necessary to the function of the program

The main class should contain an array of members and variables for any other data it must keep track of

Explanation / Answer

Find the programs and output below.

Member.java

import java.util.List;

public class Member {
   private int id;
   private String userName;
   private String password;
   private String name;
   private List<Account> owned;
   public int getId() {
       return id;
   }
   public void setId(int id) {
       this.id = id;
   }
   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;
   }
   public String getName() {
       return name;
   }
   public void setName(String name) {
       this.name = name;
   }
   public List<Account> getOwned() {
       return owned;
   }
   public void setOwned(List<Account> owned) {
       this.owned = owned;
   }
   @Override
   public String toString() {
       return "Member [id=" + id + ", userName=" + userName + ", password=" + password + ", name=" + name + ", owned="
               + owned + "]";
   }
}

Account.java

package com.chegg.serial;

public class Account {
   private int id;
   private double balance;
   private String type;
   Member member;
   public int getId() {
       return id;
   }
   public void setId(int id) {
       this.id = id;
   }
   public double getBalance() {
       return balance;
   }
   public void setBalance(double balance) {
       this.balance = balance;
   }
   public String getType() {
       return type;
   }
   public void setType(String type) {
       this.type = type;
   }
   public Member getMember() {
       return member;
   }
   public void setMember(Member member) {
       this.member = member;
   }
}

BankSystem.java; Main program

package com.chegg.serial;

import java.util.Scanner;

public class BankSystem {
   static int id=0;
   public static void main(String[] args) {
       // TODO Auto-generated method stub
       int menuchoice, incorrect= 0;
       System.out.println("If you are existing member (Y/N)");
       Scanner s = new Scanner(System.in);
       String ch = s.nextLine();
       Member m = new Member(); //It has to fetch from file.
       m.setName("user");
       m.setPassword("welcome@123");
       Account a = new Account();
       a.setMember(m);
       if(ch.equalsIgnoreCase("Y")){
           System.out.println("Enter your username");
           String un = s.nextLine();
           System.out.println("Enter your password");
           String pw= s.nextLine();
           if(un.equals(m.getUserName()) && pw.equals(m.getPassword())){
               System.out.println("1. View Your list of Account details 2. Make a deposit 3. Make a withdrawl 4. Open a new account 5.close an existing account 6.logout ");
               menuchoice = s.nextInt();
               switch(menuchoice){
               case 1 : accountDets(m);
                       break;
               case 2 : deposit(a);
                       break;
               case 3 : withdraw(a);
                      break;
               case 4 : newaccount(a);
                      break;
               case 5 : closeaccount(a);
                      break;
       case 6 : logout();
                      break;
               default : System.out.println("Incorrect option");
                         
               }
           }else{
               incorrect++;
               if(incorrect == 3){
                   System.exit(0); //To stop the executions
               }
           }
          
       }else if(ch.equalsIgnoreCase("N")){
           System.out.println("Enter your name");
           m.setId(id);
           m.setName(s.nextLine());
           System.out.println("Enter your Username");
           m.setUserName(s.nextLine());
           System.out.println("Enter your Password");
           m.setPassword(s.nextLine());
           System.out.println("Your account is created");
       }
   }

   private static void logout() {
       System.out.println("Logged out");
       System.exit(0);
      
   }

   private static void closeaccount(Account a) {
       System.out.println("Enter the change account number");
       Scanner s = new Scanner(System.in);
       a.setId(s.nextInt());
   }

   private static void withdraw(Account a) {
       System.out.println("Enter the withdraw amount");
       Scanner s = new Scanner(System.in);
       if(a.getBalance() > s.nextFloat()){
           a.setBalance(a.getBalance() - s.nextFloat());  
           System.out.println("Amount is Credited");
       }
   }

   private static void newaccount(Account a) {
       a.setId(id++);
       System.out.println("Account is created");
   }

   private static void deposit(Account a) {
       System.out.println("Enter the deposit amount");
       Scanner s = new Scanner(System.in);
       a.setBalance(a.getBalance() + s.nextFloat());
   }

   private static void accountDets(Member m) {
       m.getOwned();
       m.toString();
      
   }

}

OUTPUT:

If you are existing member (Y/N)
n
Enter your name
bags
Enter your Username
bb
Enter your Password
abc12
Your account is created