Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

some java applet programs and c programs, Exercises of Java Programming

some java applet programs and c programs

Typology: Exercises

2016/2017

Uploaded on 12/28/2017

leh-kargil
leh-kargil 🇮🇳

1 document

1 / 12

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
34 Wap to input the name ,account type and account number of a customer in a
bank and perform the following operations:
a)Write objects into file with unique account number(Serialize)
b)Read all the objects from the file.
c)Search the record from file.
35 wap to input the name ,rollnumber and marks of a student in 4 different
subjects from applet tag to java program
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
/*<applet code="AppletSum.class" width= "400" height= "600"></applet>*/
public class Appletsum extends Applet implements ActionListener
{
Button b1,b2;
TextField t1,t2,t3,t4,t5;
Label l1,l2,l3,l4,l5,l6,l7;
public void init(){
l1= new Label("Name of a student ");
l2= new Label("Marks is Subject 1");
l3= new Label("Marks is Subject 2");
l4= new Label("Marks is Subject 3");
l5= new Label("Marks is Subject 4");
l6= new Label();
l7= new Label();
t1= new TextField();
t2= new TextField();
t3= new TextField();
t4= new TextField();
t5= new TextField();
b1= new Button("SUM");
b2= new Button("AVG");
setLayout(null);
l1.setBounds(30,30,100,30);
l2.setBounds(30,60,100,30);
l3.setBounds(30,90,100,30);
l4.setBounds(30,120,100,30);
l5.setBounds(30,150,100,30);
t1.setBounds(200,30,100,30);
t2.setBounds(200,60,100,30);
t3.setBounds(200,90,100,30);
t4.setBounds(200,120,100,30);
t5.setBounds(200,150,100,30);
b1.setBounds(60,200,100,30);
b2.setBounds(60,250,100,30);
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download some java applet programs and c programs and more Exercises Java Programming in PDF only on Docsity!

34 Wap to input the name ,account type and account number of a customer in a

bank and perform the following operations:

a)Write objects into file with unique account number(Serialize)

b)Read all the objects from the file.

c)Search the record from file.

35 wap to input the name ,rollnumber and marks of a student in 4 different

subjects from applet tag to java program

import java.applet.Applet; import java.awt.; import java.awt.event.; // public class Appletsum extends Applet implements ActionListener { Button b1,b2; TextField t1,t2,t3,t4,t5; Label l1,l2,l3,l4,l5,l6,l7;

public void init(){

l1= new Label("Name of a student "); l2= new Label("Marks is Subject 1"); l3= new Label("Marks is Subject 2"); l4= new Label("Marks is Subject 3"); l5= new Label("Marks is Subject 4"); l6= new Label(); l7= new Label(); t1= new TextField(); t2= new TextField(); t3= new TextField(); t4= new TextField(); t5= new TextField(); b1= new Button("SUM"); b2= new Button("AVG"); setLayout(null); l1.setBounds(30,30,100,30); l2.setBounds(30,60,100,30); l3.setBounds(30,90,100,30); l4.setBounds(30,120,100,30); l5.setBounds(30,150,100,30);

t1.setBounds(200,30,100,30); t2.setBounds(200,60,100,30); t3.setBounds(200,90,100,30); t4.setBounds(200,120,100,30); t5.setBounds(200,150,100,30); b1.setBounds(60,200,100,30); b2.setBounds(60,250,100,30);

l6.setBounds(200,200,100,30); l7.setBounds(200,250,100,30);

add(l1); add(l2); add(l3); add(l4); add(l5); add(t1); add(t2); add(t3); add(t4); add(t5); add(b1); add(b2); add(l6); add(l7); b1.addActionListener( this); b2.addActionListener(this); } public void actionPerformed(ActionEvent e){ int a,b,c,d,s; float avg; String x; a=Integer.parseInt(t2.getText()); b=Integer.parseInt(t3.getText()); c=Integer.parseInt(t4.getText()); d=Integer.parseInt(t5.getText());

s=a+b+c+d; avg= (a+b+c+d)/4; l6.setText("sum is "+s); l7.setText("Average"+avg); }

public void mouseExited(MouseEvent me) { mousex=0; mousey=10; msg="mouse exited"; repaint(); }

public void mousePressed(MouseEvent me) { mousex=me.getX(); mousey=me.getY(); msg="down"; repaint(); }

public void mouseReleased(MouseEvent me) { mousex=me.getX(); mousey=me.getY(); msg="up"; repaint(); }

public void mouseDragged(MouseEvent me) { mousex=me.getX(); mousey=me.getY(); msg="*"; showStatus("Dragging mouse at "+mousex+" , "+mousey); repaint(); }

public void mouseMoved(MouseEvent me) { showStatus("mouse moving at "+me.getX()+" , "+me.getY()); } public void paint(Graphics g) { g.drawString(msg,mousex,mousey); } }

37 Wap to implement Keyboard events.

import java.awt.; import java.awt.event.; import java.applet.; / */ public class KeyE extends Applet implements KeyListener { String msg = ""; int X = 10, Y = 20; public void init() { addKeyListener(this); }

public void keyPressed(KeyEvent ke) { showStatus("Key Down"); }

public void keyReleased(KeyEvent ke) { showStatus("Key Up"); }

public void keyTyped(KeyEvent ke) { msg += ke.getKeyChar(); repaint(); }

public void paint(Graphics g) { g.drawString(msg, X, Y); } }

t1=new TextField(3); p4.add(t1); p4.add(new Label(" MARKS IN SUBJECT 2.")); t2=new TextField(3); p4.add(t2); p4.add(new Label(" MARKS IN SUBJECT 3.")); t3=new TextField(3); p4.add(t3); p4.add(new Label(" MARKS IN SUBJECT 4.")); t4=new TextField(3); p4.add(t4); p4.add(new Label("TOTAL")); t5=new TextField(3); p4.add(t5); p4.add(new Label("AVERAGE")); t6=new TextField(3); p4.add(t6); p4.add(tot); p4.add(avg); add(p4); m.addItemListener(this); f.addItemListener(this); c1.addItemListener(this); c2.addItemListener(this); tot.addActionListener(this); avg.addActionListener(this); } public void paint(Graphics g) { int m1,m2,m3,m4,tot; float avg=0.0f; m1=m2=m3=m4=tot=0; m1=Integer.parseInt(t1.getText()); m2=Integer.parseInt(t2.getText()); m3=Integer.parseInt(t3.getText()); m4=Integer.parseInt(t4.getText()); tot=m1+m2+m3+m4; avg=tot/4; s1=String.valueOf(tot); s2=String.valueOf(avg); s3=""; } public void actionPerformed(ActionEvent e) { s3=e.getActionCommand(); if(s3.equals("TOTAL")) t5.setText(s1); if(s3.equals("AVERAGE")) t6.setText(s2); repaint(); } public void itemStateChanged(ItemEvent e) { repaint(); } }

39 Wap to determine ip address and host name of local computer.

import java.net.InetAddress; import java.net.UnknownHostException; import java.util.Arrays;

public class IPAddress { public static void main(String args[]) { InetAddress myIP = null; try { myIP = InetAddress.getLocalHost();

String IPAddress = myIP.getHostAddress(); String hostname = myIP.getHostName(); System.out.printf("IP address of Localhost is %s %n", IPAddress); System.out.printf("Host name of your machine is %s %n", hostname); } catch(Exception e){System.out.println(e);}

40 Wap to implement methods of InetAddress class and URL connection class.

import java.io.; import java.net.; public class URLDemo { public static void main(String[] args){ try{ URL url=new URL("http://www.facebook.com");

System.out.print((char) c); } input.close(); } else { System.out.println("No Content Available"); } } }

42 Wap for messages that are typed into the window at the server and written

across the network to the client side using TCP and UDP.

43 Wap to retrieve all the records from the data base.

package javaApplication1;

import java.sql.*;

import java.sql.DriverManager;

public class JDBC {

public static void main(String a[])

try

int i=0;

Class.forName("oracle.jdbc.driver.OracleDriver");

Connection con=DriverManager.getConnection

("jdbc:oracle:thin:@localhost:1521:xe","system","kanchu");

Statement stmt=con.createStatement();

ResultSet rs=stmt.executeQuery("select * from mca");rs.getMetaData

ResultSetMetaData rsmd=rs.getMetaData();

System.out.println("column no=" +rsmd.getColumnCount());

while(rs.next())

i++;

System.out.println(rs.getString(1)+ " "+ rs.getString(2)+"

"+rs.getString(3));

con.close();

catch(Exception e)

System.out.println(e);

LIST No 4

S.No Title P.No Reamks

Java Programming

34 34 Wap to input the name ,account type and account

number of a customer in a bank and perform the following

operations: