0% found this document useful (0 votes)
1 views

Programming Assignment VIII

Uploaded by

smrutipanda0422
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Programming Assignment VIII

Uploaded by

smrutipanda0422
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Programming Assignment-VIII

(Programming using JAVA)


(Abstract Class & Interface)

1. Create an abstract class Shape and the derived classes Square, Triangle
and Circle. Write a Java program to display area of different shapes.
2. Define an interface to declare methods display ( ) & count ( ). Another
class contains a static data member maxcount, instance member name &
method display( ) to display name of a person, count the no. of characters
present in the name of the person.
3. Define an interface EmpInterface (void displayEmp(), void
giveBonus(double amount)). Define an abstact class Employee (empID,
fName, lName, salary). Define a concreate class Manager (bonus)
subclass of Employee and define the interface methods. Perform the
followings:
a. Define the appropriate constructor in class hierarchy.
b. Create an array of interface reference variables and populate with
manager objects.
c. Write a Test class to implement the above said requirements of interface
implementation.
4. Define a polygon interface that has methods area( ) and perimeter( ).
Then implement classes for Triangle, Rectangle and Square which
implement this interface, with the obvious meanings for the area( ) and
perimeter( ) methods. Write a simple user interface, which allows users to
create polygons of the various types, input their geometric dimensions,
and then output their area and perimeter.
5. Write a Java program to read your lucky number from keyboard. Treat
–ve noumber as NumberFormatException. Write appropriate Exceptional
handler.
6. Create a class Student & enter mark, name of the student. If mark is
more than 100, create exception MarksOutOfBoundException & throw it
using Java.
7 Write a recursive method in Java which, given real value x and a positive
integer n, returns the value of xn .
8. Write a recursive method in Java to return the greatest common
divisor(GCD) of two integers m and n, given that in general,
gcd(m,n)=gcd(n, m mod n).
9. The sequence of numbers 1, 1, 2, 3, 5, 8, 13 etc are called Fibonacci
numbers, each is the sum of the preceding two. Write a recursive method
in Java which, given n, returns the nth Fibonacci number.
10. In the Towers of Hanoi puzzle, we are given a platform with three
pegs, A, B, and C, sticking out of it. On peg A is a stack of n disks, each
larger than the next, so that the smallest is on the top and the largest is on
the bottom. The puzzle is to move all the disks from peg A to peg C,
moving one disk at a time, so that we never place a larger disk on top of a
smaller one. Write a recursive program using Java for solving the Towers
of Hanoi puzzle for arbitrary n. (Hint: Consider first the subproblem of
moving all but the nth disk from peg A to another peg using the third as
“temporary storage.”)

You might also like