Adjava

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 44

LAB ON ADVANCED JAVA SRI RAKSHA

3SU21SA135

INDEX

PART-A
SL NO DESCRIPTION PAGE NO
1 Write an applet program in Java to draw a 3-4
face
2 Write an applet program in Java to implement 5-9
a simple calculator
3 Write a Java program to copy a characters 10-11
from one to another
4 Write a Java program for reading and writing 12-13
a Random Access File
5 Write an applet program in Java to accept 14-16
employee number, name and basic as
parameter
6 Write a Java program using swing 17-20
component. Design a frame to accept a book
id, book code, book name and price
7 Write a Java program using swing 21-25
component. Design a frame to generate
electricity bill. Accept the meter number,
customer name, previous meter reading,
current meter reading.

PART-B
1 Write a JDBC program to process a bank 27-29
transaction
2 Write a JDBC program to retrieve the details 30-32
from telephone directory
3 Write a RMI program to convert temperature 33-35
to Fahrenheit and vice versa
4 Write a RMI program to calculate interest on 36-38
a particular amount
5 Write a RMI program to calculate Tax 39-41
depending on a salary
6 Write a RMI program to convert dollar to 42-44
rupees using command line argument

1
LAB ON ADVANCED JAVA SRI RAKSHA
3SU21SA135

PART-A

2
LAB ON ADVANCED JAVA SRI RAKSHA
3SU21SA135

PROGRAM-01
Write an applet program in Java to draw a face.
import java.awt.*;
import java.applet.*;
public class face extends Applet
{
public void paint(Graphics g)
{
setForeground(Color.black);
g.drawOval(40,40,120,150);
g.drawOval(57,75,30,20);
g.drawOval(110,75,30,20);
g.fillOval(68,81,10,10);
g.fillOval(121,81,10,10);
g.drawOval(85,100,30,30);
g.fillArc(60,125,80,40,180,180);
g.drawOval(25,92,15,30);
g.drawOval(160,92,15,30);
}
}

HTML CODE:
<html>
<body>
<applet code=”face.class”
Height=”500”;
Weight=”500”;>
</applet>
</body>
</html>

3
LAB ON ADVANCED JAVA SRI RAKSHA
3SU21SA135

OUTPUT

4
LAB ON ADVANCED JAVA SRI RAKSHA
3SU21SA135

PROGRAM-02
Write an applet program in Java to implement a simple calculator
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.*;
public class calculator extends Applet implements ActionListener
{
int n1,n2;
int res=0;
String str;
TextField txt1;
TextField txt2;
Label l1;
Label l2;
Label l3;
Label l4;
Button plus;
Button sub;
Button mul;
Button div;
public void init()
{
txt1=new TextField();
txt2=new TextField();
l1=new Label("enter 1st number");
l2=new Label("enter 2nd number");
l3=new Label("result");
l4=new Label("");
plus=new Button("ADD");

5
LAB ON ADVANCED JAVA SRI RAKSHA
3SU21SA135

sub=new Button("MINUS");
mul=new Button("PRODUCT");
div=new Button("DIVIDE");
setLayout(null);
add(txt1);
add(txt2);
add(l1);
add(l2);
add(l3);
add(l4);
add(plus);
add(sub);
add(mul);
add(div);
txt1.setBounds (300,20,80,20);
txt2.setBounds(300,50,80,20);
l1.setBounds(100,20,200,25);
l2.setBounds(100,40,200,25);
l3.setBounds(100,150,80,25);
l4.setBounds(200,150,100,25);
plus.setBounds(100,80,40,20);
sub.setBounds(200,80,40,20);
mul.setBounds(300,80,60,20);
div.setBounds(400,80,60,20);
plus.addActionListener(this);
sub.addActionListener(this);
mul.addActionListener(this);
div.addActionListener(this);
repaint();
}

6
LAB ON ADVANCED JAVA SRI RAKSHA
3SU21SA135

public void actionPerformed(ActionEvent d)


{
try
{
n1=Integer.parseInt(txt1.getText());
n2=Integer.parseInt(txt2.getText());
if(d.getSource()==plus)
{
res=n1+n2;
str=Integer.toString(res);
l4.setText(str);
}
if(d.getSource()==sub)
{
res=n1-n2;
str=Integer.toString(res);
l4.setText(str);
}
if(d.getSource()==mul)
{
res=n1*n2;
str=Integer.toString(res);
l4.setText(str);
}
if(d.getSource()==div)
{
try
{
res=n1/n2;
str=Integer.toString(res);

7
LAB ON ADVANCED JAVA SRI RAKSHA
3SU21SA135

l4.setText(str);
}
catch(ArithmeticException e)
{
l4.setText("error:Division by zero");
}
}
}
catch(NumberFormatException e)
{
l4.setText("Invalid number");
}
}
}

