OOPS Lab-5

Post date: Oct 24, 2017 6:23:26 AM

Write an algorithm and a JAVA program involving Class Inheritance for a simple book information system as specified below:

- Create a base class Info that can store the following attributes [i.e. data items] name (of type string) , author (of type string) and year (of type integer). This class can contain a constructor to set the values for the attributes name, author and year. This class contains another method to display the name, author and year.

- Create a derived class Book that extends the base class. This class can store an attribute categorycode of type integer. (Assume that the categorycode can have a value 1 or 2 or 3 when an object is created). This class can contain a constructor to set the values for name, author, year and categorycode. This class contains another method to display the name, author, year, categorycode. It also prints one of the following messages according to the value of categorycode:

If categorycode=1, it displays the message, “Philosophy”.

If categorycode=2, it displays the message, “Novel-Fiction”.

If categorycode=3, it displays the message, “Autobiography”.

-Create a Class Inheritance_Testing. This class can store the main function. Now you create the following three objects for the class Book:

“The Firm” “John Grisham 1991 2

“My Experiments with Truth” “M. K. Gandhi” 1925 3

“By Parallel Reasoning” “Paul Bartha 2010 1

Now print all these objects along with their appropriate messages.

RECURSION IMPLEMENTATION in JAVA

Write a JAVA program to implement Ackerman’s function. A function of two parameters whose value grows very fast.

Formal Definition:

A(m, n) =

  • n+1, for m = 0 & n ≥ 0
  • A(m-1, 1), for n = 0 & m > 0
  • A(m-1, A(m, n-1)), for m> 0 & n > 0 .

m = 0

m > 0, n = 0

m > 0, n > 0

A(0, n) = n+1

A(m, 0) = A(m-1, 1)

A(m, n) = A(m-1, A(m, n-1))

Test Inputs & expected Results for your JAVA Program

(Note: You will give only 2 input values: say m=3 n=9; Output is 4093)