🌙 DARK

Write a Java program to display the Account details using inheritance class and methods.

 

Account Details 
 

Write a Java program to display the Account details using inheritance class and methods.

[Note:  Strictly adhere to the object-oriented specifications given as a part of the problem statement.
Follow the naming conventions as mentioned. Create separate classes in separate files.]

 

Consider a class Account with the following private attributes/variables.

Data TypeVariable
StringholderName
LongaccountNumber
StringIFSCCode
LongcontactNumber

Include appropriate getters and setters, constructors for the class.

Prototype for the Parameterized Constructor,
public Account(String holderName, Long accountNumber, String IFSCCode, Long contactNumber)



The class Account should have the following method

Method Name & Description 

public void display()

This method displays account details in the following order holderName, accountNumber, IFSCCode and contactNumber
 

Consider class SavingsAccount which extends Account class with the following private attributes/variables.

Data TypeVariable
DoubleinterestRate

 

The SavingsAccount class include the following method

Method Name & Description 

public void display()

Invokes the base class display() and in addition displays interestRate


Include appropriate getters and setters, constructors for the class.

Prototype for the Parameterized Constructor,
public SavingAccount(String holderName, Long accountNumber, String IFSCCode, Long contactNumber, Double interestRate)
Use super Keyword to call the base class constructor.

Consider class CurrentAccount which extends Account class with the following private attributes/variables.

Data TypeVariable
StringorganizationName
LongTIN


The CurrentAccount class include the following method

Method Name & Description 

public void display()

Invokes base class display() and in addition displays organizationName,TIN

Include appropriate getters and setters, constructors for the class.

Prototype for the Parameterized Constructor,
public CurrentAccount(String holderName, Long accountNumber, String IFSCCode, Long contactNumber, String organizationName, Long TIN)

Note: Use super Keyword to call the base class constructor.

Consider a Main class with the main() method, get user details in comma separated format in the following order (Holder name, Account Number, IFSC code, Contact Number).
Display the Account Details by calling a method of the base class with a child class object.

The link to download the template code is given below
Code Template


Input and Output Format


Refer sample input and output for formatting specifications.

All the double values should be displayed up to 2 decimal places.

All text in bold corresponds to the input and the rest corresponds to output.

Sample Input and Output 1:

 

Enter User Details(HolderName,Account Number,IFSC code,Contact Number)
John,982714210,S160030600514,9092304676
Enter Account Type
savings
Enter Interest Rate
12.0
Your Contact Details
HolderName : John
Account Number : 982714210
IFSCCode : S160030600514
ContactNumber : 9092304676
Interest Rate : 12.00


Sample Input and Output 2:

Enter User Details(HolderName,Account Number,IFSC code,Contact Number)
Jack,7889142075,S1600ABY0576,9944001700
Enter Account Type
current
Enter organization Name
pentamedia Graphics Limited
Enter TIN number
7841
Your Contact Details
HolderName : Jack
Account Number : 7889142075
IFSCCode : S1600ABY0576
ContactNumber : 9944001700
Organization Name : pentamedia Graphics Limited
TIN : 7841


Sample Input and Output 3:

Enter User Details(HolderName,Account Number,IFSC code,Contact Number)
Mitchell,987451024,SWQ78914AF,9078425168
Enter Account Type
curr
Enter valid Account Type


@MRProgrammer89 


CREATE CLASS < Account :


class Account{
public String holderName,IFSCCode;
public long contactNumber,accountNumber;
public Account(String holderName, Long accountNumber, String IFSCCode, Long contactNumber) {
this.accountNumber = accountNumber;
this.holderName = holderName;
this.IFSCCode = IFSCCode;
this.contactNumber = contactNumber;
}

public String getHolderName() {
return holderName;
}

public void setHolderName(String holderName) {
this.holderName = holderName;
}

public String getIFSCCode() {
return IFSCCode;
}

public void setIFSCCode(String iFSCCode) {
IFSCCode = iFSCCode;
}

public long getContactNumber() {
return contactNumber;
}

public void setContactNumber(long contactNumber) {
this.contactNumber = contactNumber;
}

public long getAccountNumber() {
return accountNumber;
}

public void setAccountNumber(long accountNumber) {
this.accountNumber = accountNumber;
}
public void display() {
System.out.println("Your Contact Details");
System.out.println("HolderName : "+getHolderName());
System.out.println("Account Number : "+getAccountNumber());
System.out.println("IFSCCode : "+getIFSCCode());
System.out.println("ContactNumber : "+getContactNumber());
 
}


}


@MRProgrammer89 


CREATE CLASS < CurrentAccount >


public class CurrentAccount extends Account {
private String organizationName;
private long TIN;

public CurrentAccount(String holderName, Long accountNumber, String IFSCCode, Long contactNumber, String organizationName, Long TIN) {
super(holderName, accountNumber, IFSCCode, contactNumber);
this.organizationName = organizationName;
this.TIN = TIN;
}

public String getOrganizationName() {
return organizationName;
}

public void setOrganizationName(String organizationName) {
this.organizationName = organizationName;
}

public long getTIN() {
return TIN;
}

public void setTIN(long tIN) {
TIN = tIN;
}
public void display() {
super.display();
System.out.println("Organization Name : "+getOrganizationName());
System.out.println("TIN : "+getTIN());
 
}
}


@MRProgrammer89 


CREATE CLASS < SavingAccount :

import java.text.DecimalFormat;
class SavingsAccount extends Account{
private double interestRate;
    DecimalFormat df = new DecimalFormat("0.00");
public SavingsAccount(String holderName, Long accountNumber, String IFSCCode, Long contactNumber, Double interestRate) {
super(holderName, accountNumber, IFSCCode, contactNumber);
this.interestRate = interestRate;
}

public double getInterestRate() {
return interestRate;
}

public void setInterestRate(double interestRate) {
this.interestRate = interestRate;
}
public void display() {
super.display();
System.out.println("Interest Rate : "+(df.format(getInterestRate())));
 
}
}

@MRProgrammer89 


CREATE CLASS < Main :

import java.io.*;
import java.util.Scanner;
public class Main 
    public static void main(String[] args)
    { 
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter User Details(HolderName,Account Number,IFSC code,Contact Number)");        
        String details=sc.nextLine();
        String[] str=details.split(",");
        Long accNo=Long.parseLong(str[1]);
        Long conNum=Long.parseLong(str[3]);
        System.out.println("Enter Account Type");
        String type=sc.nextLine();
        if(type.equals("savings"))
        {
            System.out.println("Enter Interest Rate");
            Double i=sc.nextDouble();
            Account sa = new SavingsAccount(str[0],accNo,str[2],conNum,i);
            sa.display();
        }
        else if(type.equals("current"))
        {
            System.out.println("Enter organization Name");
            String org=sc.nextLine();
            System.out.println("Enter TIN number");
            Long tin=sc.nextLong();
            Account ca = new CurrentAccount(str[0],accNo,str[2],conNum,org,tin);
            ca.display();
        }
        else
        {
            System.out.println("Enter valid Account Type");
        }
    } 
}



@MRProgrammer89 






MOTIVATION :


    “The way we spend our time defines who we are 


Although we may not see each other as often as we’d like, distance is no match for the bond that we share. Thank you for coming to visit. It was fantastic to catch up.


VISITE MORE BLOGS




THANK YOU....😊

Post a Comment

Thanks for reading the blog. We hope it was useful to you and that you learned something new. Will always be writing on new and interesting topics, so you can visit our website to know the latest updates of our blogs. Thank You!

Previous Post Next Post

Contact Form