HTML CODE:
<html>
<applet code=”calculator.class” width=250 height=200>
</applet>
</html>

OUTPUT

8
LAB ON ADVANCED JAVA SRI RAKSHA
3SU21SA135

9
LAB ON ADVANCED JAVA SRI RAKSHA
3SU21SA135

PROGRAM-03
Write a Java program to copy a characters from one to another
import java.io.*;
class copycharacter
{
public static void main(String args[])
{
File infile=new File("input.txt");
File outfile=new File("output.txt");
FileReader ins=null;
FileWriter outs=null;
try
{
ins=new FileReader(infile);
outs=new FileWriter(outfile);
int ch;
while((ch=ins.read())!=-1)
{
outs.write(ch);
}
}
catch(IOException e)
{
System.out.println(e);
System.exit(-1);
}
finally
{
try
{

10
LAB ON ADVANCED JAVA SRI RAKSHA
3SU21SA135

ins.close();
outs.close();
}
catch(IOException e)
{}
}
}
}
OUTPUT

11
LAB ON ADVANCED JAVA SRI RAKSHA
3SU21SA135

PROGRAM-04
Write a Java program for reading and writing a Random Access File
import java.io.*;
public class Random
{
public static void main(String args[])
{
RandomAccessFile file=null;
try{
file=new RandomAccessFile("rand.txt","rw");
file.writeChar('X');
file.writeInt(555);
file.writeDouble(3.1412);
file.seek(0);
System.out.println(file.readChar());
System.out.println(file.readInt());
System.out.println(file.readDouble());
file.seek(2);
System.out.println(file.readInt());
file.seek(file.length());
file.writeBoolean(false);
file.seek(4);
System.out.println(file.readBoolean());
}
catch(IOException e)
{
System.out.println(e);
}
finally
{

12
LAB ON ADVANCED JAVA SRI RAKSHA
3SU21SA135

try
{
file.close();
}
catch(IOException e)
{}
}
}
}
OUTPUT

13
LAB ON ADVANCED JAVA SRI RAKSHA
3SU21SA135

PROGRAM-05
Write an applet program in Java to accept employee number, name and basic as
parameter. Find the gross and net salary depending on the following conditions:
If basic>20000 then DA-50% , HRA-15%, PF-12%, PT-200
If basic<=20000 then DA-40% , HRA-10%, PF-12%, PT-100
Gross=basic+da+hra
Net=gross-(PT+PF)
import java.awt.*;
import java.applet.*;
public class employee extends Applet
{
String ename;
int ecode;
double basic;
double net;
double gross;
double da,hra,pt,pf;
public void init()
{
ename=getParameter("Param 1");
ecode=Integer.parseInt(getParameter("Param 2"));
basic=Double.parseDouble(getParameter("Param 3"));
calculate();
}
public void paint(Graphics g)
{
g.drawString("basic salary:"+basic,20,60);
g.drawString("DA:"+da,20,80);
g.drawString("HRA:"+pf,20,100);
g.drawString("PF:"+pf,20,120);
g.drawString("PT:"+pt,20,140);
14
LAB ON ADVANCED JAVA SRI RAKSHA
3SU21SA135

g.drawString("Gross Salary:"+gross,20,160);
g.drawString("Net Salary:"+net,20,180);
}
public void calculate()
{
if(basic<=20000)
{
da=0.4*basic;
hra=0.1*basic;
gross=basic+da+hra;
pf=0.12*basic;
pt=100;
net=gross-(pf-pt);
}
if(basic>20000)
{
da=0.5*basic;
hra=0.15*basic;
gross=basic+da+hra;
pf=0.12*basic;
pt=200;
net=gross-(pf-pt);
}
}
}

15
LAB ON ADVANCED JAVA SRI RAKSHA
3SU21SA135

HTML CODE:
<html>
<body>
<applet code=”employee.class” height=500 width=500>
<param name=”param1” value=”Raksha”></param>
<param name=”param2” value=”1001”></param>
<param name=”param3” value=”90000”></param>
</applet>
</body>
</html>

