Quiz Space

Java OPPE 1: September 2024 (September 2024 term)

Question 1

+25 marksProgramming

In a publication system, Author a1 contributes to a set of books. Author a2 also contributes to all the books contributed by a1 except for the second book, which a2 replaces with another book. Write a program that defines two classes Author and PublicationSystem. Define a copy constructor to create a2 from a1 such that changing the values of instance variables of either a2 or a1 does not affect the other one. The program accepts the name of author a2 and the new book contributed by a2 as input.

  • Class Author has/should have the following members.
    • Private instance variables String name and String[] books to store the author name and the books contributed, respectively
    • Define the required constructor(s)
    • Accessor methods getName() and getBook(int) to get the author name and the book at a specific index, respectively.
    • Mutator methods setName(String) and setBook(int, String) to set the author name and the book at a specific index, respectively.
  • Class PublicationSystem has method main that does the following.
    • Two objects of Author, a1 and a2, are created. a2 is created using a1.
    • The name of Author a2 and the second book contributed by a2 are updated by taking the input.
    • Finally, the names of a1 and a2 and the second book contributed by a1 and a2 are printed.

What you have to do:

  • Define a constructor to initialize the instance variables in class Author.
  • Define a copy constructor to create a deep copy of another Author object in class Author.

Question 2

+25 marksProgramming

You are given two integers as input to form an object r1 of type Rectangle, and two double values as input to form an object r2 of type Rectangle. Complete the Java code to print the larger area among the areas of r1 and r2.

  • Define a generic class Rectangle with the following members.
    • Instance variables length and breadth
    • Constructor to initialize the instance variables
    • Method area() that returns the area of a rectangle object
    • Method compareArea() that returns the larger area among that of r1 and r2.
  • Class Test has method main(), and takes two integers and two double values as input to create two objects of Rectangle type. It then invokes the necessary methods and prints the larger area.

What you have to do:

  • Define methods area() and compareArea() of class Rectangle.

Question 3

+25 marksProgramming

Complete the Java code that uses the concept of inheritance to demonstrate dynamic method dispatching.

Class WaterBody has the following members:

  • Private instance variable name
  • Constructor to initialize name
  • Accessor method for name
  • Method display to display the text: Inside an anonymous body of water

Classes River and Lake should be defined in such a way that any object of River or Lake can be assigned to a reference variable of type WaterBody. See the main method to understand the context.

  • For an object of River, method display should print the message Inside river followed by the name of the river.
  • For an object of Lake, method display should print the message Inside lake followed by the name of the lake.

What you have to do:

  • Define an accessor method for name inside class WaterBody
  • Define method display inside class WaterBody
  • Define classes River and Lake

One more question in this paper

Sign in with Google — it is free — to see every question with its answer and explanation, practise it in learning mode, or take it as a timed mock test.

More on the Java OPPE 1 Sept 2024 paper

The IIT Madras BS Programming Concepts using Java (Java) OPPE 1 paper sat on Sept 2024, in the September 2024 term: 4 questions for 100 marks in 180 minutes. The first 3 questions are below. Sign in with Google — it is free — to see the whole paper with its answers and explanations, in learning mode or as a timed mock test.

FeatureJava OPPE 1 Sept 2024 at a glance
TermSeptember 2024 term
SubjectProgramming Concepts using Java
Course codeBSCS2005
Questions4
Marks100
Duration180 min
Programming4
Official paperOPPE 1, Sep 2024
Negative markingNo negative marking.
Updated

Same OPPE 1, other subjects

More Java