Mca N293 Java Lab Assignment
Mca N293 Java Lab Assignment
Mca N293 Java Lab Assignment
Run the following programs. Submit the codes + Screenshots of the outputs by
16th August, 2021 6 pm.
1. Write a program to accept a string from the user and find out the following statistics:
Count of uppercase character
Count of lowercase character
Count of digits
Count of spaces
2. Create a class called Time, which has three private instance variables – hour, min and sec. It
contains a method called add ( ) which takes one Time object as parameter and print the added
value of the calling Time object and passes Time object. In the main method, declare two Time
objects and assign values using constructor and call the add().
3. Define an exception called “NoMatchFoundException” that is thrown when a string is not equal
to “University”. Write a program that uses this.
4. Write a program to create a class named shape. In this class we have three sub classes circle,
triangle and square each class has two member function named draw () and erase (). Create
these using polymorphism concepts.
5. Write a java program to create an abstract class named Shape that contains two integers and an
empty method named printArea(). Provide three classes named Rectangle, Triangle and Circle
such that each one of the classes extends the class Shape. Each one of the classes contain only
the method printArea( ) that prints the area of the given shape.
6. Write a program to create a class named Vehicle having protected instance variables
regnNumber, speed, color, ownerName and a method showData ( ) to show “This is a vehicle
class”. Inherit the Vehicle class into subclasses named Bus and Car having individual private
instance variables routeNumber in Bus and manufacturerName in Car and both of them having
showData ( ) method showing all details of Bus and Car respectively with content of the super
class’s showData ( ) method.
7. Write multithreaded program that continuously prints the strings “ping” and “PONG” in the
console at random distances at intervals of one second. Use two threads one for “ping” and
another for “PONG”.
9. Create a class Stack that declares a stack and the methods to perform push ( ), pop ( ) and
checkEmpty ( ) operations on the stack. Create two stacks and write a menu-driven program to
perform operations on the two stacks. Whenever the number of elements in the two stacks
becomes equal, a message should automatically be generated displaying the number of
elements in each stack.
10. Write a program that displays all integers between the low and high that are the sum of cube of
their digits. In other words, find all numbers XYZ such that XYZ=X3+Y3+Z3. try 100 for low and
1000 for high.