OUTPUT:

16
LAB ON ADVANCED JAVA SRI RAKSHA
3SU21SA135

PROGRAM-06

Write a Java program using swing component. Design a frame to accept a


book id, book code, book name and price. Calculate the discount based on
the following condition.
BOOK CODE DISCOUNT
A 15%
B 20%
C 25%
Any other 5%
Calculate the discount and display the bill.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class book implements
ActionListener
{
JLabel Icode;
JLabel Iname;
JLabel Iprice;
JLabel Idisc;
JLabel Ibill;
JTextField tcode;
JTextField tname;
JTextField tprice;
JTextField tdisc;
JTextField tbill;
JButton bill;
book()
{
JFrame jfrm=new JFrame("Book Shop");

17
LAB ON ADVANCED JAVA SRI RAKSHA
3SU21SA135

jfrm.setLayout(null);
jfrm.setSize(300,300);
jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Icode=new JLabel("BOOk Code");
tcode=new JTextField();
Iname=new JLabel("Book Name");
tname=new JTextField();
Iprice=new JLabel("Book Price");
tprice=new JTextField();
Idisc=new JLabel("Discount");
tdisc=new JTextField();
Ibill=new JLabel("Net Price");
tbill=new JTextField();
bill=new JButton("BILL");
Icode.setBounds(100,25,100,25);
Iname.setBounds(100,50,100,25);
Iprice.setBounds(100,75,100,25);
Idisc.setBounds(100,100,100,25);
Ibill.setBounds(100,125,100,25);
tcode.setBounds(200,25,100,25);
tname.setBounds(200,50,100,25);
tprice.setBounds(200,75,100,25);
tdisc.setBounds(200,100,100,25);
tbill.setBounds(200,125,100,25);
bill.setBounds(200,200,125,25);
jfrm.add(Icode);
jfrm.add(Iname);
jfrm.add(Iprice);
jfrm.add(Idisc);
jfrm.add(Ibill);

18
LAB ON ADVANCED JAVA SRI RAKSHA
3SU21SA135

jfrm.add(tcode);
jfrm.add(tname);
jfrm.add(tprice);
jfrm.add(tdisc);
jfrm.add(tbill);
jfrm.add(bill);
bill.addActionListener(this);
jfrm.setVisible(true);
tdisc.setEditable(false);
tbill.setEditable(false);
}
public void actionPerformed(ActionEvent d)
{
double discount;
String discant,billamt;
int price;
double netbill;
try
{
if(tcode.getText().equals("A"))discount=15;
else if(tcode.getText().equals("B"))discount=20;
else if(tcode.getText().equals("C"))discount=25;
else discount=5;
discant=Double.toString(discount);
if(!(tname.getText().equals(""))&&
!(tcode.getText().equals(""))&&
!(tprice.getText().equals("")))
tdisc.setText(discant +"%");
price=Integer.parseInt(tprice.getText());
netbill=price-(price*discount)/100;

19
LAB ON ADVANCED JAVA SRI RAKSHA
3SU21SA135

billamt=Double.toString(netbill);
tbill.setText(billamt);
}
catch(NumberFormatException e)
{
tbill.setText("Invalid Number!!!");
}
}
public static void main(String args[])
{
new book();
}
}

OUTPUT:

20
LAB ON ADVANCED JAVA SRI RAKSHA
3SU21SA135

