Interface practice 1

 Account.java:

import java.util.*;

class Account {
	//fill the code
	private String name;
	private String accountNumber;	
	private Double balance;
	private	Date startDate;
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getAccountNumber() {
		return accountNumber;
	}
	public void setAccountNumber(String accountNumber) {
		this.accountNumber = accountNumber;
	}
	public Double getBalance() {
		return balance;
	}
	public void setBalance(Double balance) {
		this.balance = balance;
	}
	public Date getStartDate() {
		return startDate;
	}
	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}
	public Account(String name, String accountNumber, Double balance, Date startDate) {
		super();
		this.name = name;
		this.accountNumber = accountNumber;
		this.balance = balance;
		this.startDate = startDate;
	}
	
}



CurrentAccount.java:

public class CurrentAccount implements MaintnanceCharge{

    public float calculateMaintanceCharge(float noOfYears) {
        return 100*noOfYears+200;
    }

	@Override
	public Float calculateMaintancecharge(Float noOfYears) {
		// TODO Auto-generated method stub
		return null;
	}
}



Main.java:

import java.util.*;
import java.io.*;
import java.text.*;

public class Main {
    public static void main(String args[]) throws Exception{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("1.Current Account");
        System.out.println("2.Savings Account");
        Integer n = Integer.parseInt(br.readLine());
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        switch (n) {
        case 1:
            System.out.println("Name");
            String name = br.readLine();
            System.out.println("Account Number");
            String account = br.readLine();
            System.out.println("Account Balance");
            Double accountBalance = Double.parseDouble(br.readLine());
            System.out.println("Enter the Start Date(yyyy-mm-dd)");
            String sdate = br.readLine();
            System.out.println("Enter the Years");
            Float years = Float.parseFloat(br.readLine());
            Account accountObject = new Account(name, account, accountBalance, formatter.parse(sdate));
            CurrentAccount currentAccountObject = new CurrentAccount();
            Float outputValue =currentAccountObject.calculateMaintanceCharge(years);
            System.out.printf("Maintenance Charge For Current Account %.2f",outputValue);
            break;
        case 2:
            System.out.println("Name");
            String name_1 = br.readLine();
            System.out.println("Account Number");
            String account_1 = br.readLine();
            System.out.println("Account Balance");
            Double accountBalance_1 = Double.parseDouble(br.readLine());
            System.out.println("Enter the Start Date(yyyy-mm-dd)");
            String sdate_1 = br.readLine();
            System.out.println("Enter the Years");
            Float years_1 = Float.parseFloat(br.readLine());
            Account accountObject_1 = new Account(name_1, account_1, accountBalance_1, formatter.parse(sdate_1));
            SavingsAccount savingsAccountObject = new SavingsAccount();
            Float outputValue_1 = savingsAccountObject.calculateMaintanceCharge(years_1);
            System.out.printf("Maintenance Charge For Savings Account %.2f",outputValue_1);
            break;
        default:
            System.out.println("Invalid choice");
            break;
        }
    }
    
}



MaintnanceCharge.java:

public interface MaintnanceCharge {
	//create interface
	Float calculateMaintancecharge(Float noOfYears);
}


SavingsAccount.java:

public class SavingsAccount implements MaintnanceCharge{

    public float calculateMaintanceCharge(float noOfYears) {
        return 2*50*noOfYears+50;
    }

	@Override
	public Float calculateMaintancecharge(Float noOfYears) {
		// TODO Auto-generated method stub
		return null;
	}
}


Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.