0% found this document useful (0 votes)
50 views4 pages

Digital Assignment: Banking - Java (Interface)

This document contains code for a Java program that implements various object-oriented programming concepts like classes, objects, constructors, method overloading, inheritance, interfaces, and packages. The code shows an example banking system that uses remote method invocation (RMI) to allow a client program to interact with methods defined in a Banking interface. The BankingRemote class implements the Banking interface and contains the core banking functionality, while the ATMClient acts as the client program that allows users to deposit, withdraw, and check balances by calling methods on the remote Banking object.

Uploaded by

pranay yanamala
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views4 pages

Digital Assignment: Banking - Java (Interface)

This document contains code for a Java program that implements various object-oriented programming concepts like classes, objects, constructors, method overloading, inheritance, interfaces, and packages. The code shows an example banking system that uses remote method invocation (RMI) to allow a client program to interact with methods defined in a Banking interface. The BankingRemote class implements the Banking interface and contains the core banking functionality, while the ATMClient acts as the client program that allows users to deposit, withdraw, and check balances by calling methods on the remote Banking object.

Uploaded by

pranay yanamala
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Digital assignment

Name: pranay.y

Reg no: 18BCE2265

QUESTION:

Write a program(s) in Java that illustrates the following concepts. The concepts can be applied to any
practical scenario such as student administration system or software which maintains various
information about students and provides various services to the users. The other scenarios may
include retail business management software, banking systems, railway reservation system, online
shopping applications, environmental monitoring system etc.

Classes and Objects

Constructors and constructor overloading

Method overloading

Garbage collection and this reference

Inheritance

Interfaces

Packages and sub packages

Code
Banking.java (Interface)
import java.rmi.*;

import java.util.*;

public interface Banking extends Remote{

public int add(int x,int y)throws RemoteException;

public void deposit(int accnt,int amt)throws RemoteException; public void withdraw(int accnt,int
amt)throws RemoteException; public int inquiry(int accnt)throws RemoteException;

BankingRemote.java (Remote class based on interface)

import java.rmi.*; import java.rmi.server.*; import java.util.*;


public class BankingRemote extends UnicastRemoteObject implements
Banking{ Hashtable<Integer,Integer> acbalance = new Hashtable<Integer,Integer>();
BankingRemote()throws RemoteException{

super(); acbalance.put(100, 1000);

public int add(int x,int y)

{return x+y;}

public void deposit(int accnt,int amt) { int temp = acbalance.get(accnt); temp+=amt;


acbalance.put(accnt, temp);

public void withdraw(int accnt,int amt) { int temp = acbalance.get(accnt); temp-=amt;

acbalance.put(accnt, temp);

public int inquiry(int accnt) { return acbalance.get(accnt);}

ATMClient.java (Client Program)

import java.util.*;

import java.util.Scanner; import java.rmi.*;

public class ATMClient{

public static void main(String args[]){ try{

Banking stub=(Banking)Naming.lookup("rmi://localhost:5555/arka"); Scanner in = new


Scanner(System.in);

while(1==1)

System.out.println("Enter Account Number"); int ac = in.nextInt();


System.out.println("Enter 1 : deposit, 2 : withdrawl, 3 : Account balance"); int choice = in.nextInt();

switch (choice) { case 1:

System.out.println("Enter amount to deposit in $"); int amount = in.nextInt();

stub.deposit(ac,amount);

System.out.println("$ "+amount+" has been deposited."); break;

case 2:

System.out.println("Enter amount to withdraw in $"); int amountt = in.nextInt();


stub.withdraw(ac,amountt);

System.out.println("$ "+amountt+" has been withdrawn."); break;

case 3:

System.out.println("Account Balance: $ "+stub.inquiry(ac)); break;

default:

System.out.println("Wrong choice!! Please try again."); break;

System.out.println("Enter 1 to exit or 2 to continue"); int ex = in.nextInt();

if (ex==1) break;

catch(Exception e){}

}
output

You might also like