Question

In: Computer Science

It is required to develop an application in Java to perform some operations of a bank....

It is required to develop an application in Java to perform some operations of a bank. The application will have the following classes:

  1. Class called Person having following data fields (private):

firstName (String), lastName(String), gender(char), cpr(long), mobile(String) and following methods:

  1. Constructor having 5 parameters to initialize all data fields,
  2. Set and get methods for all data fields,
  3. toString method to return String equivalent of all data fields,

  1. Abstract class called Account having following data fields(protected):

accountHolder(Person), ccountNum(long), balance(double)and following methods:

  1. Constructor having 3 parameters for all 3 data fields including an object of type Person.
  2. Get methods for all three data fields.
  3. Abstract method updateBalance to update balance according to parameter.
  4. Abstract method withdraw to withdraw money from the account and update balance.
  5. Abstract method deposit to deposit money in the account and update balance.
  6. method to return String equivalent of all data fields by calling toString method of class Person.

  1. Class called Savingsccount that inherit the properties of abstract class Account having following additional data field:

interestRate(double) and following methods:

  1. Constructor having 4 parameters for all data fields including that of class Account.
  2. Set and get methods for interestRate.
  3. Implementation of method updateBalance.
  4. Implementation of method withdraw.
  5. Implementation of method deposit.
  6. Overloaded toString method to return String equivalent of all data fields.
  1. Write a class called Bank having only main method to test all functionalities of the application.

Solutions

Expert Solution

The above mentioned classes are implemented as below:

//Person.java

public class Person {
        
          private String firstName;
          private String lastName;
          private char gender;
          private long cpr;
          private String mobile;
          
        public Person(String firstName,String lastName,char gender,long cpr,String mobile){
                 this.firstName=firstName;
                 this.lastName=lastName;
                 this.gender=gender;
                 this.cpr=cpr;
                 this.mobile=mobile;
        }

        public String getFirstName() {
                return firstName;
        }

        public void setFirstName(String firstName) {
                this.firstName = firstName;
        }

        public String getLastName() {
                return lastName;
        }

        public void setLastName(String lastName) {
                this.lastName = lastName;
        }

        public char getGender() {
                return gender;
        }

        public void setGender(char gender) {
                this.gender = gender;
        }

        public long getCpr() {
                return cpr;
        }

        public void setCpr(long cpr) {
                this.cpr = cpr;
        }

        public String getMobile() {
                return mobile;
        }

        public void setMobile(String mobile) {
                this.mobile = mobile;
        }
        
        public String toString(){
                return firstName+" "+lastName+" "+gender+" "+cpr+" "+mobile;
        }
          
          

}
//Account.java


public abstract class Account {
        
        protected Person accountHolder;
        protected long accountNum;
        protected double balance;
        
        public Account(Person accountHolder, long accountNum, double balance) {
                super();
                this.accountHolder = accountHolder;
                this.accountNum = accountNum;
                this.balance = balance;
        }

        public Person getAccountHolder() {
                return accountHolder;
        }

        public long getAccountNum() {
                return accountNum;
        }

        public double getBalance() {
                return balance;
        }
        
        
        abstract void updateBalance(double amount);
        abstract void withDraw(double amount);
        abstract void deposit(double amount);
        
        public String toString(){
                return accountHolder.toString()+" "+ accountNum+" "+balance;
        }

}
//SavingsAccount.java


public class SavingsAccount extends Account {
        
        double interestRate;

        public SavingsAccount(Person accountHolder, long accountNum, double balance, double interestRate) {
                super(accountHolder, accountNum, balance);
                this.interestRate=interestRate;
        }

        public double getInterestRate() {
                return interestRate;
        }

        public void setInterestRate(double interestRate) {
                this.interestRate = interestRate;
        }

        @Override
        void updateBalance(double amount) {
                this.balance=amount;
                
        }

        @Override
        void withDraw(double amount) {
        if(amount>this.balance){
                System.out.println("You don't have sufficicent balance to Withdraw");
        }else{
                updateBalance(this.balance-amount);
        }
                
        }

        @Override
        void deposit(double amount) {
                updateBalance(this.balance+amount);             
        }
        
        public String toString(){
                return accountHolder.getFirstName()+" "+accountHolder.getLastName() + " with Account number "+accountNum+" has current balance "+balance+" with interest rate of "+interestRate;
        }
        
        
}       
        
//Bank.java

