0% found this document useful (0 votes)
27 views

A-OOP Assignment 2 SUNAIM

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)
27 views

A-OOP Assignment 2 SUNAIM

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/ 6

ASSIGNMEN

T
ADVANCED OBJECT ORIENTED PROGRAMMING

( CE- 206 )

Fall Semester 2021

Submitted By:
N ame # SUNAIM ABDULLAH
R oll N umber # 2 0 2 0 - C E - 0 41

Submitted To:

MISS UMM-E-LAILA

Computer Engineering Department


Sir Syed University of Engineering &
Technology University Road, Karachi 75300
AOOP SUNAIM ABDULLAH [2020-CE-041]

http://www.ssuet.edu.pk

ASSIGNMENT#2

QUESTION#1:
The Student table is defined as follows:
create table Student
( firstname varchar(25),
mi char(1),
lastname varchar(25),
studentID varchar(25),
year int(1)
, city varchar(20),
email varchar(30) );

Demonstration:
In this snapshot, 6 functionalities are given in terms of buttons namely first,
next, last, insert, clear and update. Beneath it, there is a form which consists of
fields like first name, last name, student ID etc. First, next and last buttons are
used to show the records of the table according to the requirements. First will
filter the details of the first user entered with ID number 1. Next will filter the
details entered afterwards and the last button is used to filter last record of the
table. Insert button is used to enter the new record in the table. Clear button is
for resetting all the fields. The purpose is that if you have entered incorrect data
in all the fields then no need to clear the field one by one. Clear button will

2
AOOP SUNAIM ABDULLAH [2020-CE-041]

automatically reset all the fields filled. Last one is update, update is for editing
any inserted record that you have entered in the past.

QUESTION#2:
Prepare a TCP client/server application that will communicate over the network and
exchange data. The server will start listening for a transmission from the client. The client
will then start and contact the server (IP address: 127.0.0.1 and port number: 6666). The
client will pass the server a 2 integer numbers i.e user name (e.g. “AliKhan”) up to 7
characters in length. On receiving a string from a client, the server should:

1. Reverse all the characters, and 2. Reverse the capitalization of the strings (“AliKhan”
would now become “NAHKILA”)

SOURCE CODE (Client):


package client;

import java.net.*;
import java.util.Scanner;
import java.io.*;

public class Client {

public static void main(String[] args) throws IOException {


try {
Scanner sc = new Scanner(System.in);
Socket s = new Socket("localhost", 333);
Scanner sc1 = new Scanner(s.getInputStream());
System.out.print("GIVEN MESSAGE: ");
String msg = sc.nextLine();
PrintStream ps = new PrintStream(s.getOutputStream());
ps.println(msg);
String reply = sc1.nextLine();

System.out.println("OUTPUT: " + reply);

3
AOOP SUNAIM ABDULLAH [2020-CE-041]

} catch (Exception e) {
System.out.println(e);
}
}
}

SOURCE CODE (Server):


package server;

import java.net.*;
import java.util.Scanner;
import java.io.*;
public class Server {
public static void main(String[] args) throws IOException {
try{ ServerSocket ss=new ServerSocket(333);
Socket s=ss.accept();//establishes connection
Scanner sc=new Scanner(s.getInputStream());
String in=sc.nextLine();

in=in.toLowerCase();
in=in.toUpperCase();

for(int i=in.length()-1; i>=0; i--) {


in = in+in.charAt(i);
}

PrintStream ps=new PrintStream(s.getOutputStream());

ps.println(in);
}catch(Exception e){System.out.println(e);}
}}

OUTPUT:

4
AOOP SUNAIM ABDULLAH [2020-CE-041]

QUESTION#3:
Produce an implement a Queue class whose add and remove methods are synchronized.
Supply one thread, called the producer, which keeps inserting strings into the queue as long
as there are fewer than 10 elements in it. When the queue gets too full, the thread waits.
Supply a second thread, called the consumer that keeps removing and printing strings from
the queue as long as the queue is not empty. When the queue is empty, the thread waits. Both
the consumer and producer threads should run for 10 iterations.

SOURCE CODE:
package queue;
import java.lang.Thread;

public class QUEUE implements Runnable {

private String Name;


public QUEUE(String ThreadName){
this.Name= ThreadName;
}
public void run(){try {
for(int j = 0; j < 10; j++) {
System.out.println(Name + ": " + j);

}
Thread.sleep(1000);
}catch (InterruptedException e) {
System.out.println(Name + " thread Interrupted");
}
System.out.println(Name + " thread exiting.");
}

public static void main(String[] args) {

5
AOOP SUNAIM ABDULLAH [2020-CE-041]

Thread t1 = new Thread( (java.lang.Runnable) new QUEUE("Insert"));


Thread t2 = new Thread((java.lang.Runnable) new QUEUE("DELETING"));
t1.start();
t2.start();

}}

OUTPUT:

You might also like