Search This Blog

Sunday, 21 August 2022

B2. Declare an interface containing methods float addition(float x, float y) and float subtraction(float x, float y). Declare the classes implementing the interface to perform respective operations

/*B2. (2019Syllabus) Declare an interface containing methods float addition(float x, float y) and float subtraction(float x, float y). Declare the classes implementing the interface to perform respective operations as listed below.
Bank - to carryout deposit and withdrawal operations. In addition to the implementation for the abstract methods, the class should contain additional methods to read and display customer information to perform the respective transaction.
EmployeeSalary - to calculate the gross and net salary. In addition to the implementation for the abstract methods, the class should contain additional methods to read and display employee information, allowance amount and deduction amount to perform the respective transaction.
Main class - which instantiates above two classes and calls respective methods.*/

import java.io.*;
interface myInterface
{
    float addition(float x, float y);
    float subtraction(float x, float y);
}
class Bank implements myInterface
{
    static float balance=0;
    float deposit, withdraw;
    float add,sub;
    String cname;
    DataInputStream in=new DataInputStream(System.in);
    public float addition(float x, float y)
    {
        balance=x+y;
        return balance;
        
    }
    public float subtraction(float x, float y)
    {
        balance = x-y;
        return balance;
    }
    public void read()throws IOException
    {
        
        System.out.println("Enter the name of customer:");
        cname=in.readLine();
        System.out.println("Enter the amount to deposit:");
        add=Float.parseFloat(in.readLine());
        System.out.println("Enter the amount to withdraw:");
        sub=Float.parseFloat(in.readLine());
        deposit=addition(balance, add);
        //System.out.println("Balance1="+add);
        withdraw=subtraction(balance, sub);
        //System.out.println("Balance2="+sub);
    }
    public void display()
    {        
        System.out.println("Details of Customer:");
        System.out.println("Name="+cname+"\nDeposit="+add+"\nWithdraw="+sub+
            "\nBalance="+balance);
                
    }
}
class EmployeeSalary
{
    static float net_sal=0;
    float add,sub;
    float basic_sal=30000;
    float allowance,deduction;
    float gross_sal;
    String ename;
        DataInputStream in=new DataInputStream(System.in);
    float addition(float x, float y)
    {
        gross_sal=x+y;
        return gross_sal;
    }
    float subtraction(float x, float y)
    {
        net_sal=x-y;
        return net_sal;
    }

    public void read()throws IOException
    {
        System.out.println("Enter the name of employee:");
        ename=in.readLine();
        System.out.println("Enter the allowance amount:");
        add=Float.parseFloat(in.readLine());
        System.out.println("Enter the deduction amount:");
        sub=Float.parseFloat(in.readLine());
        gross_sal=addition(basic_sal, add);
        //System.out.println("Balance1="+add);
        net_sal=subtraction(gross_sal, sub);
        //System.out.println("Balance2="+sub);
    }
    public void display()
    {        
        System.out.println("Details of Customer:");
        System.out.println("Name="+ename+"\nAllowance="+add+"\nDeduction="+sub+
            "\nGrossSalary="+gross_sal+"\nNetSalary="+net_sal);
    }  }
class B2
{
    public static void main(String args[])throws IOException
    {
        Bank b1=new Bank();
        EmployeeSalary e1=new EmployeeSalary();
        b1.read();
        b1.display();
        e1.read();
        e1.display();
    }
}

No comments :

Post a Comment

FREE Hit Counters