Vous êtes sur la page 1sur 5

College of Computing Sciences and Information

Technology
Bagarpur, Delhi Road, Moradabad-244001 (U.P.)

Web Technologies and Java Programming Lab


BCA 651
Lab Assignment 2
Program related to Package and interfaces
1. Create a package named Maths. Define class MathsOperations with static
methods to find the maximum and minimum of three numbers. Create another
package Stats. Define class StatsOperations with methods to find the average
and median of three numbers. Use these methods in main to perform
operations on three integers accepted using command line arguments
2. Write a Java program to create a Package SY which has a class SYMarks
(members ComputerTotal, MathsTotal, and ElectronicsTotal). Create another
package TY which has a class TYMarks (members Theory, Practicals). Create n
objects of Student class (having rollNumber, name, SYMarks and TYMarks). Add
the marks of SY and TY computer subjects and calculate the Grade (A for >=
70, B for >= 60 C for >= 50 , Pass Class for > =40 else FAIL) and display
the result of the student in proper format.
3. Create an interface, "PrimeTester", that defines one method "boolean
isPrime(int n)". When this function is called the implementing class should
determine if the given "n" is prime or not.
4. Define an interface IntOperations with methods to check whether an integer
is positive, negative, even, odd, prime and operations like factorial and sum of
digits. Definea class MyNumber having one private int data member. Write a
default constructor to initialize it to 0 and another constructor to initialize it to a
value (Use this). Implement the above interface. Create an object in main. Use
command line arguments to pass a value to the object and perform the above
operations using a menu.
5. Define an interface StackOperations which declares methods for
stack. Define a class MyStack which contains an array and top
members and implements the above interface. Initialize the stack
constructor. Write a menu driven program to perform operations on
object.

a static
as data
using a
a stack

Program related to Exception Handling


6. Create a class Student with attributes roll no, name, age and course. Initialize
values through parameterized constructor. If age of student is not in between
15
and
21
then
generate
user-defined
exception
AgeNotWithinRangeException. If name contains numbers or special symbols
raise exception NameNotValidException. Define the two exception classes.

7. Define Exceptions VowelException , BlankException, ExitException.Write


another class Test which reads a character from command line. If it is a vowel,
throw VowelException,if it is blank throw BlankException and for a character 'X'
throw an ExitException and terminate program. For any other character, display
Valid character.
8. Define class MyDate with members day, month, year. Define default and
parameterized constructors. Accept values from the command line and create a
date object. Throw user defined exceptions InvalidDayException or
InvalidMonthException if the day and month are invalid. If the date is valid,
display message Valid date.
9. Define a class which contains method DisplayColor which takes one character
as argument. Raise an error if the character is not an alphabet. If the alphabet is
a color of the rainbow, display the color name. If it is any other alphabet, report
an error.
10.
Write a program which accepts two integers and an arithmetic operator
from the command line and performs the operation. Fire the following user
defined exceptions:
a. If the no of arguments are less than 3 then fire
IllegalNumberOfArguments
b. If the operator is not an Arithmetic operator, throw
InvalidOperatorException.
c. If result is ve, then throw NegativeResultException
Program related to Multithreading
11.
Write a multithreaded java program to print all number below 10000 that
are both prime and Fibonacci number. Design a thread that generates prime
number below 10000 and writes them into a pipe. Design another thread that
generates Fibonacci number and writes them to another pipe. The main thread
should read both the pipes to identify number common to both.
12.
To write a java program for generating two threads, one for generating
even number and one for generating odd number.
13.
To write a java program to develop a producer and consumer problem
using thread.
14.
Write a java program to create five threads with different priorities. Send
two threads of the highest priority to sleep state. Check the aliveness of the
threads and mark which thread is long lasting.
Program related to Input and Output
15.
ByteArrayInputStream create two byte array strams- one to represent our
sample string completely and other to represent only the first two words.
16.
Write a program to extract the tokens in a string passed in command line
and display the token along with its type.(using StreamTokenizer)
17.