public class Bank {
         public static void main(String[] args){
                 Person p1 = new Person("Sam", "Roy", 'F', 15, "978901789");
                 SavingsAccount s1 = new SavingsAccount(p1, 1148027110, 89900, 8);
                 System.out.println("Before Withdraw");
                 System.out.println(s1.toString());
                 s1.withDraw(19800);
                 System.out.println("After Withdraw and Before Deposit");
                 System.out.println(s1.toString());
                 s1.deposit(10700);
                 System.out.println("After Deposit");
                 System.out.println(s1.toString());
         }
}

The ouput screenshot for the above program is as below:

If you have any queries regarding this answer, please reach out through the comment section.


Related Solutions

Programming language= In Java and Oracle Sql You are required to develop a simple HR application...
Programming language= In Java and Oracle Sql You are required to develop a simple HR application for a small accounting firm that wishes to keep track of all the employees at the firm; storing details about their salary, phone numbers and Date of Birth. The firm has many departments and there are 5 to 20 employees in each department. The department information includes department name, description and total number of employees in that department. The company also provides vehicles for...
In Java Develop, test, and execute a graphics application for simulations using Java. Create a Java...
In Java Develop, test, and execute a graphics application for simulations using Java. Create a Java application. Given a set of events, choose the resulting programming actions. Understand the principles behind Java. Understand the basic principles of object-oriented programming including classes and inheritance. Deliverables .java files as requested below. Requirements Create all the panels. Create the navigation between them. Start navigation via the intro screen. The user makes a confirmation to enter the main panel. The user goes to the...
how to creat a bank system application for Java?
how to creat a bank system application for Java?
Develop a Java application which implements an application for a store chain that has three types...
Develop a Java application which implements an application for a store chain that has three types of stores which are Book, Music, and Movie stores. Your application should have an Item abstract class which should be extended by the Book and Multimedia classes. Item class has abstract priceAfterTax method, you need to implement this method in derived classes. Multimedia class is a superclass for Music and Movie classes. Your project should also include the IPromotion interface, which should be implemented...
You will write a Java Application program to perform the task of generating a calendar for...
You will write a Java Application program to perform the task of generating a calendar for the year 2020. You are required to modularize your code, i.e. break your code into different modules for different tasks in the calendar and use method calls to execute the different modules in your program. Your required to use arrays, ArrayList, methods, classes, inheritance, control structures like "if else", switch, compound expressions, etc. where applicable in your program. Your program should be interactive and...
Develop a Java application that determines the gross pay for each of three employees.
(Salary Calculator) Develop a Java application that determines the gross pay for each of three employees. The company pays straight time for the first 40 hours worked by each employee and time and a half for all hours worked in excess of 40. You’re given a list of the employees, their number of hours worked last week and their hourly rates. Your program should input this information for each employee, then determine and display the employee’s gross pay. Use class...
Develop a Java application to simulate a game played in an elementary classroom. In this game,...
Develop a Java application to simulate a game played in an elementary classroom. In this game, the teacher places herself in the center of a circle of students surrounding her. She then distributes an even number of pieces of candy to each student. Not all students will necessarily receive the same number of pieces; however, the number of pieces of candy for each student is even and positive. When the teacher blows a whistle, each student takes half of his...
Develop a Java application that plays a "guess the number" game as described below. a) The...
Develop a Java application that plays a "guess the number" game as described below. a) The user interface is displayed and the user clicks the “Start Game” button to begin the game. b) Your application then gets a random number in the range 1-1000 inclusive (you might want to use Math.random or the Random class). c) The application then displays the following prompt (probably via a JLabel): I have a number between 1 and 1000 can you guess my number?...
NEED IN JAVA Problem statement. This application will support the operations of a technical library for...
NEED IN JAVA Problem statement. This application will support the operations of a technical library for an R&D organization. This includes the searching for and lending of technical library materials, including books, videos, and technical journals. Users will enter their company ids in order to use the system; and they will enter material ID numbers when checking out and returning items.   Each borrower can be lent up to five items. Each type of library item can be lent for a...
Develop a Java application using Parboiled library to write aparser for a customer form. Your...
Develop a Java application using Parboiled library to write a parser for a customer form. Your program should include a grammar for the parser and display the parse tree with no errors.The customer form should include the following structure:First name, middle name (optional), last nameStreet address, city, state (or province), countryPhone numberRules• First name, middle name and last name should start with an uppercase letter followed by lower case letters. Middle name is an optional input meaning such an input...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT