Quiz Space

Programming Concepts using Java OPPE 1: 26 June 2022 (May 2022 term)

Question 1

+25 marksProgramming

Tourists t1 and t2 visit a set of tourist places in India. Tourist t2, besides visiting all the tourist places visited by t1, also visits an additional place. Write a Java program that models this scenario using a copy constructor. The code should take as input the name of Tourist t1 and the two tourist places visited by t1, followed by the name of Tourist t2 and the additional place visited by t2.

  • Class Tourist has tName, tPlaces as instance variables.
    • It should have two parameterized constructors, one to instantiate the instance variables and the other is a copy constructor.
    • Implement the copy constructor public Tourist(Tourist t) so that any later change in the visited places of Tourist t2 does not affect the visited places of t1.
    • Override the method toString() to display the output as shown in the test cases.
  • Class TravellerTest has the main method.
    • It accepts the names of the tourists, places visited by t1 and the additional place visited by t2 as input.

Question 2

+25 marksProgramming

Complete the Java program to compute the area of a rectangle. The inputs for the program are the x and y coordinates of the points denoting the top-left corner and that of the bottom-right corner of the rectangle.

  • Class Rectangle has/should have the following members:
    • Two instance variables cp1 and cp2 of type Point, where Point is a private class inside class Rectangle.
    • Constructor Rectangle(int, int, int, int), where the arguments are in the order: x-coordinate and y-coordinate of one corner, x-coordinate and y-coordinate of the opposite corner of a rectangle.
    • Methods int getWidth() and int getHeight() compute the width and the height of the rectangle respectively. These should compute the absolute values (if needed, use a method from the Math class).
    • Class Point is an inner class with two instance variables x and y, and a constructor to initialize them.
  • Class PvtClass has the main method that reads in all the four coordinates in the following order: x-coordinate and y-coordinate of one corner, x-coordinate and y-coordinate of the opposite corner of a rectangle. It then creates a new Rectangle object using these coordinates, and finds its area.

Question 3

+25 marksProgramming

Complete the Java program that defines three classes Person, Employee and Student. The classes Employee and Student inherit from Person. The input to the program is the number of persons, followed by, for each person, an integer indicating the type of person (1 for Person, 2 for Employee and 3 for Student), a name and a number (if the type is Employee or Student) that denotes the salary of an Employee or the semester of a Student. Your program should implement a method printAll that is capable of printing a list of objects, each of which may be of type Person, Employee or Student.

  • Class Person has been defined.
  • Define class Employee, which has an additional instance variable (as compared to class Person) salary of type double, and overrides the method show of class Person. Write the appropriate constructor for the same.
  • Define class Student, which has an additional instance variable (as compared to class Person) semester of type int, and overrides the method show of class Person. Write the appropriate constructor for the same.
  • Class TClass has two methods, main and printAll. Complete the definition of method printAll that accepts a list of the following types only: List<Person>, List<Employee> and List<Student>, and prints the objects using method show.

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 26 Jun 2022 paper

The IIT Madras BS Programming Concepts using Java (Java) OPPE 1 paper sat on 26 Jun 2022, in the May 2022 term (T2 2022): 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 26 Jun 2022 at a glance
TermMay 2022 term (T2 2022)
SubjectProgramming Concepts using Java
Course codeBSCS2005
Questions4
Marks100
Duration180 min
Programming4
Official paperOPPE 1, 26 Jun 2022
Negative markingNo negative marking.
Updated

More Java