Interface

INTERFACE PRACTICAL PROBLEM 1

Sample Input and Output 1:

Welcome to Notification Setup
Please select your bank:
1)ICICI
2)HDFC
1
Enter the type of Notification you want to enter
1)SMS
2)Mail
3)Courier
1
ICICI - Notification By SMS


Sample Input and Output 2:

Welcome to Notification Setup
Please select your bank:
1)ICICI
2)HDFC
2
Enter the type of Notification you want to enter
1)SMS
2)Mail
3)Courier
4
Invalid Input


Sample Input and Output 3:

Welcome to Notification Setup
Please select your bank:
1)ICICI
2)HDFC
4
Invalid Input

CODE:

public class BankFactory {
    
public ICICI getIcici() {
return new ICICI();
}
public HDFC getHdfc() {
return new HDFC();
}

}

interface Notification{

    void notificationBySms();
void notificationByEmail();
void notificationByCourier();
}

public class HDFC implements Notification{

    public void notificationBySms() {
System.out.println("HDFC - Notification By SMS");
}

public void notificationByEmail() {
System.out.println("HDFC - Notification By Mail");
}

public void notificationByCourier() {
System.out.println("HDFC - Notification By Courier");
}

     // Fill your code

}

public class ICICI implements Notification{

    public void notificationBySms() {
System.out.println("ICICI - Notification By SMS");
}

public void notificationByEmail() {
System.out.println("ICICI - Notification By Mail");
}

public void notificationByCourier() {
System.out.println("ICICI - Notification By Courier");
}

    

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {

    public static void main(String[] args) throws IOException {
    BankFactory bankFactory = new BankFactory();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
ICICI icici;
HDFC hdfc;
System.out.println("Welcome to Notification Setup\nPlease select your bank:\n1)ICICI\n2)HDFC");
int select = Integer.parseInt(br.readLine());
if(select == 1){
icici = bankFactory.getIcici();
System.out.println("Enter the type of Notification you want to enter\n1)SMS\n2)Mail\n3)Courier");
int notificationChoice = Integer.parseInt(br.readLine());
if(notificationChoice == 1){
icici.notificationBySms();
} else if (notificationChoice == 2){
icici.notificationByEmail();
}else if(notificationChoice == 3) {
icici.notificationByCourier();
} else {
System.out.println("Invalid Input");
}
} else if(select ==2) {
hdfc = bankFactory.getHdfc();
System.out.println("Enter the type of Notification you want to enter\n1)SMS\n2)Mail\n3)Courier");
int notificationChoice = Integer.parseInt(br.readLine());
if(notificationChoice == 1){
hdfc.notificationBySms();
} else if (notificationChoice == 2){
hdfc.notificationByEmail();
}else if(notificationChoice == 3) {
hdfc.notificationByCourier();
} else {
System.out.println("Invalid Input");
}
} else {
System.out.println("Invalid Input");
}
}
}



Comments

Popular posts from this blog