0% found this document useful (0 votes)
7 views5 pages

Practical Questions

Important Topics2

Uploaded by

Anil Kumar B
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views5 pages

Practical Questions

Important Topics2

Uploaded by

Anil Kumar B
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Practical Questions

Module-1
1) There is a telecommunication company called “Powered Air” who have approached you to
build their Interactive Voice Response (IVR) system. write a Java program and be able to
provide the following menu (given below):
Note: User should provide an input for each menu display. Welcome to Powered Air service.
What would you like to do?
a. Know my balance. b. Know my validity date
c. Know number of free calls available. d. More
1. Prepaid Bill Request 2. Customer Preferences 3. GPRS activation
4. Special Message Offers 5. Special GPRS Off ers 6. 3G Activation
7. Go back to Previous menu
You are free to display your own messages in this IVR.
2) Create a class Rectangle. The class has attributes length and width. It should have methods
that calculate the perimeter and area of the rectangle. It should have read Attributes method
to read length and width from user.
Hint: Area of rectangle = length * width, Perimeter of rectangle = 2*(length+width).
3) Implement a Java Program that reads a line of integers, and then displays each integer, and
the sum of all the integers (use String Tokenizer class).
4) Implement a java program to print all tokens of a string on the bases of multiple separators
(use String Tokenizer class).
5) Using inheritance, one class can acquire the properties of others. Consider a class Animal
that has only one method “walk”. Next, create a Bird class that also has a fl y method. Finally,
create a bird object that can both fl y and walk.
6) Using inheritance, Write the following code in your editor :
1. A class named Arithmetic with a method named “add” that takes integers as parameters and
returns an integer denoting their sum.
2. A class named Adder that inherits from a super class named Arithmetic.
Note: Your classes should not be Public.
7) When a subclass inherits from a super class, it also inherits its methods; however, it can also
override the super class methods (as well as declare and implement new ones). Consider the
Sports class having methods get Name()[which returns name of sport] and get Number Of
Team Members()[which returns no of team members] create a Soccer class that inherits from
the Sports class. We can override get Name method and return a different subclass-specific.
8) string and override getNumberOfTeamMembers method and return no of team members
Implement a java program to create an abstract class named Shape that contains an empty
method named number Of Sides ( ).Provide three classes named Trapezoid, Triangle and
Hexagon such that each one of the classes extends the class Shape. Each one of the classes
contains only the method number Of Sides ( ) that shows the number of sides in the given
geometrical figures.
9) You are given an interface Advanced Arithmetic which contains a method signature int
divisor_sum(int n). You need to write a class called My Calculator which implements the
interface. divisor_sum function just takes an integer as input and return the sum of all its
divisors. For example divisors of 6 are 1, 2, 3 and 6, so divisor_sum should return 12. The
value of n will be at most 1000.
10) Implement a Java program for the following
a) Creation of simple package.
b) Accessing a package.
11) Implement a Java program to read two numbers a,b from user and perform division a/b,if the
user passes b value as zero, handle the exception using try and catch otherwise display the
result.
12) Create a class called Customer with data members account_number, balance (initialize with
10000), and member functions print(), deposit(), and withdraw(). Print method display account
number and balance. If withdraw amount is less than current balance while withdrawing,
throw an exception “In Suffi cient Funds”. If the input is 1 do print. If the input is 2 withdraw
(). If the input is 3 deposit. If the input is 4 terminate program.
13) Implement a Java program which accepts age as input from the user and throws an exception
“Not Eligible to Vote” when age is <=18 otherwise print “Eligible to Vote”.
Module-2
1) Print in Order
Suppose we have a class:
public class Foo {
public void fi rst() { print(“fi rst”); }
public void second() { print(“second”); }
public void third() { print(“third”); }
}
The same instance of Food will be passed to three different threads. Thread A will call first(),
thread B will call second(), and thread C will call third(). Design a mechanism and modify the
program to ensure that second() is executed after first(), and third() is executed after second().
Note: We do not know how the threads will be scheduled in the operating system, even though
the numbers in the input seem to imply the ordering. The input format you see is mainly to
ensure our tests’ comprehensiveness.
Example 1:
Input: nums = [1,2,3] Output: “first second third”
Explanation: There are three threads being fi red asynchronously. The input [1,2,3] means
thread A calls first(), thread B calls second(), and thread C calls third(). “first second third” is
the correct output.
Example 2:
Input: nums = [1,3,2] Output: “first second third”
Explanation: The input [1,3,2] means thread A calls first(), thread B calls third(), and thread C
calls second(). “first second third” is the correct output.

2) Flood Fill:
An image is represented by an m x n integer grid image where image[i][j] represents the pixel
value of the image. You are also given three integers sr, sc, and color. You should perform a
flood fill on the image starting from the pixel image[sr][sc].
To perform a flood fill, consider the starting pixel, plus any pixels connected 4-directionally to
the starting pixel of the same color as the starting pixel, plus any pixels connected 4-directionally
to
those pixels (also with the same color), and so on. Replace the color of all of the aforementioned
pixels with color.
Return the modified image after performing the flood fill.
111222
110220
101201
Example 1:
Input: image = [[1,1,1],[1,1,0],[1,0,1]], sr = 1, sc = 1, color = 2
Output: [[2,2,2],[2,2,0],[2,0,1]]
Explanation: From the centre of the image with position (sr, sc) = (1, 1) (i.e., the red pixel),
all pixels connected by a path of the same color as the starting pixel (i.e., the blue pixels) are
colored with the new color.
Note the bottom corner is not coloured 2, because it is not 4-directionally connected to the
starting pixel.
Example 2:
Input: image = [[0,0,0],[0,0,0]], sr = 0, sc = 0, color = 0
Output: [[0,0,0],[0,0,0]]
Explanation: The starting pixel is already colored 0, so no changes are made to the image.

3) Count words in a given string


The input parameter is a list of strings representing lines of text.
Count how often the word occurs in the text.
If the word “kitten” occurred in a text 23 times, then its entry would be “kitten - 23\n”. Return
statistics as a String containing all the entries.
Omit all words which contain less than 4 letters and appear less than 10 (the words which are
too small or to rare) The entries in the resulting String should be also sorted by their amount
and then in alphabetical order if it is needed.
4) Implement a Java program for handling mouse events when the mouse entered, exited,
clicked, pressed, released, dragged and moved in the client area.

5) Implement a Java program for handling key events when the key board is pressed, released,
typed.

6) Implement a Java swing program that reads two numbers from two separate text fields and
display sum of two numbers in third text fi eld when button “add” is pressed.

7) Implement a Java program to design student registration form using Swing Controls. The
form which having the following fields and button “save”. Form Fields are: Name, RNO,
Mail id, Gender, Branch, and Address.

8) Implement a java program using swings to design a multiple choice question having three
options (use radio button) ,display the message using dialog box “Your answer is wrong” if
the user selects wrong option otherwise display ,”Your answer is correct.”

You might also like