1. //main.java import java.io.*; import java.text.*; import java.util.*; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("1.Current Account\n2.Savings Account"); int choice = scanner.nextInt(); scanner.nextLine(); // consume newline System.out.println("Name"); String name = scanner.nextLine(); System.out.println("Account Number"); int number = scanner.nextInt(); System.out.println("Account Balance"); int balance = scanner.nextInt(); scanner.nextLine(); // consume newline System.out.println("Enter the Start Date(yyyy-mm-dd)"); String startDateStr = scanner.nextLine(); System.out.println("Enter the Due Date(yyyy-mm-dd)"); String dueDateStr = scanner.nextLine(); Date startDate = parseDate(startDateStr); Date dueDate = parseDate(dueDateStr); Account account; if (choice == 1) { account = new CurrentAccount(name, number, balance, startDate); } else { account = new SavingsAccount(name, number, balance, startDate); } double interest = account.calculateInterest(dueDate); String accountType = (choice == 1) ? "Current" : "Savings"; System.out.printf("%s Account Interest %.2f%n", accountType, interest); } private static int monthsDifference(Date startDate, Date endDate) { Calendar c1 = new GregorianCalendar(); c1.setTime(startDate); Calendar c2 = new GregorianCalendar(); c2.setTime(endDate); int ans = (c2.get(Calendar.YEAR) - c1.get(Calendar.YEAR)) * 12; ans += c2.get(Calendar.MONTH) - c1.get(Calendar.MONTH); return ans; } private static Date parseDate(String dateString) { try { return new SimpleDateFormat("yyyy-MM-dd").parse(dateString); } catch (ParseException e) { e.printStackTrace(); return null; } } } //accout.java import java.util.* ; public abstract class Account { String name; int number; int balance; Date startDate; Account(String name, int number, int balance, Date startDate) { this.name = name; this.number = number; this.balance = balance; this.startDate = startDate; } abstract double calculateInterest(Date dueDate); protected static int monthsDifference(Date startDate, Date endDate) { Calendar c1 = new GregorianCalendar(); c1.setTime(startDate); Calendar c2 = new GregorianCalendar(); c2.setTime(endDate); int ans = (c2.get(Calendar.YEAR) - c1.get(Calendar.YEAR)) * 12; ans += c2.get(Calendar.MONTH) - c1.get(Calendar.MONTH); return ans; } } //currentaccount.java import java.util.*; public class CurrentAccount extends Account { CurrentAccount(String name, int number, int balance, Date startDate) { super(name, number, balance, startDate); } double calculateInterest(Date dueDate) { int months = monthsDifference(startDate, dueDate); double rate = 5.0 / 12 / 100; return balance * rate * months; } } //savingsaccount.java import java.util.*; public class SavingsAccount extends Account { SavingsAccount(String name, int number, int balance, Date startDate) { super(name, number, balance, startDate); } double calculateInterest(Date dueDate) { int months = monthsDifference(startDate, dueDate); double rate = 12.0 / 12 / 100; return balance * rate * months; } } 2.. //icici.java class Icici implements Notification { //Fill your code here 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"); } } //bankfactory.java class BankFactory { //Fill your code here public Icici getIcici() { return new Icici(); } public Hdfc getHdfc() { return new Hdfc(); } } //notification.java interface Notification { //Fill your code here void notificationBySms(); void notificationByEmail(); void notificationByCourier(); } //main.java import java.util.*; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("Welcome to Notification Setup"); System.out.println("Please select your bank:"); System.out.println("1) ICICI"); System.out.println("2) HDFC"); int bankChoice = scanner.nextInt(); if (bankChoice == 1 || bankChoice == 2) { System.out.println("Enter the type of Notification you want to enter"); System.out.println("1) SMS"); System.out.println("2) Mail"); System.out.println("3) Courier"); int notificationChoice = scanner.nextInt(); BankFactory bankFactory = new BankFactory(); if (bankChoice == 1) { Icici icici = bankFactory.getIcici(); switch (notificationChoice) { case 1: icici.notificationBySms(); break; case 2: icici.notificationByEmail(); break; case 3: icici.notificationByCourier(); break; default: System.out.println("Invalid Input"); } } else { Hdfc hdfc = bankFactory.getHdfc(); switch (notificationChoice) { case 1: hdfc.notificationBySms(); break; case 2: hdfc.notificationByEmail(); break; case 3: hdfc.notificationByCourier(); break; default: System.out.println("Invalid Input"); } } } else { System.out.println("Invalid Input"); } } } //hdfc.java class Hdfc implements Notification { //Fill your code here 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"); } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter