Sie sind auf Seite 1von 12

LAB EXERCISE - I

1. Try out the Listing 1.1 to 1.3 in order to understand the procedure for creating an applet
and an application.
2. Store a string in the form of an array and find out whether the string is a palindrome or
not.
3. Write a program which tells whether a number is even or odd. Take a range from 1 - 50.
4. Display the output which is given below:
*
**
***
5. Write a program which sorts an array of type integer.
6. Write a program which prints out the square of odd numbers, the even numbers are
skipped. Use a range between 1 - 20.
7. Write a program to display fibonacci series which is given here: 1,1,2,3,5,8,13

Compiled by Logic Option Pvt. Ltd.

Page 1 of 12

LAB EXERCISE - II
1. Create a class called Employee that will have the following attributes:
Employee Number
Name
Address
Date of Birth
Hiredate
The class must have the following methods also:
i) A constructor that accepts nothing and initializes all numeric attributes with 0
and String with null
ii) A constructor that accepts all attribute values
iii) A method called display() that displays all attributes
iv) A method called changeAddress(String address) that changes the address of
an employee
Create two subclass of Employee class called Wagers and Salaried. The Wagers
should have additional attributes as days worked and salary per day. The Salaried
should have additional attributes as basic salary, da, hra, pf, and other deductions.
Both of these classes should have display() methods of their own that displays all
details of an employee and the type of employee (Salaried or Wager).
i) Test the methods of Employee class.
ii) Test the display() method of all three classes.
iii) Create an object of Wagers class and another object of Employee class. Type
cast the object of Wagers class to an object of Employee class.
iv) Create two objects of a class that have identical information and use ==
operator to check if it gives you the right result.
2. Write a program that accepts numeric command line arguments and adds all of them.
For example, if the argument list is:
100 100 134 150 300 200
The output should be:
984
3. Print all the methods and constructors of Button class.
4. Study the case study given below and create the broad outline of the classes in it. Human
Resource Department of ABC Ltd. handles nearly 10 applications per employee everyday.
Errors in filling forms translate into lost-time and money. They want to automate the task
of employee filling the forms correctly without any errors so that they can be further
processed and added to the database. The employee has to fill all the related forms (not
necessarily in any sequence). We will curtail the number of forms to be filled up (for the
purpose of cutting down the problem domain). There are two forms: ABC Ltd Provident
Fund Scheme and Employee Information Sheet.
Compiled by Logic Option Pvt. Ltd.

Page 2 of 12

Compiled by Logic Option Pvt. Ltd.

Page 3 of 12

We will continue with the case study in the coming sessions.

Compiled by Logic Option Pvt. Ltd.

Page 4 of 12

LAB EXERCISE III


1. Create an abstract class called figure which has an abstract method called draw(). make
the subclasses called Filled_Rectangle, Filled_Arc and override the draw() function in
which you would just print the massage regarding the current object. (You can later on
use the same example in AWT to create actual objects)
2. Create an interface called Shape which should have a constant - pie, a method prototypes
for - calcArea(). Create three classes - Rectangle, Circle and Square which implement this
interface and has a method called getDimensions(). Print the area of all the three shapes.
3. Create a package called easy which has a class called StringFunctions . It has the
functions - replicate(char c, int times), upper(char c), lower(char c), substr(String s, int
start, int length). Create another class outside this package which uses these functions.
4. Create a package which has the following components:
class Course
data members
courseName
courseDuration
courseFee
member functions
getCourseDetails()
printCourseDetails()
Interface Activity
Declare your own constants
dance(western, folk)
sports(cricket,badminton)
arts(painting, handicraft)
none(no participation)
(create the constants for each suboption in dance, sports and arts appropriately)
Create a class called Student which extends from Course and implements Activity. It has
rollNo, studentName as the data members, and getDetails() and printDetails() as member
functions. The printDetails() function should display the students particulars, the course
he has taken and the extra activities in which he has participated( make use of the
interfaces constants).

Compiled by Logic Option Pvt. Ltd.

Page 5 of 12

LAB EXERCISE IV
1. Draw a rectangle in an applet filled with red color. The dimensions and starting point of
the rectangle should be accepted from the HTML file. If no dimensions are given, draw
the rectangle having a width of 250 and height of 150 at (10,10) position.
2. Create an applet having the background color as pink. The applet should display an image
in its original size and the same image in half of its original size.
3. Add a sound file to the applet created in Q2. The sound file should be played in a loop
and should stop once the user stops the applet and restart when the user starts the applet
again.
4. Use Java2D to create applets that:
i) display this symbol.

ii) defines a stroke that is 15 pixels wide, having a round shape at the end of the
stroke and round shape again at the join and draw the same symbol again.
iii) draws the same symbol having different dash phases.
iv) fills the inner half circles with a diagonal gradient fill and the outer circle with
horizontal gradient fill. Use different fill colors.

Compiled by Logic Option Pvt. Ltd.

Page 6 of 12

LAB EXERCISE V
1. Create an application which accepts two strings as command line arguments. It checks for
the number of command line arguments. If they are less or more it throws an exception
object giving an appropriate message.
2. Create an application that has integer variables a, b and c and result as float. Store some
values in them and apply the formula result = a / (b-c). Catch the probable exception.
3. Create an application that accepts some numbers, maximum five, from the command line.
It stores them in an array called marks and then adds 2% marks more to each element. It
then displays the average of the marks obtained. Zero/es can also be entered as command
line argument as a student may not have appeared in an exam/s. Catch the probable
exception/s.
4. Create an application that contain two classes - Temp and Caller. The Temp class has a
function disp() which displays any message. The Caller class has the main() method
which has only two statement Temp obj = null , and the next statements as obj.disp().
What is the exception being raised and how would you handle it, first by using trycatch
block and then using throws clause. What happens if you do not use throws clause in the
second case?

Compiled by Logic Option Pvt. Ltd.

Page 7 of 12

LAB EXERCISE VI
1. Create an applet in which the text Java Platform 2 moves from right to left. The
moment entire text has moved past the left hand side of the screen, it should reappear
from the right side. First use overriding of update() method to remove flickering.
2. Create any animation of you choice. Add a sound file to the background. (Use any audio
and picture files).
3. Create an animation in which a ball moves back and forth in the following way:

Use double-buffering to eliminate flickering.


4. Write an application that creates four threads. The first thread prints fibonacci numbers
less than 400, the second thread prints prime numbers less than 400, the third thread
prints a string Welcome 400 times and the fourth thread prints a string Java 2 300
times. Assign the following priorities to the threads:
Thread 1 1
Thread 2 10
Thread 3 5
Thread 4 5
Now run the program and see which thread finishes last.

Compiled by Logic Option Pvt. Ltd.

Page 8 of 12

LAB EXERCISE VII


1. Create an applet which prompts for the user to enter the username and password. The
labels should be in the font Dialog, Bold and 16 pt, the text fields should be in the font
TimesRoman, Regular and 14 pts.. The background colour of the text fields is cyan and
the foreground colour is blue. The applets background colour should be green.
2. Create a GUI like the one given below. Decide the fonts for the heading and the labels.
Customer address should be accepted in a text area. The gender can either be male or
female, the booking type is a choice control, Train number is a list box and push buttons
for generate etc. are given at the right side. You will not be handling any events in this
exercise.

3. Create a panel and attach card layout to it. Create 2 panels more each of which is
containing a question( true/false question whose answer is submitted by using a check
box and multiple choice question whose answer is submitted by using a radio button).
Display these panels one by one programmatically. (After completing the next session
apply event handling to traverse through these panels during runtime)
4. Design the GUI interface to design the application for Case Study in session 2.Your
interface should look like

Compiled by Logic Option Pvt. Ltd.

Page 9 of 12

Compiled by Logic Option Pvt. Ltd.

Page 10 of 12

LAB EXERCISE VIII


1. To implement the GUI for case study in session 7 handle the following events.
Users should use drop-down menu to select any application. Based on the
application selected, the details of filling up the form should be displayed in the
text area above and the appropriate application should get displayed below. In
case of big forms, a scroll bar should be provided in the lower frame that is the
Application Form area. Include validation for entry of values and display
appropriate error messages using dialog boxes.
If the user presses Clear button then display a dialog box with message Are
you sure and yes and no buttons. In case user presses no then come back
to screen otherwise clear the application screen entries.
If the user presses Quit button then close the application.
Additional Exercise
2. Create a menu that has the following menu options:

i) The menu options Close, Save, and Save As should disabled in the beginning and
should be enabled only when New or Open is clicked.
ii) From the View menu option, respective dialog boxes should be invoked as shown
in the figure. For doing this you must define only one subclass of Dialog class and
use it in your program to display all three types of dialog boxes.

Compiled by Logic Option Pvt. Ltd.

Page 11 of 12

LAB EXERCISE IX
1. Create a file stream which writes to a file called parts.dat . This file contains the details of
a part like the partcode - int, qty_avail - int, rate - float. After writing to the file it displays
the contents of the file.
2. Take any file of your file system or find out whether it contains some bytes. If it is not
empty, read and display its contents using the buffered streams.
3. Accept a directory name as a string from the user and validate whether the string is a
directory or not. If it is a directory, then display the list of files and directories under it
distinguishing the files and directories by giving a remark along with their names.
4. Create a random file called salesman.txt that stores the, salesmanID - int and the
compensation - float, given to a particular salesman. Display the record of a particular
salesman.
5. Create a class called Orders that has the following elements:
Data Members
order_No - char
invoice_Number - int
order_Description - char
order_Quantity - float
Member Functions
getDetails()
showDetails()
Serialize this class, add some order details and store in a file called orders.txt . After
that print the order details.
6. Continuing with case study in session 8 handle the event for button Save Form. For
Employee Information sheet save the form objects in employee.txt file and clear the
screen. For Provident Fund save the form objects in pf.txt file and clear the screen.
Additional Exercise
7. Provide button Admission List in SInterface.java which when clicked on displays
details of the student (that is selected applicants) with their Student roll number,
CourseName and optional subject.
8. Modify class CreateOkDialog so that the along with the message to be displayed the
window name can also be passed at run time.

Compiled by Logic Option Pvt. Ltd.

Page 12 of 12

Das könnte Ihnen auch gefallen