You are on page 1of 32

------------SLIP1-------------

1. Create an abstract class shape. Derive three classes sphere, cone and cylinder
from it.
Calculate area and volume of all (use method overriding)
-----------REFER BOOK----------
2. Design an HTML page containing 4 option buttons (Painting, Drawing, Singing
and Swimming) and 2 buttons Reset and Submit. When the user clicks Submit
button, the server responds by adding a cookie containing the selected hobby and
sends a message back to the client. Program should not allow duplicate cookies to
be written. (SERVLET CODE USE NETBEANS ON WINDOWS).
-----------REFER BOOK----------
------------SLIP2-------------
1. Write a menu driven program to perform the following operations on a set of
integers as shown in the following figure. The load operation should generate 10
random integers (2 digits) and display the numbers on the screen. The save operation
should save the numbers to a file “numbers.txt”. The Sort menu provides various
operations and the result is displayed on the screen.

Operation Sort
Load Ascending
Save Descending
Exit

Numbers

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
public class SampleMenu1 extends JFrame implements ActionListener
{
JMenuItem load,save,exit;
JRadioButtonMenuItem b1,b2;
JTextArea tr;
JMenuBar mb;
JMenu m,New;
ButtonGroup bg;
JFileChooser fc1;
JLabel lblnum;
public SampleMenu1()
{
setSize(600,700) ;
initComponent();
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void initComponent()
{
bg=new ButtonGroup();
mb = new JMenuBar();
load=new JMenuItem(" Load ");
save=new JMenuItem(" Save ");
exit=new JMenuItem(" Exit ");
b1=new JRadioButtonMenuItem(" Ascending");
b2=new JRadioButtonMenuItem(" Descending");
setJMenuBar(mb) ;
lblnum = new JLabel("Numbers :");
mb.add(m = new JMenu("Operation"));
m.add(load);
m.add(save);
m.addSeparator();
m.add(exit);
mb.add(New =new JMenu(" Sort "));
New.add(b1);
New.add(b2);
bg.add(b1);
bg.add(b2);
add(lblnum);
JPanel p = new JPanel();
p.add(new JTextArea());
tr=new JTextArea(" ");
lblnum.setBounds(80,210,100,30);
tr.setBounds(50,250,500,300);
add(tr);
add(p);
load.addActionListener(this);
save.addActionListener(this);
exit.addActionListener(this);
b1.addActionListener(this);
b2.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
Object src = e.getSource();
String fname="";
String num="";
if(src.equals(load))
{
try
{
tr.setText("");
fc1 = new JFileChooser("File Dialog");
int result;
result=fc1.showOpenDialog(this);
if(result==fc1.APPROVE_OPTION)
{
fname=fc1.getSelectedFile().getAbsolutePath();
}
FileInputStream fin=new FileInputStream(fname);
int i;

do
{
i=fin.read();
if(i!=-1)
{
num=num+""+(char)(i);
}
}while(i!=-1);
tr.append(num);
}
catch(IOException io)
{
System.out.println(""+io);
}
}
else if(src.equals(exit))
{
setVisible(false);
System.exit(0);
}
else if(src.equals(save))
{
try
{
FileWriter fout=new FileWriter(fc1.getSelectedFile().getAbsolutePath());
num="";
num=tr.getText();
fout.write(num);
fout.close();
}
catch(Exception se)
{
System.out.println(""+se);
}
}
else if(src.equals(b1))
{
System.out.println("Ascending Button Clicked");
}
else if(src.equals(b2))
{
System.out.println("Descending Button Clicked");
}
}
public static void main(String arg[])
{
new SampleMenu1();
}
}

2. Write a client-server program which displays the server machine’s date and time
on the
client machine.
---------refer book-----------

------------SLIP4-------------

1. Write a menu driven program to perform the following operations on a set of


integers as shown in the following figure. The load operation should generate 10
random integers (2 digits) and display the numbers on the screen. The save operation
should save the numbers to a file “numbers.txt”. The Sort menu provides various
operations and the result is displayed on the screen.
Operation Compute
Load Sum
Save Average
Exit
Numbers
2. Design a servlet that provides information about a HTTP request from a client,
such as IP address and browser type. The servlet also provides information about the
server on which the servlet is running, such as the operating system type, and the
names of currently loaded servlet.
----------refer book------------

------------SLIP5-------------
1. Define a class SavingAccount (acno, name, balance). Define appropriate
constructors and operations withdraw(), deposit(), and viewbalance(). The
minimum balance must be 500. Create an object and perform operations.
Raise user defined “InsufficientFundsException” when balance is not
sufficient for withdraw operation.
--------------refer book---------------------
2. Define a thread to move numbers inside a panel vertically. The numbers
should be created between 0 – 9 when user clicks on the Start Button. Each
number should have a different color and vertical position (calculated
randomly). Note: suppose user has clicked Start button 5 times then five
numbers say 0, 1, 5, 9, 3 should be created and move inside the panel.
Choice of number between 0-9 is random. Ensure that number is moving
within the panel border only.
import java.awt.*;
import java.awt.event.*;
public class Ass19 extends Frame implements ActionListener,Runnable
{
Button b1,b2;
TextArea t;
int cnt;
Thread t1 = new Thread(this,"t1");
public Ass19()
{
setLayout(null);
t=new TextArea();
b1=new Button("Start");
b2=new Button("Stop");
t.setBounds(50,50,600,100);
t.setForeground(Color.RED);
b1.setBounds(50,170,100,30);
b2.setBounds(160,170,100,30);
add(t);
b1.addActionListener(this);
b2.addActionListener(this);
add(b1);
add(b2);
setSize(900,400);
setVisible(true);
cnt=0;

addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});

}
public void actionPerformed(ActionEvent ae)
{
String str;
str=ae.getActionCommand();
if(str.equals("Start"))
{

t1.start();
}
if(str.equals("Stop"))
{
t1.stop();
}
}
public void run()
{
try
{
while(true)
{

for(int i=0;i<=100;i++)
{
t.setText(" "+i);
Thread.sleep(150);
}

}
}
catch(Exception e)
{}
}
public static void main(String args[])
{
new Ass19().show();
}
}

------------SLIP6-------------
1. Write a program to accept a decimal number in the Textfield. After clicking
Calculate button, program should display the binary, octal, hexadecimal equivalent
for the entered decimal number.
Decimal Number TextField
Binary Number Label
Octal Number Label
Hexadecimal Number Label
CALCULATE
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class slip24java extends JFrame implements ActionListener
{
JFrame fm;
JButton b1;
JTextField t1,t2,t3,t4;
JLabel l1,l2,l3,l4;
slip24java()
{
fm=new JFrame("number");
fm.setLayout(null);
fm.setSize(800,800);
fm.setVisible(true);
fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

b1=new JButton("calculate");
b1.setBounds(160,220,100,30);
b1.addActionListener(this);

l1=new JLabel("Decimal Number");


l1.setBounds(30,100,150,20);

t1=new JTextField(20);
t1.setBounds(190,100,150,20);

l2=new JLabel("Binary Number");


l2.setBounds(30,130,150,20);

t2=new JTextField(20);
t2.setBounds(190,130,150,20);

l3=new JLabel("Octal Number");


l3.setBounds(30,160,150,20);

t3=new JTextField(20);
t3.setBounds(190,160,150,20);

l4=new JLabel("Hexadecimal Number");


l4.setBounds(30,190,150,20);

t4=new JTextField(20);
t4.setBounds(190,190,150,20);
fm.add(l1);
fm.add(t1);
fm.add(l2);
fm.add(t2);
fm.add(l3);
fm.add(t3);
fm.add(l4);
fm.add(t4);
fm.add(b1);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
int dec=Integer.parseInt(t1.getText());
t2.setText(""+Integer.toBinaryString(dec));
t3.setText(""+Integer.toOctalString(dec));
t4.setText(""+Integer.toHexString(dec));
}
}
public static void main(String args[])
{
slip24java s=new slip24java();
}
}
2. Write a server program which echoes messages sent by the client. The process
continues till the client types “END”.
-----------------refer notebook----------------------

------------SLIP7-------------
1. Create a package named Series having two different classes to print the
following
series:
a. Prime numbers b. Squares of numbers Write a program to generate ‘n’ terms of
the above series.
-----------------refer book--------------------------
2. Create a table Student with the fields roll number, name, percentage using
Postgresql. Write a menu driven program (Command line Interface) to perform the
following operations on student table.
a. Insert b. Modify c. Delete d. Search e. View All f. Exit
-----------------refer book--------------------------
------------SLIP8-------------
1. Write a program to create the following GUI and apply the changes to the text in
the
TextField.
Font Style
Arial Bold
5-10 Italic

TextField

3. Design a servlet which counts how many times a user has visited a web page.
If the user is visiting the page for the first time then display a message
“Welcome”. If the user is revisiting the page, then display the number of times
page is visited. (Use Cookies)
-----------------refer book--------------------

------------SLIP9-------------
1. Create an Applet which displays a message in the center of the screen. The
message indicates the events taking place on the applet window. Handle events like
mouse click, mouse moves, mouse dragged, mouse pressed. The message should
update each time an event occurs. The message should give details of the event such
as which mouse button was pressed (Hint: Use repaint(), MouseListener,
MouseMotionListener)

import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class slip13_1 extends Applet implements MouseListener,


MouseMotionListener
{
int x, y;
String msg = " ";
TextField tf1;

public void init()


{
addMouseListener(this);
addMouseMotionListener(this);

tf1 = new TextField(20);


add(tf1);
}

public void paint(Graphics g)


{
g.drawString(msg, x, y);
}

public void mouseClicked(MouseEvent me)


{
x = 10;
y = 10;
msg = "Mouse Clicked.";
tf1.setText("" + me.getX() + ", " + me.getY());
repaint();
}

public void mouseEntered(MouseEvent me)


{
x = 10;
y = 10;
msg = "Mouse Entered.";
repaint();
}

public void mouseExited(MouseEvent me)


{
x = 10;
y = 10;
msg = "Mouse Exited.";
repaint();
}

public void mousePressed(MouseEvent me)


{
x = me.getX();
y = me.getY();
msg = "Mouse Pressed.";
repaint();
}

public void mouseReleased(MouseEvent me)


{
x = me.getX();
y = me.getY();
msg = "Mouse Released.";
repaint();
}

public void mouseDragged(MouseEvent me)


{
x = me.getX();
y = me.getY();
msg = "*";
showStatus("Dragging Mouse at: " + x + ", " + y);
repaint();
}

public void mouseMoved(MouseEvent me)


{
x = me.getX();
y = me.getY();
msg = "I am Moving..";
showStatus("Moving Mouse at: " + x + ", " + y);
repaint();
}
}
2. Write a program which sends the name of text file from the client to server and
display the contents of that file on the client machine. If the file does not exists
display proper error message.
-----------refer book--------------

------------SLIP10-------------
1. Write a program to implement a simple arithmetic calculator. Perform
appropriate
validations.
Result
123+
456-
789*
0.=/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class calc extends JFrame implements ActionListener
{
JTextField t1;
Font f;
JButton b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b16;
String flag;
int a,b;
calc(String title)
{
super(title);
setVisible(true);
setSize(320,250);
setLayout(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f=new Font("Times New Roman",Font.BOLD,25);
t1=new JTextField(15);
t1.setBounds(30,20,250,30);
add(t1);
b1=new JButton("1");
b1.setBounds(20,60,60,25);
b1.setFont(f);
add(b1);
b1.addActionListener(this);
b2=new JButton("2");
b2.setBounds(90,60,60,25);
b2.setFont(f);
b2.addActionListener(this);
add(b2);
b3=new JButton("3");
b3.setBounds(160,60,60,25);
b3.setFont(f);
add(b3);
b3.addActionListener(this);
b4=new JButton("4");
b4.setBounds(20,95,60,25);
b4.setFont(f);
add(b4);
b4.addActionListener(this);
b5=new JButton("5");
b5.setBounds(90,95,60,25);
b5.setFont(f);
add(b5);
b5.addActionListener(this);
b6=new JButton("6");
b6.setBounds(160,95,60,25);
b6.setFont(f);
add(b6);
b6.addActionListener(this);
b7=new JButton("7");
b7.setBounds(20,130,60,25);
b7.setFont(f);
add(b7);
b7.addActionListener(this);
b8=new JButton("8");
b8.setBounds(90,130,60,25);
b8.setFont(f);
add(b8);
b8.addActionListener(this);
b9=new JButton("9");
b9.setBounds(160,130,60,25);
b9.setFont(f);
add(b9);
b9.addActionListener(this);
b10=new JButton("0");
b10.setBounds(20,165,60,25);
b10.setFont(f);
add(b10);
b10.addActionListener(this);
b11=new JButton("+");
b11.setBounds(230,60,60,25);
add(b11);
b11.addActionListener(this);
b12=new JButton("-");
b12.setBounds(230,95,60,25);
b12.setFont(f);
add(b12);
b12.addActionListener(this);
b13=new JButton("*");
b13.setBounds(230,130,60,25);
b13.setFont(f);
add(b13);
b13.addActionListener(this);
b14=new JButton("/");
b14.setBounds(230,165,60,25);
b14.setFont(f);
add(b14);
b14.addActionListener(this);
b15=new JButton("=");
b15.setBounds(160,165,60,25);
b15.setFont(f);
add(b15);
b15.addActionListener(this);
b16=new JButton("Ac");
b16.setBounds(90,165,60,25);
Font f1=new Font("Times new Roman",Font.BOLD,15);
b16.setFont(f1);
add(b16);
b16.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
t1.setText(t1.getText()+"1");
}
if(e.getSource()==b2)
{
t1.setText(t1.getText()+"2");
}
if(e.getSource()==b3)
{
t1.setText(t1.getText()+"3");
}
if(e.getSource()==b4)
{
t1.setText(t1.getText()+"4");
}
if(e.getSource()==b5)
{
t1.setText(t1.getText()+"5");
}
if(e.getSource()==b6)
{
t1.setText(t1.getText()+"6");
}
if(e.getSource()==b7)
{
t1.setText(t1.getText()+"7");
}
if(e.getSource()==b8)
{
t1.setText(t1.getText()+"8");
}
if(e.getSource()==b9)
{
t1.setText(t1.getText()+"9");
}
if(e.getSource()==b10)
{
t1.setText(t1.getText()+"0");
}
if(e.getSource()==b11)
{
a=Integer.parseInt(t1.getText());
t1.setText("");
flag="a";
}
if(e.getSource()==b12)
{
a=Integer.parseInt(t1.getText());
t1.setText("");
flag="m";
//t1.setText("-");
}
if(e.getSource()==b13)
{
a=Integer.parseInt(t1.getText());
t1.setText("");
flag="mult";
// t1.setText(t1.getText()+"*");
}
if(e.getSource()==b14)
{
a=Integer.parseInt(t1.getText());
t1.setText("");
flag="d";
//t1.setText(t1.getText()+"/");
}
if(e.getSource()==b16)
{
t1.setText("");
}
if(e.getSource()==b15)
{
if(flag=="a")
{
b=Integer.parseInt(t1.getText());
a=a+b;
t1.setText(""+a);
}
if(flag=="m")
{
b=Integer.parseInt(t1.getText());
a=a-b;
t1.setText(""+a);
}
if(flag=="mult")
{
b=Integer.parseInt(t1.getText());
a=a*b;
t1.setText(""+a);
}
if(flag=="d")
{
b=Integer.parseInt(t1.getText());
if(b==0)
{
t1.setText("Error");
}
else
{
a=a/b;
t1.setText(""+a);
}

}
}
}

public static void main(String args[])


{
calc c1=new calc("Calculator");
}

}
2. Write a program to accept a list of file names on the client machine and check
how
many exist on the server. Display appropriate messages on the client side.
import java.net.*;
import java.io.*;

class server3
{
public static void main(String[] args) throws IOException
{
Socket s = null;
PrintWriter out = null;
ServerSocket ss = null;
String fname[]=new String[20];
int i,n;
try
{
ss = new ServerSocket(1234);
System.out.println("Server Started.......");
s= ss.accept();
System.out.println("Server Connected.......");
BufferedReader in = new BufferedReader(new
InputStreamReader(s.getInputStream()));
out = new PrintWriter(s.getOutputStream(), true);
n=Integer.parseInt(in.readLine());
System.out.println("The files are: ");
for(i=0;i<n;i++)
{
fname[i]=in.readLine();
System.out.println(fname[i]);
File f=new File(fname[i]);
if(f.exists())
out.println("File present ");
else
out.println("The file "+fname[i]+" does not exists");
}
out.close();
s.close();
}
catch (Exception e)
{
System.out.println("Error: "+e);
}
}
}
import java.io.*;
import java.net.*;

class client3
{
public static void main(String[] args) throws IOException
{
Socket s = null;
PrintWriter out = null;
int i,n;
try
{
s = new Socket("127.0.0.1", 1234);
out = new PrintWriter(s.getOutputStream(), true);
BufferedReader in = new BufferedReader(new
InputStreamReader(s.getInputStream()));
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
System.out.print("Enter the how many files you want: ");
n=Integer.parseInt(br.readLine());
out.println(n);
String fname[]=new String[n];
System.out.println("Enter the "+n+" file names: ");
for(i=0;i<n;i++)
{
fname[i]=br.readLine();
out.println(fname[i]);
System.out.println(in.readLine());
}
s.close();
in.close();
}
catch (UnknownHostException e)
{
System.out.println("Error :"+e);
}
}
}
------------SLIP11-------------
1. Write a program to accept a string as command line argument and check
whether it is a
file or directory. Also perform operations as follows:
a. If it is a directory, list the names of text files. Also, display a count showing
the number of files in the directory. b. If it is a file display various details of that
file.
---------------refer notebook----------------
2. Define a thread called “PrintTextThread” for printing text on command prompt
for ‘n’ number of times. Create three threads and run them. Pass the text and ‘n’ as
parameters to the thread constructor. Example:
a. First thread prints “I am in FY” 10 times b. Second thread prints “I am in SY”
20 times c. Third thread prints “I am in TY” 30 times.
-----------------refer notebook-----------------------------
------------SLIP12-------------
1. Create the following GUI screen using appropriate layout manager. Accept the
name,
class, hobbies from the user and display the selected options in a text box.
Your Name TextField
Your Class Your Hobbies
FY Music
SY Dance
TY Sports
Name ---- , Class ----, Hobbies ------

2. Write a program to calculate the sum and average of an array of 1000 integers
(generated randomly) using 10 threads. Each thread calculates the sum of 100
integers. Use these values to calculate average. [Use join method].
-----------refer book----------
------------SLIP14-------------
1. Write a menu driven program to perform the following operations on a text file
“phone.txt” which contains name and phone number pairs. The menu should have
options:
a. Search name and display phone number b. Add new name-phone number pair.
--------------refer book-------------
2. Construct a Linked List containing names of colors: red, blue, yellow and
orange. Then
extend your program to do the following:
a. Display the contents of the List using an Iterator. b. Display the contents of the
List in reverse order using a ListIterator. c. Create another list containing pink and
green. Insert the elements of this list between blue and yellow.
--------------refer book-------------
------------SLIP15-------------
1. Write a program to read item information (id, name, price, qty) from the file
“item.dat”. Write a menu driven program to perform the following operations using
Random access file:
a. Search for a specific item by name b. Find costliest item c. Display all items and
total cost
---------------refer notebook----------------
2. Create a Hash table containing student name and percentage. Display the details
of the hash table. Also search for a specific student and display percentage of that
student.
---------------refer book----------------
------------SLIP19-------------
1. Create an Applet which displays a message in the center of the screen. The
message indicates the events taking place on the applet window. Handle various
keyboard related events. The message should update each time an event occurs. The
message should give details of the event such as which key was pressed, released,
typed etc. (Hint: Use repaint(), KeyListener).
---------------refer text---------------------
2. Accept “n” integers from the user and store them in a collection. Display them in
the sorted order. The collection should not accept duplicate elements (Use suitable
collection). Search for a particular element using predefined search method in the
collection framework.
import java.io.*;
import java.util.*;
class slip19
{
public static void main(String args[])throws Exception
{
DataInputStream d=new DataInputStream(System.in);
TreeSet t=new TreeSet();
System.out.println("Enter n");
int n=Integer.parseInt(d.readLine());
System.out.println("Enter the elements");
for(int i=1;i<=n;i++)
{
int a=Integer.parseInt(d.readLine());
t.add(new Integer(a));
}
System.out.println("the elements in sorted order");
System.out.println(t);
/*System.out.println("Enter element to search from collection");
int z=Integer.parseInt(d.readLine());
int p=Collections.binarySearch(t,z);
System.out.println("the element is found at"+p);*/
}
}

------------SLIP22-------------
1. Write a menu driven program to perform the following operations. Accept
operation accept the two numbers using input dialog box. GCD will compute the
GCD of two numbers and display it in message box and Power operation will
calculate the value of an and display it in message box where “a” and “n” are two
inputted values.
Operation Compute
Accept GCD
Exit Power
---------------refer book------------------------
2. Create a JSP page which accepts user name in a text box and greet the user
according
to the time on server side. Example: Input : User Name: ABC Output : Good
Morning ABC/ Good Afternoon ABC / Good Evening ABC
---------------refer book------------------------

------------SLIP25-------------
1. Define a class Employee having members – id, name, department, salary. Define
default and parameterized constructors. Create a subclass called Manager with
private member bonus. Define methods accept and display in both the classes. Create
“n” objects of the Manager class and display the details of the manager having the
maximum total salary (salary + bonus).
---------------refer notebook---------------------
2. Write a program to create a shopping mall. User must be allowed to do purchase
from two pages. Each page should have a page total. The third page should display
a bill, which consists of a page total of whatever the purchase has been done and
print the total. (Use HttpSession servlet code).
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class shoppingmoll extends HttpServlet


{

public void doGet(HttpServletRequest req, HttpServletResponse resp)


throws IOException, ServletException
{
resp.setContentType("text/html");
PrintWriter pw=resp.getWriter();
HttpSession session ;
String nb=session.getAttribute("nb");
int pn=Integer.parseInt(session.getAttribute("pn"));
int p3=Integer.parseInt(req.getParameter("t3"));
int p4=Integer.parseInt(req.getParameter("t4"));
pw.println("p1="+p3);
pw.println("p1="+p4);
pw.println("p1="+nb);
pw.println("p1="+pn);
int total=p3+p4;
pw.println("total amount ="+total);
}
}screen1.html
<html>
<body>
<form name=f1 method=get action="http://localhost:8080/ty/screen2.html">
notebook<input type="text" name="t1" value=""><br>
pains<input type="text" name="t2" value=""><br>
<input type="submit" name="b1" value="submit">
session.setAttribute("nb",t1);
session.setAttribute("pn",t2);
</form>
</body>
</html>
Screen2.html
<html>
<body>
<form name=f1 method=get action="http://localhost:8080/ty/shoppingmoll">

bags<input type="text" name="t3" value=""><br>


pd<input type="text" name="t4" value=""><br>
<input type="submit" name="b2" value="submit">
</form>
</body>
</html>

You might also like