Quiz Space

Programming Concepts using Java OPPE 1: Undated (undated)

Question 1

+25 marksProgramming

Write a program that, given a string s as input, prints the string obtained by removing all duplicate characters from s (that is, retain only the first occurrence of each character). The characters should appear in the output in the same order as they appear in s.

Note: str.charAt(arg) returns the character present at index arg in the string str.

Sample input 1: eerie, output: eri

Sample input 2: abcd, output: abcd

Question 2

+25 marksProgramming

It has been decided to give a promotion to one of the four employees in the Sales department of a company based on the following criteria. An employee with the maximum number of years of experience is considered the ideal candidate for promotion. If two employees have the maximum experience, then the one who has taken the minimum number of days of leave will be considered for promotion. Assume that no two of them have taken the same number of days of leave.

Class Employee must implement the interface Comparable, and should have the following members.

  • Instance variables: ID (employee ID), experience (number of years of experience), nleaves (number of days of leave taken so far)
  • Override the method equals(Object o) such that it returns true if the two employees being compared have the same ID; else, return false.
  • Override the method compareTo to compare two Employee objects, based on experience and nleaves.

Class Company has two methods:

  • The method main() accepts the inputs to instantiate four objects of Employee type. The input is accepted in the order ID, experience, and nleaves, for each employee. It then invokes the method displayID(e), which returns the ID of the employee who gets the promotion, by using the method compareTo(Employee e) inside the class Employee.

Question 3

+25 marksProgramming

Write a program that, given the x and y coordinates of two points p1(x1, y1) and p2(x2, y2) on a two-dimensional plane, finds the mid-point p3(x3, y3) of the line segment formed by p1 and p2 using the formula:

x3 = (x1 + x2) / 2 and y3 = (y1 + y2) / 2

Class Point has the following members.

  • Instance variables x and y
  • A constructor to initialize x and y
  • A method mid(Point p) to return the mid-point of the line segment joining the current point to p
  • A method that overrides the method toString() in the Object class to format the output

Class Test has the main method.

  • The main method accepts the two input points. The first line of input will be x1 and y1 of point p1(x1, y1). The second line of input will be x2 and y2 of point p2(x2, y2). It then invokes the method mid of one of the objects.

Sample input 1: 3 4 and 5 6, output: (4,5)

Sample input 2: -3 4 and -5 6, output: (-4,5)

5 more questions 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 Undated paper

The IIT Madras BS Programming Concepts using Java (Java) OPPE 1 paper sat on Undated, in the Undated: 8 questions for 200 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 Undated at a glance
TermUndated
SubjectProgramming Concepts using Java
Course codeBSCS2005
Questions8
Marks200
Duration180 min
Programming8
Official paperOPPE 1, Additional
Negative markingNo negative marking.
Updated

More Java