inherittance

inherittance

Develop a class Borrower which has 5 important fileds, namely borrowerId, borrowerName, borrowerLastName, contactNumber and dateOfBirth. Your class must demonstrate good encapsulation where all fileds get manipulated through get and set methods. Save your file as Borrower.java

Sample input

The borrower class is instantiated four times using the following sample data:

borrowerId[10420040, 10420041, 10420042, 10420043]

borrowerName[David, Mike, Steve, Finsen]

borrowerLastName[Desalt, Smith, Sugars, Lions]

contactNumber[7820001, 1209111,8912100,79910211]

dateOfBirth[1990-11-01, 1981-12-12, 1991-22-03, 1980-10-02]

The program should allow the system administrator to search for a certain borrower in the class by inputing the borrower's ID in the input screen & return the search results on a message dialog box.

View Answers

August 18, 2011 at 4:36 PM

import java.util.Scanner;
import java.util.ArrayList;
class Borrower{
    int borrowerId;
    String borrowerName;
    String borrowerLastName;
    long contactNumber;
    String dateOfBirth;

    Borrower(int borrowerId,String borrowerName,String borrowerLastName,long contactNumber,String dateOfBirth){
    this.borrowerId= borrowerId;
    this.borrowerName=borrowerName;
    this.borrowerLastName=borrowerLastName;
    this.contactNumber=contactNumber;
    this.dateOfBirth=dateOfBirth;
    }
    public int getBorrowerId(){
        return borrowerId;
    }
    public String getBorrowerName(){
        return borrowerName;
    }
    public String getBorrowerLastName(){
        return borrowerLastName;
    }
    public long getContactNumber(){
        return contactNumber;
    }
    public String getDateOfBirth(){
        return dateOfBirth;
    }


    public static void main(String[] args){
        Scanner input=new Scanner(System.in);
    ArrayList<Borrower> list=new ArrayList<Borrower>();
    Borrower b1=new Borrower(10420040,"David","Desalt",7820001,"1990-11-01");
    Borrower b2=new Borrower(10420041,"Mike","Smith",1209111,"1981-12-12");
    Borrower b3=new Borrower(10420042,"Steve","Sugars",8912100,"1991-22-03");
    Borrower b4=new Borrower(10420043,"Finsen","Lions",79910211,"1980-10-02");
    list.add(b1);
    list.add(b2);
    list.add(b3);
    list.add(b4);
System.out.println(" ");
System.out.print("Enter Id to search: ");
int id = input.nextInt();
System.out.println();
for(Borrower b : list){
if(id == b.getBorrowerId())
{
System.out.print("Name is: "+b.getBorrowerName()+"\nLast Name is: "+b.getBorrowerLastName()+"\nContact No is: " +b.getContactNumber()+"\nDate of Birth is: "+b.getDateOfBirth());
}
}
}
}









Related Tutorials/Questions & Answers:
inherittance

Ads