Java Interfaces: Attribute Datatype
Java Interfaces: Attribute Datatype
Write a program to calculate maintenance charges based on the type of account and
display the same using Interfaces.
1.Current Account
2.Savings Account
1
Name
SB
Account Number
12345
Account Balance
5000
Enter the Start Date(yyyy-mm-dd)
2013-04-22
Enter the Years
4
Maintenance Charge For Current Account 600.00
1.Current Account
2.Savings Account
2
Name
SB
Account Number
54321
Account Balance
3000
Enter the Start Date(yyyy-mm-dd)
2014-04-12
Enter the Years
6
Maintenance Charge For Savings Account 650.00
1.Current Account
2.Savings Account
3
Invalid choice
PROGRAM
Account.java
…………………..
import java.util.*;
import java.text.*;
class Account {
return name;
this.name=name;
}
public String getAccountNumber(){
return accountNumber;
this.accountNumber=accountNumber;
return balance;
this.balance=balance;
return startDate;
this.startDate=startDate;
this.name=name;
this.accountNumber=accountNumber;
this.balance=balance;
this.startDate=startDate;
Cont…………..
Savings account.java
………………………………….
import java.util.*;
import java.text.*;
class SavingsAccount {
return charges;
Cont……………….
Current account.java
……………………………………
import java.util.*;
import java.text.*;
return charges;
Cont………..
maintanceCharge.java
………………………………………
//create interface
interface MaintenanceCharge{
//create interface
Cont……………
Main.java
………………..
import java.util.*;
import java.io.*;
import java.text.*;
System.out.println("2.Savings Account");
Integer n = Integer.parseInt(br.readLine());
switch (n) {
case 1:
System.out.println("Name");
System.out.println("Account Number");
System.out.println("Account Balance");
break;
case 2:
System.out.println("Name");
System.out.println("Account Number");
String account_1 = br.readLine();
System.out.println("Account Balance");
break;
default:
System.out.println("Invalid choice");
break;
…………………………………………………………………………………………………………………………………………………………………
Interface
Write a program to display different types of Stalls by implementing interface.
Strictly adhere to the Object-Oriented specifications given in the problem statement. All class
names, attribute names, and method names should be the same as specified in the problem
statement.
Create an interface Stall with the following method.
Method Name Description
void display() abstract method.
Consider a class GoldStall which implements the Stall interface and define the following
private attributes.
Attribute Datatype
stallName String
cost Integer
ownerName String
tvSet Integer
Consider a class PremiumStall which implements the Stall interface and define the following
private attributes.
Attribute Datatype
stallName String
cost Integer
ownerName String
projector Integer
Input Format:
Output Format:
Print “Invalid Stall Type” if the user has chosen the stall type other than the given type
Otherwise, display the details of the stall.
Refer to sample output for formatting specifications.
Note: All Texts in bold corresponds to the input and the rest are output.
PROGRAM
GoldStall.java
…………………..
return stallName;
this.stallName = stallName;
return cost;
this.cost = cost;
return ownerName;
}
this.ownerName = ownerName;
return tvSet;
this.tvSet = tvSet;
this.stallName = stallName;
this.cost = cost;
this.ownerName = ownerName;
this.tvSet = tvSet;
void display() {
System.out.println("Cost:"+"Rs."+cost);
}
Cont………….
Excutive Stall.java
………………………………
return stallName;
this.stallName = stallName;
return cost;
this.cost = cost;
return ownerName;
return screen;
this.screen = screen;
this.stallName = stallName;
this.cost = cost;
this.ownerName = ownerName;
this.screen = screen;
void display() {
System.out.println("Cost:"+"Rs."+cost);
System.out.println("Owner Name:"+ownerName);
Cont……
primiamStallGold.java
…………………………………
return stallName;
this.stallName = stallName;
return cost;
this.cost = cost;
return ownerName;
this.ownerName = ownerName;
}
return projector;
this.projector = projector;
this.stallName = stallName;
this.cost = cost;
this.ownerName = ownerName;
this.projector = projector;
void display() {
System.out.println("Cost:"+"Rs."+cost);
Cont………..
Stall.java
………….
interface Stall{
void display();
//create interface
Cont…
Main.java
…………………
import java.util.*;
import java.lang.*;
System.out.println("1)Gold Stall");
System.out.println("2)Premium Stall");
System.out.println("3)Executive Stall");
switch(type)
case 1:
System.out.println("Enter Stall details in comma-separated(Stall Name, Stall Cost, Owner
Name, Number of TV sets)");
String st1=br.nextLine();
String[] str1=st1.split(",");
gd.display();
break;
case 2:
String st2=br.nextLine();
String[] str2=st2.split(",");
PremiumStall pm = new
PremiumStall(str2[0],Integer.parseInt(str2[1]),str2[2],Integer.parseInt(str2[3]));
pm.display();
break;
case 3:
String st3=br.nextLine();
String[] str3=st3.split(",");
ExecutiveStall ex = new
ExecutiveStall(str3[0],Integer.parseInt(str3[1]),str3[2],Integer.parseInt(str3[3]));
ex.display();
break;
default:
break;
…………………………………………………………………………………………………………………………………………….........
Write a program to display different types of notifications for the type of bank chosen by
implementing the interface.
public void notificationBySms() This method is used to display the message "ICICI - Notification By SMS"
public void notificationByEmail() This method is used to display the message "ICICI - Notification By Mail"
public void notificationByCourier() This method is used to display the message "ICICI - Notification By Courier"
public void notificationBySms() This method is used to display the message "HDFC - Notification By SMS"
public void notificationByEmail() This method is used to display the message "HDFC - Notification By Mail"
public void notificationByCourier() This method is used to display the message "HDFC - Notification By Courier"
public Icici getIcici( ) This method is used to return the object for ICICI class
public Hdfc getHdfc( ) This method is used to return the object for HDFC class
The first integer corresponds to select the bank, the next integer corresponds to the type of
the notification.
If there is no valid input then display ' Invalid input'.
[Note: All text in bold corresponds to the input and remaining text corresponds to
output]
Problem Requirements:
Java
Keyword Min Count Max Count
interface 1 -
PROGRAM
Icici.java
………………
Cont…..
Hdfc.java
…………….
}
public void notificationByCourier(){
Cont…….
Notification.java
……………………….
interface Notification{
Cont…………..
Main.java
………………
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
ICICI icici;
HDFC hdfc;
if(select == 1){
icici = bankFactory.getIcici();
if(notificationChoice == 1){
icici.notificationBySms();
icici.notificationByEmail();
}else if(notificationChoice == 3) {
icici.notificationByCourier();
} else {
System.out.println("Invalid Input");
hdfc = bankFactory.getHdfc();
System.out.println("Enter the type of Notification you want to
enter\n1)SMS\n2)Mail\n3)Courier");
if(notificationChoice == 1){
hdfc.notificationBySms();
hdfc.notificationByEmail();
}else if(notificationChoice == 3) {
hdfc.notificationByCourier();
} else {
System.out.println("Invalid Input");
} else {
System.out.println("Invalid Input");
……………………………………………………………………………………………………………………………………………………
[Note: Strictly adhere to the object-oriented specifications given as a part of the problem
statement. Use the same class names, attribute names and method names]
Include appropriate getters and setters for the outer class attributes in both the inner classes.
Get the option for the shape to compute the area and get the attribute according to the
shape option and set the values to the Shape class attributes. Calculate the area and print
the area.
Input Format:
Output Format:
PROGRAM
Shape.java
……………….
import java.util.*;
return value1;
Rectangle.value1 = value1;
return value2;
return area;
return value1;
}
public static void setValue1(double value1){
Triangle.value1 = value1;
return value2;
Triangle.value2 = value2;
return totalArea;
Cont………
Main.java
……………….
import java.util.*;
import java.text.*;
int input=sc.nextInt();
double value1,value2;
switch (input)
case 1:
rectangle.setValue1(sc.nextDouble());
rectangle.setValue2(sc.nextDouble());
break;
case 2:
triangle.setValue1(sc.nextDouble());
triangle.setValue2(sc.nextDouble());
break;
default:
System.out.println("Invalid choice");
break;
……………………………………………………………………………………………………………………………………………………….