Write a program that will imitate copying content of a file to another.

18.
Write a program to count the number of occurrence of the character & in
a file given in the command line.

19.
Write a java program to print the character at every fifth byte of a file
given in command line.
20.
Create a FileInputStream to represent the file in the command line. Read
byte by byte. Typecast the byte to character and check whether it is a &. If yes
increment the count.
21.
Write a program to determine whether the two files given in command
line are identical.(Using RandomAccessFile)

Write a program to input a word from the user and remove the duplicate characters present in it.
Example:
INPUT abcabcabc
OUTPUT abc
INPUT javaforschool
OUTPUT javforschl
INPUT Mississippi
OUTPUT Misp
Write a program to accept a sentence which may be terminated by either . ? or ! only. Any other character
may be ignored. The words may be separated by more than one blank space and are in UPPER CASE.
Perform the following tasks:
(a)
Accept the sentence and reduce all the extra blank space between two words to
a single blank space.
(b)
Accept a word from the user which is part of the sentence along with its
position number and delete the word and display the sentence.
Test your program with the sample data and some random data:
Example 1
INPUT:

MORNING WALK IS A IS BLESSING FOR THE WHOLE DAY.

WORD TO BE DELETED: IS
WORD POSITION IN THE SENTENCE: 6
OUTPUT:

A MORNING WALK IS A BLESSING FOR THE WHOLE DAY.

Example 2
INPUT:

AS YOU

SOW, SO SO YOU REAP.

WORD TO BE DELETED: SO
WORD POSITION IN THE SENTENCE: 4
OUTPUT:

AS YOU SOW, SO YOU REAP.

Given a time in numbers we can convert it into words. For example :


5 : 00 five oclock
5 : 10 ten minutes past five
5 : 15 quarter past five

5 : 30
5 : 40
5 : 45
5 : 47

half past five


twenty minutes to six
quarter to six
thirteen minutes to six

Write a program which first inputs two integers, the first between 1 and 12 (both inclusive) and second between
0 and 59 (both inclusive) and then prints out the time they represent, in words.
Your program should follow the format of the examples above.
SAMPLE DATA :
1. INPUT :
TIME : 3,0
OUTPUT : 3 : 00 Three o clock
2. INPUT :
TIME : 7,29
OUTPUT : 7 : 29 Twenty nine minutes past seven
3. INPUT :
TIME : 6,34
OUTPUT : 6 : 34 Twenty six minutes to seven
4. INPUT :
TIME : 12,1
OUTPUT : 12 : 01 One minute past Twelve
5. INPUT :
TIME : 12,45
OUTPUT : 12 : 45 Quarter to One
Ad by unisales | Close

Question:
The input in this question will consist of a number of lines of English text consisting of the letters of the English
alphabets, the punctuation marks () apostrophe, (.) full stop, (,) comma , (;) semicolon , (:) colon and white
space. Write a program to print the words of the input in reverse order without any punctuation marks other than
blanks.
For example, Consider the following input text:
INPUT:
Enter number of sentences: 2
Enter the sentences:
This is a sample piece of text to illustrate this question
if you are smart you will solve this right.
OUTPUT: right this solve will you smart are you if question this illustrate to text of piece sample a is this
NOTE : Individual words (i.e. characters of every word) are not reversed
Test your program for the following data and some random data:
Sample Input 1 :
Enter number of sentences: 1
Enter the text: Do not judge a book by its cover.
Sample Output: Cover its by book a judge not do

Sample Input 2:
Enter number of sentences: 2
Enter the text:
Emotions, controlled and directed to work, is character.
By Swami Vivekananda.
Write a program to input a string (word). Convert it into lowercase letters. Count and print the frequency of each
alphabet present in the string. The output should be given as:
Sample Input: Alphabets
Sample Output:
==========================
Alphabet
Frequency
==========================
a
2
b
1
e
1
h
1
l
1
p
1
s
1
t
1
swaps the values of two Strings without using any third (temp) variable.

Vous aimerez peut-être aussi