Professional Documents
Culture Documents
Java Da-3
Java Da-3
PROGRAMMING IN JAVA
LAB DIGITAL ASSIGNMENT – III
NAME:ANNAPOORNA A NAIR
REG-NO:21MIS0130
1. Use AWT to design the following page:
CODE:
import java.awt.event.*;
import javax.swing.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.PreparedStatement;
ApplicationForm() {
l1 = new JLabel("Application Form");
l1.setBounds(270, 30, 100, 50);
add(l1);
name = new JLabel("Name: ");
name.setBounds(200, 100, 100, 30);
add(name);
t1 = new JTextField();
t1.setBounds(320, 100, 150, 30);
add(t1);
age = new JLabel("Age: ");
age.setBounds(200, 150, 100, 30);
add(age);
t2 = new JTextField();
t2.setBounds(320, 150, 150, 30);
add(t2);
nationality = new JLabel("Nationality: ");
nationality.setBounds(200, 200, 100, 30);
add(nationality);
t3 = new JTextField();
t3.setBounds(320, 200, 150, 30);
add(t3);
designation = new JLabel("Designation: ");
designation.setBounds(200, 250, 100, 30);
add(designation);
t4 = new JTextField();
t4.setBounds(320, 250, 150, 30);
add(t4);
submit = new JButton("Submit");
submit.setBounds(270, 330, 100, 30);
submit.addActionListener(this);
add(submit);
setLayout(null);
setTitle("Application Form");
setSize(700, 500);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
OUTPUT:
After clicking submit button:
2. Implement a multi-tasking program to find the Armstrong numbers between 1 to 10000.
Create five threads and allocate the above given task for a specific range of values. At the end
of the program, output the count of the Armstrong numbers generated on the whole.(Use
Extends Thread class)
CODE:
armstrong(int x, int y) {
this.start = x;
this.end = y;
}
class armm {
public static void main(String args[]) throws Exception {
armstrong ob1 = new armstrong(1, 2000);
ob1.start();
armstrong ob2 = new armstrong(2001, 4000);
ob2.start();
armstrong ob3 = new armstrong(4001, 6000);
ob3.start();
armstrong ob4 = new armstrong(6001, 8000);
ob4.start();
armstrong ob5 = new armstrong(8001, 10000);
ob5.start();
ob1.join();
ob2.join();
ob3.join();
ob4.join();
ob5.join();
System.out.println("\nCount is: " + armstrong.count);
}
}
OUTPUT:
3. Implement a Client Server program using TCP protocol. The Client should send an
integer value to the server. The Server receives the value and calculates the factorial
value to the server. The server receives the value and calculates the factorial value
and sends the result to the client. The client should finally display the result to the
user.
CODE:
SERVER:-
import java.net.*;
import java.io.*;
class factserver {
public static void main(String args[]) throws Exception {
ServerSocket ss = new ServerSocket(2222);
while (true) {
System.out.println("Server is waiting");
Socket s = ss.accept();
BufferedReader br = new BufferedReader(new
InputStreamReader(s.getInputStream()));
PrintStream p = new PrintStream(s.getOutputStream());
System.out.println("Server is listening");
int a = Integer.parseInt(br.readLine());
int fact = 1;
for (int i = 1; i <= a; i++) {
fact *= i;
}
p.println("Factorial is :" + fact);
}
}
}
CLIENT:-
import java.net.*;
import java.io.*;
import java.util.*;
class factclient {
public static void main(String args[]) throws Exception {
Socket s = new Socket("localhost", 2222);
BufferedReader br = new BufferedReader(new
InputStreamReader(s.getInputStream()));
PrintStream p = new PrintStream(s.getOutputStream());
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number A: ");
int a = sc.nextInt();
p.println(a);
String msg = br.readLine();
System.out.println(msg);
s.close();
}
}
OUTPUT:-
SERVER:-
CLIENT:-