PROGRAM-07
Write a Java program using swing component. Design a frame to generate electricity
bill. Accept the meter number, customer name, previous meter reading, current meter
reading. Use data validation to check whether the current meter reading is greater than
the previous meter reading. Produce a bill in neat format. Calculate the bill based on
consumption as follows:
Modules<150-Rs.200
For next 50 Modules
Rs.1.50/Module For next 100
Modules Rs.2.00/Module
For next additional Modules Rs.3.00/Module or Rs.500 whichever is maximum.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ElectricBill implements
ActionListener
{
JLabel Imno;
JLabel Icname;
JLabel Ipmr;
JLabel Icmr;
JLabel Iunit;
JLabel Iamt;
JTextField tmno;
JTextField tcname;
JTextField tpmr;
JTextField tcmr;
JTextField tunit;
JTextField tamt;
JButton bill;
ElectricBill()
{

21
LAB ON ADVANCED JAVA SRI RAKSHA
3SU21SA135

JFrame jfrm=new JFrame("Electricity Bill");


jfrm.setLayout(null);
jfrm.setSize(300,300);
jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Imno=new JLabel("Meter number:");
tmno=new JTextField();
Icname=new JLabel("Customer name:");
tcname=new JTextField();
Ipmr=new JLabel("Previous Meter reading:");
tpmr=new JTextField();
Icmr=new JLabel("Current Meter reading:");
tcmr=new JTextField();
Iunit=new JLabel("Unit consumed:");
tunit=new JTextField();
Iamt=new JLabel("Total Amount:");
tamt=new JTextField();
bill=new JButton("BILL");
Imno.setBounds(10,25,200,25);
Icname.setBounds(10,50,200,25);
Ipmr.setBounds(10,75,200,25);
Icmr.setBounds(10,100,200,25);
Iunit.setBounds(10,125,200,25);
Iamt.setBounds(10,150,200,25);
tmno.setBounds(200,25,200,25);
tcname.setBounds(200,50,200,25);
tpmr.setBounds(200,75,200,25);
tcmr.setBounds(200,100,200,25);
tunit.setBounds(200,125,200,25);
tamt.setBounds(200,150,200,25);
bill.setBounds(200,200,120,25);

22
LAB ON ADVANCED JAVA SRI RAKSHA
3SU21SA135

jfrm.add(Imno);
jfrm.add(tmno);
jfrm.add(Icname);
jfrm.add(tcname);
jfrm.add(Ipmr);
jfrm.add(tpmr);
jfrm.add(Icmr);
jfrm.add(tcmr);
jfrm.add(Iunit);
jfrm.add(tunit);
jfrm.add(Iamt);
jfrm.add(tamt);
jfrm.add(bill);
bill.addActionListener(this);
jfrm.setVisible(true);
tamt.setEditable(false);
}
public void actionPerformed(ActionEvent d)
{
int unit, diff, cmr, pmr;
String net=null;
double charge=0;
try
{
pmr=Integer.parseInt(tpmr.getText());
cmr=Integer.parseInt(tcmr.getText());
if(cmr>pmr)
{
unit=cmr-pmr;
if(unit<=150)

23
LAB ON ADVANCED JAVA SRI RAKSHA
3SU21SA135

charge=200;
else
if(unit>150&&unit<=200)
{
diff=unit-150;
charge=200+(diff*1.5);
}
else
if(unit>200&&unit<=300)
{
diff=unit-200;
charge=200+(unit*2);
}
else
{
diff=unit-150;
charge=Math.max(200+diff*3,500);
}
net=Double.toString(charge);
tunit.setText(Integer.toString(unit));
tamt.setText(net);
}
else
tamt.setText("Invaild reading");
}
catch(NumberFormatException e)
{
tamt.setText("Invalid Number!!!");
}
}

24
LAB ON ADVANCED JAVA SRI RAKSHA
3SU21SA135

public static void main(String args[])


{
new ElectricBill();
}
}

OUTPUT:

25
LAB ON ADVANCED JAVA SRI RAKSHA
3SU21SA135

PART-B

PROGRAM-01
Write a JDBC program to process a bank transaction
import java.sql.Connection;

26
LAB ON ADVANCED JAVA SRI RAKSHA
3SU21SA135

import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.io.*;
public class Bank
{
static
{
try
{
Class.forName("com.mysql.jdbc.cj.Driver");
}
catch(ClassNotFoundException cnf)
{
System.out.println("Driver could not be loaded"+cnf);
}
}
public static void main(String args[])
{
try
{
String ConnectionUrl="jdbc:mysql://localhost:3307/ashish";
String dbuser="root";
String pswd="password";
DataInputStream in=new DataInputStream (System.in);
String sql;
int vaccno,flag=0;
try
{

27
LAB ON ADVANCED JAVA SRI RAKSHA
3SU21SA135

Connection con =
DriverManager.getConnection(ConnectionUrl,dbuser,pswd);
Statement st=con.createStatement();
System.out.println("enter account number");
vaccno=Integer.parseInt(in.readLine());
sql="select * from account where accno ="+vaccno;
ResultSet rec=st.executeQuery(sql);
while(rec.next())
{
System.out.print(rec.getInt("accno"));
System.out.println("\t"+rec.getString("name"));
System.out.println("\t"+rec.getInt("bal"));
flag=1;
}
if(flag==0)
{
System.out.println("no record found");
}
}
catch(SQLException e1)
{
System.out.println("SQL Exception:"+e1);
}
}
catch(IOException e2)
{
System.out.println("IOException:"+e2);
}
}
}
OUTPUT:
28
LAB ON ADVANCED JAVA SRI RAKSHA
3SU21SA135

PROGRAM-02
Write a JDBC program to retrieve the details from telephone directory
import java.sql.Connection;

29
LAB ON ADVANCED JAVA SRI RAKSHA
3SU21SA135

import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.io.*;
public class Telephone
{
static
{
try
{
Class.forName("com.mysql.jdbc.cjDriver");
}
catch(ClassNotFoundException cnf)
{
System.out.println("Driver could not be loaded"+cnf);
}
}
public static void main(String args[])
{
try
{
String ConnectionUrl="jdbc:mysql://localhost:3306/ashish";
String dbuser="root";
String pswd="password";
DataInputStream in=new DataInputStream (System.in);
String ch;
int flag=0;
try{
Connection con = DriverManager.getConnection(ConnectionUrl,dbuser,pswd);

30
LAB ON ADVANCED JAVA SRI RAKSHA
3SU21SA135

Statement st=con.createStatement();
System.out.println("Enter a few character of user name");
ch=in.readLine();
ResultSet rec=st.executeQuery
("select * from tele where cname like'"+ch+"%'");
while(rec.next())
{
System.out.println(rec.getString("cname"));
System.out.println("\t"+rec.getString("phone"));
flag=1;
}
if(flag==0)
{
System.out.println("no record found");
}
}
catch(SQLException e1)
{
System.out.println("SQL Exception:"+e1);
}
}
catch(IOException e2)
{
System.out.println("IOException:"+e2);
}
}
}
OUTPUT:

31
LAB ON ADVANCED JAVA SRI RAKSHA
3SU21SA135

PROGRAM-03

32
LAB ON ADVANCED JAVA SRI RAKSHA
3SU21SA135

Write a RMI program to convert temperature to Fahrenheit and vice versa


Interface:
import java.rmi.*;
public interface Tempintf extends Remote
{
double cen_fah(double c) throws RemoteException;
double fah_cen(double f) throws RemoteException;
}

Implementation:
import java.rmi.*;
import java.rmi.server.*;
public class TempConvert extends UnicastRemoteObject implements Tempintf
{
public double cen_fah(double c) throws RemoteException
{
double f=c*1.8+32;
return f;
}
public double fah_cen(double f) throws RemoteException
{
double c=(f-32)/1.8;
return c;
}
public TempConvert()throws RemoteException {};
}

Server:
import java.rmi.*;
import java.net.*;

33
LAB ON ADVANCED JAVA SRI RAKSHA
3SU21SA135

public class TempServer


{
public static void main(String args[])
{
try
{
TempConvert t=new TempConvert();
Naming.rebind("TempServer",t);
}
catch(Exception e)
{}
}
}

Client:
import java.rmi.*;
import java.io.*;
public class TempClient
{
public static void main(String args[])
{
try
{
DataInputStream in=new DataInputStream(System.in);
Tempintf t=(Tempintf)Naming.lookup("rmi://localhost/TempServer");
System.out.println("Temperature converion");
System.out.println("Enter celsius Temperature");
float c=Float.valueOf(in.readLine());
System.out.println("Fehrenhit value is:"+t.cen_fah(c));
System.out.println("Enter Fahrenhit Temperature");

34
LAB ON ADVANCED JAVA SRI RAKSHA
3SU21SA135

float f=Float.valueOf(in.readLine());
System.out.println("celsius value is:"+t.fah_cen(f));
}
catch(Exception e)
{}
}
}

OUTPUT:

PROGRAM-04

35
LAB ON ADVANCED JAVA SRI RAKSHA
3SU21SA135

Write a RMI program to calculate interest on a particular amount


Interface:
import java.rmi.*;
public interface Simpleintf extends Remote
{
double simplecal(double p,double t,double r)throws RemoteException;
}

Implementation:
import java.rmi.*;
import java.rmi.server.*;
public class Simpleimp extends UnicastRemoteObject implements Simpleintf
{
public double simplecal(double p,double t, double r)throws RemoteException
{
double si=(p*t*r)/100;
return si;
}
public Simpleimp() throws RemoteException {};
}

Server:
import java.rmi.*;
import java.net.*;
public class SimpleServer
{
public static void main(String args[])
{
try
{

36
LAB ON ADVANCED JAVA SRI RAKSHA
3SU21SA135

Simpleimp s=new Simpleimp();


Naming.rebind("SimpleServer",s);
}
catch(Exception e)
{}
}
}

Client:
import java.rmi.*;
import java.io.*;
public class SimpleClient
{
public static void main(String args[])
{
try
{
DataInputStream in=new DataInputStream (System.in);
Simpleintf s=(Simpleintf)
Naming.lookup("rmi://localhost/SimpleServer");
System.out.println("Simple Interest");
System.out.println("Enter Principle Amount:");
double p=Double.valueOf(in.readLine());
System.out.println("Enter Time:");
double t=Double.valueOf(in.readLine());
System.out.println("Enter Rate of Interest:");
double r=Double.valueOf(in.readLine());
System.out.println("Simple Interest is:"+s.simplecal(p,t,r));
}
catch(Exception e)
{}
37
LAB ON ADVANCED JAVA SRI RAKSHA
3SU21SA135

}
}

OUTPUT:

PROGRAM-05
Write a RMI program to calculate Tax depending on a salary

38
LAB ON ADVANCED JAVA SRI RAKSHA
3SU21SA135

Interface:
import java.rmi.*;
public interface Taxintf extends Remote
{
double Taxcal(double t) throws RemoteException;
}

Implementation:
import java.rmi.*;
import java.rmi.server.*;
public class Taximp extends UnicastRemoteObject implements Taxintf
{
public double Taxcal (double t) throws RemoteException
{
double tax=0;
if(t<=10000)
tax=0;
if(t>10000&&t<=25000)
tax=0.025*t;
if(t>25000&&t<=100000)
tax=0.05*t;
if(t>100000&&t<=1000000)
tax=0.075*t;
if(t>1000000)
tax=0.1*t;
return tax;
}
public Taximp()throws RemoteException{};
}

39
LAB ON ADVANCED JAVA SRI RAKSHA
3SU21SA135

Server:
import java.rmi.*;
import java.net.*;
public class Taxserver
{
public static void main(String args[])
{
try
{
Taximp x=new Taximp();
Naming.rebind("Taxserver",x);
}
catch(Exception e)
{}
}
}

Client:
import java.rmi.*;
import java.io.*;
public class Taxclient
{
public static void main(String args[])
{
try
{
DataInputStream in=new DataInputStream(System.in);
Taxintf t=(Taxintf)Naming.lookup("rmi://localhost/Taxserver");
System.out.println("enter Salary:");
double s=Double.valueOf(in.readLine());

40
LAB ON ADVANCED JAVA SRI RAKSHA
3SU21SA135

double it=t.Taxcal(s);
if(it==0)
{
System.out.println("salary less than 10000");
System.out.println("No Tax Deduction");
System.exit(0);
}
System.out.println("Tax is"+it);
}
catch(Exception e)
{}
}
}

OUTPUT:

PROGRAM-06
Write a RMI program to convert dollar to rupees using command line argument

41
LAB ON ADVANCED JAVA SRI RAKSHA
3SU21SA135

Interface:
import java.rmi.*;
public interface Dolintf extends Remote
{
double dollar (double i)throws RemoteException;
}

Implementation:
import java.rmi.*;
import java.rmi.server.*;
public class DolConvert extends UnicastRemoteObject implements Dolintf
{
public double dollar (double i)throws RemoteException
{
double d=i*74;
return d;
}
public DolConvert()throws RemoteException{};
}

Server:
import java.rmi.*;
import java.net.*;
public class DolServer
{
public static void main(String args[])
{
try
{
DolConvert x=new DolConvert();

42
LAB ON ADVANCED JAVA SRI RAKSHA
3SU21SA135

Naming.rebind("DolServer",x);
}
catch(Exception e)
{}
}
}

Client:
import java.rmi.*;
import java.io.*;
public class DolClient
{
public static void main(String args[])
{
try
{
DataInputStream in=new DataInputStream(System.in);
Dolintf x=(Dolintf)Naming.lookup("rmi://localhost/DolServer");
System.out.println("dollar conversion");
System.out.println("enter dollar");
double i=Float.valueOf(in.readLine());
System.out.println("value dollars in rupee is:"+x.dollar(i));
}
catch(Exception e)
{}
}
}

OUTPUT:

43
LAB ON ADVANCED JAVA SRI RAKSHA
3SU21SA135

44

You might also like