0% found this document useful (0 votes)
29 views261 pages

OOP Java Lab MCQs and Coding Tasks

The document is an assessment report for a student named Abhinandan ER from Rajalakshmi Engineering College, detailing their performance in an Object-Oriented Programming lab course. It includes multiple-choice questions (MCQs) with answers, marks obtained, and statuses indicating whether the answers were correct or wrong. The total marks for the assessment were 15, with the student scoring 9.

Uploaded by

erabhinandan525
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views261 pages

OOP Java Lab MCQs and Coding Tasks

The document is an assessment report for a student named Abhinandan ER from Rajalakshmi Engineering College, detailing their performance in an Object-Oriented Programming lab course. It includes multiple-choice questions (MCQs) with answers, marks obtained, and statuses indicating whether the answers were correct or wrong. The total marks for the assessment were 15, with the student scoring 9.

Uploaded by

erabhinandan525
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

SUBJECT: OBJECT ORIENTED PROGRAMMING

CODE: CS23333

NAME:
ROLL NO:

YEAR:

SEC:
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 1_MCQ

Attempt : 1
Total Mark : 15
Marks Obtained : 9

Section 1 : MCQ

1. Which of the following data types is used to store floating-point


06

6
numbers with greater precision?
00

00

00
0
01

01

01

01
07

07

07

Answer
07
24

24

24

24
double
Status : Correct Marks : 1/1

2. What will be the output of the following code snippet?

import [Link].*;

class OperatorPrecedenceExample {
6

6
00

00

00

00

public static void main(String[] args) {


01

01

01

01

int a = 5, b = 3, c = 2;
07

07

07

07
24

24

24

24
int result = a + b * c;
06

6
00

00

00
0
01

01

01

01
[Link](result);
07

07

07

07
24

24

24

24
}
}
Answer
16
Status : Wrong Marks : 0/1

3. What is the result of the following expression?


6

6
00

00

00

00
import [Link].*;
01

01

01

01
07

07

07

07
24

24

24

24
class ComplexExpressionExample {
public static void main(String[] args) {
int a = 5, b = 2, c = 3, d = 4;
int result = a + b * c / d - b;

[Link](result);
}
}
Answer
06

6
00

00

00
5
0
01

01

01

01
07

07

07

07
Status : Wrong Marks : 0/1
24

24

24

24

4. What is the output of the following code?

class TestClass {
public static void main(String[] args) {
int count = 8;
count = count ^ 1;

[Link](count);
6

6
00

00

00

00

}
01

01

01

01

}
07

07

07

07
24

24

24

24
Answer
06

6
00

00

00
0
01

01

01

01
Compilation error
07

07

07

07
Status : Wrong Marks : 0/1
24

24

24

24
5. Which of the following is not a primitive data type?

Answer
string
Status : Correct Marks : 1/1
6

6
00

00

00

00
6. What is the output of the following code?
01

01

01

01
07

07

07

07
24

24

24

24
class TestClass {
public static void main(String[] args) {
int x = 5;
int X = 10;

int sum = x + X;
int bitwiseResult = x | X;

[Link](sum);
[Link](bitwiseResult);
06

6
00

00

00
}
0
01

01

01

01
}
07

07

07

07
24

24

24

24
Answer
1515
Status : Correct Marks : 1/1

7. What is the output of the following code?

class TestClass {
public static void main(String[] args) {
6

6
00

00

00

00

int a = 5;
01

01

01

01

int b = 10;
07

07

07

07
24

24

24

24
06

6
00

00

00
int sum = a + b;
0
01

01

01

01
int bitwiseAnd = a & b;
07

07

07

07
24

24

24

24
int bitwiseOr = a | b;

[Link](sum);
[Link](bitwiseAnd);
[Link](bitwiseOr);
}
}
Answer
15015
6

6
00

00

00

00
Status : Correct Marks : 1/1
01

01

01

01
07

07

07

07
24

24

24

24
8. Which of the following data types is used to store single characters?

Answer
char
Status : Correct Marks : 1/1

9. What is the output of the following code?


06

6
00

00

00
0
01

01

01

01
class TestClass {
07

07

07

public static void main(String[] args) { 07


24

24

24

24
int a = 10;
int b = 3;
[Link](a / b);
}
}
Answer
3.3333333333333335
Status : Wrong Marks : 0/1
6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
10. What will be the output of the following code?
06

6
00

00

00
0
01

01

01

01
import [Link].*;
07

07

07

07
24

24

24

24
class TernaryOperatorExample {
public static void main(String[] args) {
int a = 5, b = 10;
int result = (a > b) ? a : b;
[Link](result);
}
}
Answer
6

6
00

00

00

00
Undefined behavior
01

01

01

01
07

07

07

07
Status : Wrong Marks : 0/1
24

24

24

24
11. What will be the output of the following code snippet?

class DivisionExample {
public static void main(String[] args) {
double num1 = 10.5;
double num2 = 3;
int result = (int)(num1 / num2);
[Link](result);
06

6
00

00

00
}
0
01

01

01

01
}
07

07

07

07
24

24

24

24
Answer
3.5
Status : Wrong Marks : 0/1

12. What is the output of the following program?

class Arithmetic {
public static void main(String[] args) {
6

6
00

00

00

00

char ch = 'A';
01

01

01

01

[Link](ch);
07

07

07

07
24

24

24

24
}
06

6
00

00

00
}
0
01

01

01

01
07

07

07

07
Answer
24

24

24

24
A
Status : Correct Marks : 1/1

13. What will be the output of the following program?

class DataTypesMCQ {
public static void main(String[] args) {
int a = 10;
6

6
00

00

00

00
double b = 5;
01

01

01

01
[Link](a / b);
07

07

07

07
24

24

24

24
}
}
Answer
2.0
Status : Correct Marks : 1/1

14. What is the output of the following code?


06

6
00

00

00
import [Link].*;
0
01

01

01

01
07

07

07

07
24

24

24

24
class RelationalOperatorExample {
public static void main(String[] args) {
int x = 8, y = 4;
boolean result = (x != y);

[Link](result);
}
}
Answer
6

6
00

00

00

00

true
01

01

01

01
07

07

07

07

Status : Correct Marks : 1/1


24

24

24

24
15. What is the output of the following program?
06

6
00

00

00
0
01

01

01

01
class Demo {
07

07

07

07
24

24

24

24
public static void main(String[] args) {
String text = "Hello, World!";
[Link](text);
}
}
Answer
Hello, World!
Status : Correct Marks : 1/1
6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06

6
00

00

00
0
01

01

01

01
07

07

07

07
24

24

24

24
6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 1_Q1

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
06

6
00

00

00
0

Gloria is responsible for monitoring the performance of two machines in a


01

01

01

01
07

07

07

factory. She needs to determine which of the two machines is operating 07


24

24

24

24
closest to the optimal temperature of 100 degrees Celsius using the
relational operator.

Assist Gloria in displaying the machine's temperature, which is closer to


100, and the difference from 100.

Input Format
The first line of input consists of an integer N, representing the temperature of
the first machine.
6

6
00

00

00

00
01

01

01

01

The second line consists of an integer M, representing the temperature of the


07

07

07

07

second machine.
24

24

24

24
Output Format
06

6
00

00

00
0
01

01

01

01
The output prints "The integer closer to 100 is X with a difference of Y" where X
07

07

07

07
is the temperature of the closer machine and Y is the difference from 100.
24

24

24

24
Refer to the sample output for formatting specifications.
Sample Test Case
Input: 90
80
Output: The integer closer to 100 is 90 with a difference of 10
6

6
00

00

00

00
Answer
01

01

01

01
07

07

07

07
import [Link].*;
24

24

24

24
import [Link];
class main{
public static void main(String []args){
Scanner s1=new Scanner([Link]);
int a,b;
a=[Link]();
b=[Link]();
int c,d;
if(a>100)
c=a-100;
06

6
00

00

00
else
0
01

01

01

01
c=100-a;
07

07

07

if(b>100) 07
24

24

24

24
d=b-100;
else
d=100-b;
if(c<d)
[Link]("The integer closer to 100 is "+a+"with a difference of
"+c );
else
[Link]("The integer closer to 100 is "+b+"with a difference of
"+d);
}
6

6
00

00

00

00

}
01

01

01

01
07

07

07

07
24

24

24

24
24 24 24 24
07 07 07 07
01 01 01 01
00 0 00 0
6 06 6 06
Status : Correct

24 24 24 24
07 07 07 07
01 01 01 01
00 00 00 00
6 6 6 6

24 24 24 24
07 07 07 07
01 01 01 01
00 00 00 00
6 6 6 6

24 24 24 24
07 07 07 07
Marks : 10/10

01 01 01 01
00 00 00 00
6 6 6 6
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 1_Q2

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. PROBLEM STATEMENT:
06

6
00

00

00
0

Dave got two students who wants help with their doubt. Each handouts an
01

01

01

01
07

07

07

integer and wants to find if one Integer Positive While the Other is Not 07
24

24

24

24
Divisible by 3. Write a program to achieve this and conclude for them.

Input Format
The first line of input represents the first integer.

The second line of input represents the second integer.


Output Format
The output should display as "One of the integers is positive while the other is
6

not divisible by 3." or "Neither of the integers meets the condition."


00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06

6
00

00

00
0
01

01

01

01
Refer to the sample output for the formatting specifications.
07

07

07

07
24

24

24

24
Sample Test Case
Input: 4
3
Output: One of the integers is positive while the other is not divisible by 3.
Answer
import [Link];
class main{
public static void main(String args[]){
int a,b;
6

6
00

00

00

00
Scanner s1=new Scanner([Link]);
01

01

01

01
07

07

07

07
a=[Link]();
24

24

24

24
b=[Link]();
if((a>=0&&b%3!=0)||(b>=0&&a%3!=0))
[Link]("One of the integers is positive while the other is not
divisible by 3.");
else
[Link]("Neither of the integers meets the condition.");

}
}
06

6
00

00

00
0
01

01

01

01
07

07

07

07
Status : Correct Marks : 10/10
24

24

24

24
6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 1_Q3

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem statement
06

6
00

00

00
0

Manoj, a developer at MoneyMatters Inc., is working on improving the


01

01

01

01
07

07

07

company's financial system. He needs to create a program that takes an 07


24

24

24

24
integer input, converts it into a double, and displays both the original
integer and the converted double value.

Input Format
The input consists of a single integer representing a monetary amount.
Output Format
The first line of the output displays the "Original Integer: ", followed by an integer
representation of the input value.
6

6
00

00

00

00

The second line displays the "Converted Double: ", followed by a double value
01

01

01

01
07

07

07

07

representing the input as a decimal value.


24

24

24

24
06

6
00

00

00
0
01

01

01

01
07

07

07

07
24

24

24

24
Refer to the sample output for the formatting specifications.
Sample Test Case
Input: 20
Output: Original Integer: 20
Converted Double: 20.0
Answer
import [Link];
6

6
00

00

00

00
public class Main {
01

01

01

01
07

07

07

07
public static void main(String[] args) {
24

24

24

24
Scanner sc = new Scanner([Link]);
int number = [Link]();
double converted = (double) number;
[Link]("Original Integer: " + number);
[Link]("Converted Double: " + converted);
}
}

Status : Correct Marks : 10/10


06

6
00

00

00
0
01

01

01

01
07

07

07

07
24

24

24

24
6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 1_Q4

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
06

6
00

00

00
0

Vishal and Arun are discussing the properties of numbers. Vishal gives
01

01

01

01
07

07

07

Arun two integers. He asks Arun to check if the sum of these two numbers 07
24

24

24

24
is a multiple of their product.

Can you assist Arun and determine whether the sum is a multiple of the
product?

Input Format
The input consists of two space-separated integers.
Output Format
6

The output prints:


00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
1. "Sum is Multiple of Product" if the sum of the two numbers is divisible by their
06

6
00

00

00
product.
0
01

01

01

01
2. "Sum is Not Multiple of Product" otherwise.
07

07

07

07
24

24

24

24
Refer to the sample output for formatting specifications.
Sample Test Case
Input: 1 2
Output: Sum is Not Multiple of Product
Answer
6

6
00

00

00

00
import [Link];
01

01

01

01
07

07

07

07
class main {
24

24

24

24
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
int a = [Link]();
int b = [Link]();
int sum = a + b;
int product = a * b;

if (sum % product == 0) {
[Link]("Sum is Multiple of Product");
} else {
[Link]("Sum is Not Multiple of Product");
06

6
00

00

00
0

}
01

01

01

01
07

07

07

07
}
24

24

24

24
}

Status : Correct Marks : 10/10


6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 1_Q5

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement:
06

6
00

00

00
0

Emily has a beautiful circular garden in her backyard. She's interested in


01

01

01

01
07

07

07

calculating two important measurements for her garden: the 07


24

24

24

24
circumference and the area. To do this, she needs a program that can take
the radius of her circular garden as input and provide the calculated
circumference and area as output. The formulas she should use are as
follows:

To calculate the circumference (C) of a circle, you can use the formula:
C=2*π*r
A = π * r^2
6

6
00

00

00

00

Where:
01

01

01

01
07

07

07

07
24

24

24

24
C represents the circumference.
06

6
00

00

00
0
01

01

01

01
A represents the area.
07

07

07

07
24

24

24

24
π (pi) is approximately 3.14159.
r is the radius of the circle.

Emily is not a programmer, and she needs your help to create a program
that will make these calculations for her garden.

Input Format
The first line of input contains a single double-point number radius, representing
the radius of the circle.
6

6
00

00

00

00
Output Format
01

01

01

01
07

07

07

07
The output should consist of two lines:
24

24

24

24
The first line should print the circumference of the circle rounded to 2 decimal
places, followed by the unit "meters".

The second line should print the area of the circle rounded to 2 decimal places,
followed by the unit "square meters".
06

6
00

00

00
Refer to the sample output for formatting specifications.
0
01

01

01

01
07

07

07

07
Sample Test Case
24

24

24

24
Input: 3.0
Output: Circumference: 18.85 meters
Area: 28.27 square meters
Answer
import [Link];
class main {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
double radius = [Link]();
6

6
00

00

00

00

double pi = 3.14159;
01

01

01

01

double circumference = 2 * pi * radius;


07

07

07

07
24

24

24

24
double area = pi * radius * radius;
06

6
00

00

00
0
01

01

01

01
[Link]("Circumference: %.2f meters%n", circumference);
07

07

07

07
[Link]("Area: %.2f square meters%n", area);
24

24

24

24
}
}

Status : Correct Marks : 10/10


6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06

6
00

00

00
0
01

01

01

01
07

07

07

07
24

24

24

24
6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 1_Q6

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
06

6
00

00

00
0

Joey is learning about bitwise operations and is working on a project that


01

01

01

01
07

07

07

involves extracting specific bits from integers. He needs to write a program 07


24

24

24

24
that takes an integer and the number of bits N as input and outputs the
value of the lowest N bits of the integer.

Help Joey in his project to understand and visualize how bitwise


operations work in practical scenarios.

Input Format
The first line of input consists of an integer X, representing the given integer.
6

The second line consists of an integer N, representing the number of bits to


00

00

00

00
01

01

01

01

extract.
07

07

07

07
24

24

24

24
Output Format
06

6
00

00

00
0
01

01

01

01
The output displays "Result: " followed by an integer representing the value of
07

07

07

07
the lowest N bits of the given integer.
24

24

24

24
Refer to the sample output for formatting specifications.
Sample Test Case
Input: 85
2
Output: Result: 1
6

6
00

00

00

00
Answer
01

01

01

01
07

07

07

07
import [Link];
24

24

24

24
class main{
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
int x = [Link]();
int n = [Link]();
int mask = (1 << n) - 1;
int result = x & mask;
[Link]("Result: " + result);
}
}
06

6
00

00

00
0
01

01

01

01
Status : Correct Marks : 10/10
07

07

07

07
24

24

24

24
6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 1_Q7

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement:
06

6
00

00

00
0

Miles is working on a program that involves analyzing two integers. He


01

01

01

01
07

07

07

wants to check if either one of the integers is both: 07


24

24

24

24

Less than or equal to zero, [Link] you help him create a program that
identifies whether either of the integers meets these conditions?

Input Format
The input consists of two integers on separate lines, denoted as 'input1' and
'input2'.
Output Format
A single line with a boolean result (either 'true' or 'false') indicating whether either
6

6
00

00

00

00

'input1' or 'input2' is both less than or equal to zero and odd.


01

01

01

01
07

07

07

07
24

24

24

24
06

6
00

00

00
0
01

01

01

01
07

07

07

07
Refer to the sample output for format specifications
24

24

24

24
Sample Test Case
Input: -45
10
Output: true
Answer
import [Link];

public class Main {


6

6
00

00

00

00
public static void main(String[] args) {
01

01

01

01
07

07

07

07
Scanner sc = new Scanner([Link]);
24

24

24

24
int input1 = [Link]([Link]());
int input2 = [Link]([Link]());

boolean condition1 = (input1 <= 0 && input1 % 2 != 0);


boolean condition2 = (input2 <= 0 && input2 % 2 != 0);

[Link](condition1 || condition2);
}
}

Status : Correct Marks : 10/10


06

6
00

00

00
0
01

01

01

01
07

07

07

07
24

24

24

24
6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 1_Q8

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
06

6
00

00

00
0

In the Kingdom of Finance, the royal treasury is managed by the treasurer,


01

01

01

01
07

07

07

Sir Cedric. Sir Cedric tracks the daily expenses of the kingdom using an 07
24

24

24

24
expense report that lists three major categories: food, clothing, and
utilities. However, the King wants to know if the average daily expense is
greater than at least two of these categories to ensure the kingdom is
spending wisely.

Your task is to help Sir Cedric determine if the average daily expense is
greater than two of the categories. Specifically, you need to calculate the
average of the three expenses and check if it is greater than any two
categories.
6

6
00

00

00

00

Note: Use the ternary operator


01

01

01

01
07

07

07

07
24

24

24

24
06

6
Input Format

00

00

00
0
01

01

01

01
Three integers a, b, and c represent the daily expenses for food, clothing, and
07

07

07

07
24

utilities. Each integer is provided on a single line.

24

24

24
Output Format
The average of the three expenses, rounded to two decimal places.

A message indicating whether the average is greater than at least two of the
expense categories.

1. If the average is greater than the two smallest monthly expenses, print
"Average is greater than both X and Y," where X and Y are the two smallest
expenses.
6

6
00

00

00

00
2. Otherwise, display "Average is not greater than two smallest expenses".
01

01

01

01
07

07

07

07
24

24

24

24
Refer to the sample output for formatting specifications.
Sample Test Case
Input: 4
6
10
Output: 6.67
06

6
Average is greater than both 4 and 6
00

00

00
0
01

01

01

01
Answer
07

07

07

07
24

24

24

24
import [Link];
class main{
public static void main(String args[]){
Scanner s=new Scanner([Link]);
int a=[Link]();
int b=[Link]();
int c=[Link]();
double d=(a+b+c)/3.0;
[Link]("%.2f",d);
if(d>a&&d>b){
6

[Link]("Average is greater than both " +a+"and " +b);


00

00

00

00

}
01

01

01

01
07

07

07

07

else if(d>a&&d>c){
24

24

24

24
[Link]("Average is greater than both " +a+"and " +c);
06

6
00

00

00
}
0
01

01

01

01
else if(d>b&&d>c){
07

07

07

07
[Link]("Average is greater than both " +b+"and " +c);
24

24

24

24
}
else{
[Link]("Average is not greater than two smallest expenses");
}
}
}

Status : Correct Marks : 10/10


6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06

6
00

00

00
0
01

01

01

01
07

07

07

07
24

24

24

24
6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 1_Q9

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
06

6
00

00

00
0

Phill is a quality control manager at a manufacturing plant. He needs to


01

01

01

01
07

07

07

verify if a sensor reading at a midpoint station (S2) falls exactly halfway 07


24

24

24

24
between the readings of the previous station (S1) and the next station (S3).
Help him by developing a program that checks if the second sensor
reading is the average (midpoint) of the first and third sensor readings.

Use the relational operator to solve the program.

Input Format
The first line of input consists of an integer S1, representing the sensor reading
of the first station.
6

6
00

00

00

00
01

01

01

01

The second line consists of an integer S2, representing the sensor reading of the
07

07

07

07

midpoint station.
24

24

24

24
06

6
00

00

00
The third line consists of an integer S3, representing the sensor reading of the
0
01

01

01

01
next station.
07

07

07

07
24

24

24

24
Output Format
The first line of output displays a boolean value representing whether the sensor
reading at the midpoint station is halfway between the readings of the first and
the next stations.

The second line displays one of the following:

1. If the result is true, print "The second integer is halfway between the first and
third integers."
2. Otherwise, print "The second integer is not halfway between the first and third
6

6
00

00

00

00
integers."
01

01

01

01
07

07

07

07
24

24

24

24
Refer to the sample output for formatting specifications.
Sample Test Case
Input: 1
7
10
Output: false
06

6
The second integer is not halfway between the first and third integers.
00

00

00
0
01

01

01

01
Answer
07

07

07

07
24

24

24

24
// You are using Java
import [Link];
class main{
public static void main(String args[]){
Scanner s=new Scanner([Link]);
int a=[Link]();
int b=[Link]();
int c=[Link]();
int d=(a+c)/2;
if(d==b){
6

[Link]("true");
00

00

00

00

[Link]("The second integer is halfway between the first and


01

01

01

01
07

07

07

07

third integers.");
24

24

24

24
}
06

6
00

00

00
else{
0
01

01

01

01
[Link]("false");
07

07

07

07
[Link]("The second integer is not halfway between the first
24

24

24

24
and third integers.");

}
}
}

Status : Correct Marks : 10/10


6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06

6
00

00

00
0
01

01

01

01
07

07

07

07
24

24

24

24
6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 1_Q10

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
06

6
00

00

00
0

Aishu is supervising a construction project that needs to be completed


01

01

01

01
07

07

07

with the help of three workers: A, B, and C. 07


24

24

24

24

She knows how many days each of them would take to complete the entire
project individually:

A can complete it in x days,B in y days,C in z days.


Initially, all three workers (A, B, and C) work together for d1 days.
After that, C leaves, and only A and B continue for another d2 days.
Then B also leaves, and A works alone to finish the remaining work.
6

6
00

00

00

00

Your tasks is to help aishu to implement this functionality using the class
01

01

01

01
07

07

07

07

WorkDistribution and Method calculateWork(int x, int y, int z, int d1, int d2)
24

24

24

24
06

6
Calculate the total work completed in the first d1 days by A, B, and

00

00

00
0
01

01

01

01
[Link] the work completed in the next d2 days by A and [Link]
07

07

07

07
the remaining work after these d1 + d2 days.
24

24

24

24
Input Format
The first line of input contains five space-separated integers: x y z d1 d2

where:

x represents the Days A takes to complete the work alone

y represents the Days B takes to complete the work alone


6

6
00

00

00

00
z represents the Days C takes to complete the work alone
01

01

01

01
07

07

07

07
d1 represents the Days A, B, and C work together
24

24

24

24
d2 represents the Days A and B work together (after C leaves)
Output Format
The first line of output prints "Work done in first d1 days (A+B+C): " followed by a
double value rounded to 2 decimal places.

The second line of output prints "Work done in next d2 days (A+B): " followed by
a double value rounded to 2 decimal places.
06

6
00

00

00
The third line prints "Remaining work: " followed by a double value rounded to 2
0
01

01

01

01
decimal places.
07

07

07

07
24

24

24

24

Refer to the sample output for formatting specifications.


Sample Test Case
Input: 10 20 30 2 2
Output: Work done in first d1 days (A+B+C): 0.37
Work done in next d2 days (A+B): 0.30
Remaining work: 0.33
6

6
00

00

00

00
01

01

01

01

Answer
07

07

07

07
24

24

24

24
import [Link];
06

6
00

00

00
class main{
0
01

01

01

01
public static void main(String[] args) {
07

07

07

07
Scanner sc = new Scanner([Link]);
24

24

24

24
int x = [Link]();
int y = [Link]();
int z = [Link]();
int d1 = [Link]();
int d2 = [Link]();
double a = 1.0 / x;
double b = 1.0 / y;
double c = 1.0 / z;
double work1 = d1 * (a + b + c);
double work2 = d2 * (a + b);
6

6
00

00

00

00
double remaining = 1 - (work1 + work2);
01

01

01

01
[Link]("Work done in first d1 days (A+B+C): %.2f\n", work1);
07

07

07

07
[Link]("Work done in next d2 days (A+B): %.2f\n", work2);
24

24

24

24
[Link]("Remaining work: %.2f\n", remaining);
}
}

Status : Correct Marks : 10/10


06

6
00

00

00
0
01

01

01

01
07

07

07

07
24

24

24

24
6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 2_MCQ

Attempt : 1
Total Mark : 15
Marks Obtained : 7

Section 1 : MCQ

1. What will be the output of the following code?


06

6
00

00

00
0

class Test {
01

01

01

01
07

07

07

public static void main(String[] args) { 07


24

24

24

24
int x = 5, y = 2;
if (x + y == 10)
[Link]("Ten");
else if (x - y == 3)
[Link]("Three");
else
[Link]("None");
}
}
6

6
00

00

00

00

Answer
01

01

01

01
07

07

07

07

None
24

24

24

24
Status : Wrong Marks : 0/1
06

6
00

00

00
0
01

01

01

01
07

07

07

07
2. What will be the output of the following code?
24

24

24

24
public class Main {
public static void main(String[] args) {
int i = 1;
while(i < 10) {
i += 2;
}
[Link](i);
}
6

6
00

00

00

00
}
01

01

01

01
07

07

07

07
Answer
24

24

24

24
11
Status : Correct Marks : 1/1

3. What will be the output of the following Java code snippet?

public class Main {


public static void main(String[] args) {
int score = 75;
06

6
00

00

00
if(score >= 90) {
0
01

01

01

01
[Link]("Grade: A");
07

07

07

} else if(score >= 80) { 07


24

24

24

24
[Link]("Grade: B");
} else if(score >= 70) {
[Link]("Grade: C");
} else {
[Link]("Grade: D");
}
}
}
Answer
6

6
00

00

00

00
01

01

01

01

Grade: A
07

07

07

07
24

24

24

24
Status : Wrong Marks : 0/1
06

6
00

00

00
0
01

01

01

01
07

07

07

07
4. What will be the output of the following code?
24

24

24

24
class LoopTest {
public static void main(String[] args) {
int i = 1;
do {
[Link](i + " ");
i *= 2;
} while (i <= 8);
}
6

6
00

00

00

00
}
01

01

01

01
07

07

07

07
Answer
24

24

24

24
1248
Status : Correct Marks : 1/1

5. What will be the output of the following code?

class Test {
public static void main(String[] args) {
int a = 4, b = 5;
06

6
00

00

00
if ((a + b) % 2 == 0)
0
01

01

01

01
[Link]("Even");
07

07

07

else 07
24

24

24

24
[Link]("Odd");
}
}
Answer
Even
Status : Wrong Marks : 0/1
6

6
00

00

00

00

6. What will be the output of the following code?


01

01

01

01
07

07

07

07
24

24

24

24
public class Main {
06

6
00

00

00
public static void main(String[] args) {
0
01

01

01

01
for(int i = 1; i <= 20; i = i * 2) {
07

07

07

07
24

24

24

24
[Link](i + " ");
}
}
}
Answer
1 2 4 8 16
Status : Correct Marks : 1/1
6

6
00

00

00

00
7. What will be the output of the following code?
01

01

01

01
07

07

07

07
24

24

24

24
class Main {
public static void main(String[] args) {
for (int i = 5; i > 0; i--) {
[Link](i + " ");
}
}
}
Answer
12345
06

6
00

00

00
0

Status : Wrong Marks : 0/1


01

01

01

01
07

07

07

07
24

24

24

24

8. What will be the output of the following code?

public class Main {


public static void main(String[] args) {
int i = 10;
do {
[Link](i + " ");
i -= 3;
} while(i > 0);
6

6
00

00

00

00

}
01

01

01

01

}
07

07

07

07
24

24

24

24
Answer
06

6
00

00

00
0
01

01

01

01
1234
07

07

07

07
Status : Wrong Marks : 0/1
24

24

24

24
9. What will be the output of the following code?

class ConditionTest {
public static void main(String[] args) {
int x = 10;
if (x > 5)
[Link]("High");
6

6
}
00

00

00

00
01

01

01

01
}
07

07

07

07
24

24

24

24
Answer
High
Status : Correct Marks : 1/1

10. What will be the output of the following code?

class Test {
public static void main(String[] args) {
06

6
int num = 15;
00

00

00
0
01

01

01

01
if (num > 10)
07

07

07

if (num % 3 == 0) 07
24

24

24

24
[Link]("Divisible");
else
[Link]("Not Divisible");
}
}
Answer
Divisible
Status : Correct Marks : 1/1
6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
11. What will be the output of the following code?
06

6
00

00

00
0
01

01

01

01
class LoopTest {
07

07

07

07
24

24

24

24
public static void main(String[] args) {
int i = 1;
while (i > 0) {
[Link](i + " ");
i++;
if (i == 5) break;
}
}
}
6

6
Answer
00

00

00

00
01

01

01

01
12345
07

07

07

07
24

24

24

24
Status : Wrong Marks : 0/1

12. What will be the output of the following code?

class ConditionTest {
public static void main(String[] args) {
int a = 7;
if (a == 7)
[Link]("Match");
06

6
00

00

00
else
0
01

01

01

01
[Link]("No Match");
07

07

07

07
24

24

24

24
}
}
Answer
Match
Status : Correct Marks : 1/1

13. What will be the output of the following code?


6

6
00

00

00

00

public class Main {


01

01

01

01

public static void main(String[] args) {


07

07

07

07
24

24

24

24
int sum = 0;
06

6
00

00

00
for(int i = 1; i <= 5; i++) {
0
01

01

01

01
sum += i;
07

07

07

07
24

24

24

24
}
[Link](sum);
}
}
Answer
15
Status : Correct Marks : 1/1
6

6
00

00

00

00
14. What will be the output of the following Java code snippet?
01

01

01

01
07

07

07

07
24

24

24

24
public class Main {
public static void main(String[] args) {
int day = 4;
String result = "";
switch(day) {
case 1:
result = "Monday";
break;
case 2:
result = "Tuesday";
06

6
00

00

00
break;
0
01

01

01

01
case 3:
07

07

07

07
24

24

24

24
result = "Wednesday";
break;
default:
result = "Other Day";
}
[Link](result);
}
}
Answer
6

6
00

00

00

00

Wednesday
01

01

01

01
07

07

07

07

Status : Wrong Marks : 0/1


24

24

24

24
15. What will be the output of the following code?
06

6
00

00

00
0
01

01

01

01
class Loop {
07

07

07

07
24

24

24

24
public static void main(String[] args) {
for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= 2; j++) {
[Link](i + "" + j + " ");
}
}
}
}
Answer
6

6
00

00

00

00
12345
01

01

01

01
07

07

07

07
Status : Wrong Marks : 0/1
24

24

24

24
06

6
00

00

00
0
01

01

01

01
07

07

07

07
24

24

24

24
6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 2_Q1

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
06

6
00

00

00
0

Arun is working on a project to automate the process of determining


01

01

01

01
07

07

07

whether a student has passed or failed based on their subject marks. 07


24

24

24

24

He aims to create a simple program that takes positive integers as marks


for five subjects from the user. If the average of the marks is greater than
or equal to 50, the student has passed the exam. Otherwise, the student
has failed.

Help Arun to implement the project.

Input Format
6

The input consists of five space-separated integers, representing the marks in


00

00

00

00
01

01

01

01

five subjects.
07

07

07

07
24

24

24

24
Output Format
06

6
00

00

00
0
01

01

01

01
The first line of output prints "Average score: " followed by an integer
07

07

07

07
representing the average score.
24

24

24

24
The second line prints one of the following:

1. If the condition is satisfied, print "The student has passed".


2. Otherwise, the output prints "The student has failed".

Refer to the sample output for formatting specifications.


6

6
00

00

00

00
Sample Test Case
01

01

01

01
07

07

07

07
Input: 50 60 70 80 90
24

24

24

24
Output: Average score: 70
The student has passed
Answer
// You are using Java
import [Link];
class main{
public static void main(String args[]){
Scanner s=new Scanner([Link]);
int a=[Link]();
06

6
00

00

00
int b=[Link]();
0
01

01

01

01
int c=[Link]();
07

07

07

int d=[Link](); 07
24

24

24

24
int e=[Link]();
int t=(a+b+c+d+e)/5;
[Link]("Average score: " +t);
if(t>=50){
[Link]("The student has passed");
}
else
{
[Link]("The student has failed");
}
6

6
00

00

00

00

}
01

01

01

01

}
07

07

07

07
24

24

24

24
24 24 24 24
07 07 07 07
01 01 01 01
00 0 00 0
6 06 6 06
Status : Correct

24 24 24 24
07 07 07 07
01 01 01 01
00 00 00 00
6 6 6 6

24 24 24 24
07 07 07 07
01 01 01 01
00 00 00 00
6 6 6 6

24 24 24 24
07 07 07 07
Marks : 10/10

01 01 01 01
00 00 00 00
6 6 6 6
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 2_Q2

Attempt : 2
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
06

6
00

00

00
0

Samantha is a diligent math student who is exploring the world of


01

01

01

01
07

07

07

programming. She is learning Java and has recently studied conditional 07


24

24

24

24
statements. One day, her teacher gives her an interesting problem to solve,
which takes a number as input and checks whether it is a multiple of 5 or
7.

Help her complete the task.

Input Format
The input consists of a single integer N, representing the number to be checked.
Output Format
6

6
00

00

00

00
01

01

01

01

If the number is a multiple of 5 but not 7, the output prints "N is a multiple of 5".
07

07

07

07
24

24

24

24
06

6
00

00

00
If the number is a multiple of 7, the output prints "N is a multiple of 7".
0
01

01

01

01
07

07

07

07
Otherwise the output prints "N is neither multiple of 5 nor 7" where N is an
24

24

24

24
entered integer.

Refer to the sample output for formatting specifications.


Sample Test Case
Input: 10
Output: 10 is a multiple of 5
6

6
00

00

00

00
01

01

01

01
Answer
07

07

07

07
24

24

24

24
// You are using Java
import [Link];
class main{
public static void main(String args[]){
Scanner s=new Scanner([Link]);
int a=[Link]();
if(a%5==0){
[Link](a+" is a multiple of 5 ");
}
else if(a%7==0){
[Link](a+" is a multiple of 7 ");
06

6
00

00

00
0

}
01

01

01

01
07

07

07

07
else{
24

24

24

24
[Link](a+" is neither multiple of 5 nor 7 ");
}
}
}

Status : Correct Marks : 10/10


6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 2_Q3

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
06

6
00

00

00
0

John is a fitness trainer, and he wants to use the BMI calculator to assess
01

01

01

01
07

07

07

the body mass index of his clients. He has a list of clients based on their 07
24

24

24

24
height and weight.

John plans to write a program to quickly determine the BMI and provide a
classification for each client.
If BMI is less than 18.5, the program will classify it as "Underweight"If BMI
is between 18.6 and 24.9, the program will classify it as "Normal Weight"If
BMI is between 25.0 and 29.9, the program will classify it as "Overweight"If
BMI is 30.0 or higher, the program will classify it as "Obese"
Note: Formula to calculate BMI = weight/(height*height)
6

6
00

00

00

00
01

01

01

01
07

07

07

07

Input Format
24

24

24

24
The first line of input consists of a double value, representing the height of the
06

6
00

00

00
person in meters.
0
01

01

01

01
07

07

07

07
The second line consists of a double value, representing the weight of the
24

24

24

24
person in kilograms.
Output Format
The first line of output prints "BMI: " followed by a double (rounded to two
decimal places) representing the calculated BMI.

The second line prints "Classification: " followed by a string indicating the BMI
category (Underweight, Normal Weight, Overweight, or Obese).
6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
Refer to the sample output for formatting specifications.
Sample Test Case
Input: 1.2
45.2
Output: BMI: 31.39
Classification: Obese
Answer
import [Link];
06

6
class main{
00

00

00
0

public static void main(String[] args) {


01

01

01

01
07

07

07

07
Scanner sc = new Scanner([Link]);
24

24

24

24
double height = [Link]();
double weight = [Link]();
double bmi = weight / (height * height);
String classification;

if (bmi < 18.5) {


classification = "Underweight";
} else if (bmi >= 18.6 && bmi <= 24.9) {
classification = "Normal Weight";
} else if (bmi >= 25.0 && bmi <= 29.9) {
6

classification = "Overweight";
00

00

00

00

} else {
01

01

01

01
07

07

07

07

classification = "Obese";
24

24

24

24
24 24 24 24
07 07 07 07

}
01 01 01 01

}
00 0 00 0 }
6 06 6 06

Status : Correct
24 24 24 24
07 07 07 07
01 01 01 01
00 00 00 00
6 6 6 6
[Link]("BMI: %.2f\n", bmi);

24 24 24 24
07 07 07 07
01 01 01 01
[Link]("Classification: " + classification);

00 00 00 00
6 6 6 6

24 24 24 24
07 07 07 07
Marks : 10/10

01 01 01 01
00 00 00 00
6 6 6 6
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 2_Q4

Attempt : 1
Total Mark : 10
Marks Obtained : 6.5

Section 1 : Coding

1. Problem Statement
06

6
00

00

00
0

Amit wants to evaluate the depreciation of his car over time to understand
01

01

01

01
07

07

07

its current value and categorize it based on that value. 07


24

24

24

24

Write a program that helps him determine the current value of his car after
a certain number of years of depreciation and classify it into one of three
categories:
High: If the current value is greater than 10,[Link]: If the current
value is between 5,000 and 10,000, both [Link]: If the current value
is less than 5,000.
The depreciation rate of the car is 15% per year. The program should
calculate the current value of the car after applying this depreciation over
6

6
00

00

00

00

the given number of years and print the current value along with the
01

01

01

01
07

07

07

07

category.
24

24

24

24
06

6
Input Format

00

00

00
0
01

01

01

01
The first line of input consists of an integer, representing the initial cost of the
07

07

07

07
24

car.

24

24

24
The second line consists of an integer, representing the number of years the car
has been depreciating.
Output Format
The first line of output prints a double value, representing the current value of the
car, rounded off to two decimal places "Current Value: <value>".

The second line prints its category "Category: <categories>".


6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
Refer to the sample output for formatting specifications.
Sample Test Case
Input: 20000
5
Output: Current Value: 8874.11
Category: Medium
Answer
06

6
// You are using Java
00

00

00
0

import [Link];
01

01

01

01
07

07

07

07
class main{
24

24

24

24
public static void main(String args[]){
Scanner s=new Scanner([Link]);
int intialcost=[Link]();
int years=[Link]();
double rate=0.15;
double CurrentValue=intialcost*[Link](1-rate,years);
CurrentValue=[Link](CurrentValue*100.0)/100.0;
String Category;
if (CurrentValue>10000){
Category="High";
6

}
00

00

00

00

else if (CurrentValue>=5000){
01

01

01

01
07

07

07

07

Category="Medium";
24

24

24

24
}
06

6
00

00

00
else {
0
01

01

01

01
Category="Low";
07

07

07

07
}
24

24

24

24
[Link]("Current Value: " +CurrentValue);
[Link]("Category: " +Category);
}
}

Status : Partially correct Marks : 6.5/10


6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06

6
00

00

00
0
01

01

01

01
07

07

07

07
24

24

24

24
6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 2_Q5

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
06

6
00

00

00
0

Ted, the computer science enthusiast, has accepted the challenge of


01

01

01

01
07

07

07

writing a program that checks if the number of digits in an integer matches 07


24

24

24

24
the sum of its digits.

Guide Ted in designing and writing the code to solve this problem using a
'do-while' loop.

Input Format
The input consists of an integer N, representing the number to be checked.
Output Format
6

If the sum is equal to the number of digits, print "The number of digits in N
00

00

00

00
01

01

01

01

matches the sum of its digits."


07

07

07

07
24

24

24

24
06

6
00

00

00
Else, print "The number of digits in N does not match the sum of its digits."
0
01

01

01

01
07

07

07

07
24

24

24

24
Refer to the sample output for formatting specifications.
Sample Test Case
Input: 20
Output: The number of digits in 20 matches the sum of its digits.
Answer
import [Link];
6

6
00

00

00

00
public class Main {
01

01

01

01
07

07

07

07
public static void main(String[] args) {
24

24

24

24
Scanner sc = new Scanner([Link]);
int N = [Link]();
int num = N;
int sum = 0, digits = 0;
do {
sum += num % 10;
num /= 10;
digits++;
} while (num > 0);
if (sum == digits)
[Link]("The number of digits in " + N + " matches the sum of
06

6
00

00

00
0

its digits.");
01

01

01

01
07

07

07

07
else
24

24

24

24
[Link]("The number of digits in " + N + " does not match the
sum of its digits.");
}
}

Status : Correct Marks : 10/10


6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 2_Q6

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
06

6
00

00

00
0

Maya, a student in an arts and crafts class, wants to create a pattern using
01

01

01

01
07

07

07

stars (*) in a specific format. She plans to use a program to help her 07
24

24

24

24
construct the pattern.

Write a program that takes an integer as input and constructs the following
pattern using nested for loops.

Input: 5

Output:
*
6

6
00

00

00

00

**
01

01

01

01
07

07

07

07
24

24

24

24
***
06

6
00

00

00
0
01

01

01

01
****
07

07

07

07
24

24

24

24
*****
****
***
**
*

Input Format
6

6
The input consists of a number (integer) representing the number of rows.
00

00

00

00
01

01

01

01
Output Format
07

07

07

07
24

24

24

24
The output displays the required pattern.

Refer to the sample output for the formatting specifications.


Sample Test Case
Input: 5
Output: *
06

6
00

00

00
**
0
01

01

01

01
***
07

07

07

**** 07
24

24

24

24
*****
****
***
**
*
Answer
// You are using Java
import [Link];
public class Main {
6

6
00

00

00

00

public static void main(String[] args) {


01

01

01

01

Scanner sc = new Scanner([Link]);


07

07

07

07
24

24

24

24
int rows = [Link]();
06

6
00

00

00
for (int i = 1; i <= rows; i++) {
0
01

01

01

01
for (int j = 1; j <= i; j++) {
07

07

07

07
[Link]("* ");
24

24

24

24
}
[Link]();
}
for (int i = rows - 1; i >= 1; i--) {
for (int j = 1; j <= i; j++) {
[Link]("* ");
}
[Link]();
}
}
6

6
00

00

00

00
}
01

01

01

01
07

07

07

07
Status : Correct Marks : 10/10
24

24

24

24
06

6
00

00

00
0
01

01

01

01
07

07

07

07
24

24

24

24
6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 2_Q7

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
06

6
00

00

00
0

You are taking part in a coding challenge where your task is to design a
01

01

01

01
07

07

07

program that conjures a mesmerizing numerical pyramid pattern. The 07


24

24

24

24
enchanting pattern is fashioned using a for loop and is customized based
on user input.

Participants are prompted to unveil the pyramid's magic by specifying its


height - essentially dictating the number of rows in this spellbinding
creation.

Write a program that employs to weave this captivating numerical pyramid


as shown below.
6

6
00

00

00

00

Example
01

01

01

01
07

07

07

07
24

24

24

24
06

6
Input:

00

00

00
0
01

01

01

01
4
07

07

07

07
24

24

24

24
Output:

Input Format
The input consists of a positive integer n representing the number of rows in the
pattern.
Output Format
The output prints the required pyramid pattern, as shown in the sample output.
6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
Refer to the sample output for the formatting specifications.
Sample Test Case
Input: 4
Output: 1
123
12345
1234567
06

6
00

00

00
Answer
0
01

01

01

01
07

07

07

07
// You are using Java
24

24

24

24
import [Link];
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int n = [Link]();
for (int i = 1; i <= n; i++) {
for (int s = 1; s <= n - i; s++) {
[Link](" ");
}
for (int num = 1; num <= 2 * i - 1; num++) {
6

[Link](num);
00

00

00

00

}
01

01

01

01
07

07

07

07

[Link]();
24

24

24

24
24 24 24 24
07 07 07 07

}
01 01 01 01
}
00 0 00 0 }
6 06 6 06

Status : Correct

24 24 24 24
07 07 07 07
01 01 01 01
00 00 00 00
6 6 6 6

24 24 24 24
07 07 07 07
01 01 01 01
00 00 00 00
6 6 6 6

24 24 24 24
07 07 07 07
Marks : 10/10

01 01 01 01
00 00 00 00
6 6 6 6
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 2_Q8

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
06

6
00

00

00
0

A bank generates secure codes using 3-digit numbers where each digit is
01

01

01

01
07

07

07

unique, and the code must be divisible by 3. You are tasked with generating 07
24

24

24

24
the first N such codes based on user input, ensuring the digits are unique
and the number is divisible by 3.

Note: Use nested for loops to solve.

Input Format
The first line contains an integer N representing the number of valid codes to
generate.
Output Format
6

6
00

00

00

00
01

01

01

01

The output prints N line,s each line contains a valid 3-digit code.
07

07

07

07
24

24

24

24
06

6
00

00

00
0
01

01

01

01
07

07

07

07
24

24

24

24
Refer to the sample output for formatting specifications.
Sample Test Case
Input: 5
Output: 102
105
108
120
123
6

6
00

00

00

00
Answer
01

01

01

01
07

07

07

07
// You are using Java
24

24

24

24
import [Link];
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int N = [Link]();
int count = 0;
for (int i = 1; i <= 9 && count < N; i++) {
for (int j = 0; j <= 9 && count < N; j++) {
if (j == i) continue;
for (int k = 0; k <= 9 && count < N; k++) {
if (k == i || k == j) continue;
06

6
00

00

00
0

int num = i * 100 + j * 10 + k;


01

01

01

01
07

07

07

07
if (num % 3 == 0) {
24

24

24

24
[Link](num);
count++;
if (count == N) break;
}
}
}
}
}
}

Status : Correct Marks : 10/10


6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
REC_2028_OOPS using Java_Week 3_MCQ

Attempt : 1
Total Mark : 15
Marks Obtained : 2

Section 1 : MCQ

1. What will be the output of the following code?


06

6
00

00

00
0

class Sample {
01

01

01

01
07

07

07

public static void main(String[] args) { 07


24

24

24

24
int[][] data = {
{1, 2},
{3, 4}
};
int sum = 0;

for (int[] row : data) {


for (int val : row) {
sum += val;
}
6

6
00

00

00

00

}
01

01

01

01
07

07

07

07
24

24

24

24
[Link]("Sum = " + sum);
06

6
00

00

00
}
0
01

01

01

01
}
07

07

07

07
24

24

24

24
Answer
Sum = 10
Status : Correct Marks : 1/1

2. What will be the output of the following code?

class Q {
public static void main(String[] args) {
6

6
00

00

00

00
int[] a = {1, 2, 3, 4};
01

01

01

01
for (int i = 0; i < [Link] / 2; i++) {
07

07

07

07
24

24

24

24
int temp = a[i];
a[i] = a[[Link] - 1 - i];
a[[Link] - 1 - i] = temp;
}
[Link](a[0]);
}
}
Answer
3
06

6
00

00

00
0

Status : Wrong Marks : 0/1


01

01

01

01
07

07

07

07
24

24

24

24

3. What will be the output of the following code?

class ReverseArray {
public static void main(String[] args) {
int[] a = {1, 2, 3, 4};
for (int i = 0; i < [Link] / 2; i++) {
int temp = a[i];
a[i] = a[[Link] - 1 - i];
a[[Link] - 1 - i] = temp;
6

6
00

00

00

00

}
01

01

01

01

for (int i : a)
07

07

07

07
24

24

24

24
[Link](i + " ");
06

6
00

00

00
}
0
01

01

01

01
}
07

07

07

07
24

24

24

24
Answer
4123
Status : Wrong Marks : 0/1

4. What will be the output of the following code?

class Sample {
public static void main(String[] args) {
6

6
00

00

00

00
int[] a = {1, 2, 3};
01

01

01

01
int product = 1;
07

07

07

07
24

24

24

24
for (int i = 0; i < [Link]; i++) {
product *= a[i];
}
[Link](product);
}
}
Answer
3
Status : Wrong Marks : 0/1
06

6
00

00

00
0
01

01

01

01
07

07

07

07
24

24

24

24
5. What will be the output of the following code?

public class Test {


public static void main(String[] args) {
int[] x = {4, 8, 12};
int result = x[0] * x[2];
[Link](result);
}
}
6

Answer
00

00

00

00
01

01

01

01

12
07

07

07

07
24

24

24

24
Status : Wrong Marks : 0/1
06

6
00

00

00
0
01

01

01

01
07

07

07

07
6. What will be the output of the following code?
24

24

24

24
class Q {
public static void main(String[] args) {
int[] nums = {3, 6, 7, 2, 8};
int sum = 0;
for (int i = 0; i < [Link]; i++) {
if (nums[i] % 2 == 0)
sum += nums[i];
}
6

6
00

00

00

00
[Link](sum);
01

01

01

01
}
07

07

07

07
}
24

24

24

24
Answer
6
Status : Wrong Marks : 0/1

7. What will be the output of the following code?

class Sample {
06

6
00

00

00
public static void main(String[] args) {
0
01

01

01

01
int[][] matrix = {
07

07

07

{1, 2, 3}, 07
24

24

24

24
{4, 5, 6}
};
[Link](matrix[1][2]);
}
}
Answer
6
Status : Correct Marks : 1/1
6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
8. What will be the output of the following code?
06

6
00

00

00
0
01

01

01

01
class Q {
07

07

07

07
24

24

24

24
public static void main(String[] args) {
int[] a = {1, 2, 3, 4};
for (int i = 0; i < [Link]; i++) {
if (a[i] % 2 == 0)
a[i] = 0;
}
[Link](a[1] + " " + a[3]);
}
}
6

6
Answer
00

00

00

00
01

01

01

01
10
07

07

07

07
24

24

24

24
Status : Wrong Marks : 0/1

9. What will be the output of the following code?

class M {
public static void main(String[] args) {
int[][] arr = {
{1, 2},
{3, 4},
06

6
00

00

00
{5, 6}
0
01

01

01

01
};
07

07

07

07
24

24

24

24

for (int i = 0; i < [Link]; i++) {


[Link](arr[i][0] + " ");
}
}
}
Answer
124
Status : Wrong Marks : 0/1
6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
10. What will be the output of the following code?
06

6
00

00

00
0
01

01

01

01
class Q {
07

07

07

07
24

24

24

24
public static void main(String[] args) {
int[][] arr = {
{5, 6, 7},
{8, 9, 10}
};
[Link](arr[0][2]);
}
}
Answer
6

6
00

00

00

00
5
01

01

01

01
07

07

07

07
Status : Wrong Marks : 0/1
24

24

24

24
11. What will be the output of the following code?

class Q {
public static void main(String[] args) {
int[] a = {1, 2, 1, 3, 1, 4};
int count = 0;
for (int i = 0; i < [Link]; i++) {
if (a[i] == 1) count++;
06

6
00

00

00
}
0
01

01

01

01
[Link](count);
07

07

07

07
24

24

24

24
}
}
Answer
1
Status : Wrong Marks : 0/1

12. What will be the output of the following code?


6

6
00

00

00

00

class Q {
01

01

01

01

public static void main(String[] args) {


07

07

07

07
24

24

24

24
int[][] a = {
06

6
00

00

00
{1, 2},
0
01

01

01

01
{3, 4}
07

07

07

07
24

24

24

24
};
for (int i = 0; i < [Link]; i++) {
for (int j = 0; j < a[0].length; j++) {
[Link](a[i][j] + " ");
}
}
}
}
Answer
6

6
00

00

00

00
134
01

01

01

01
07

07

07

07
Status : Wrong Marks : 0/1
24

24

24

24
13. What will be the output of the following code?

class Q {
public static void main(String[] args) {
int[] nums = {4, 2, 9, 5};
int max = nums[0];
for (int i = 1; i < [Link]; i++) {
if (nums[i] > max)
06

6
00

00

00
max = nums[i];
0
01

01

01

01
}
07

07

07

07
24

24

24

24
[Link](max);
}
}
Answer
4
Status : Wrong Marks : 0/1

14. What will be the output of the following code?


6

6
00

00

00

00
01

01

01

01

class Q {
07

07

07

07
24

24

24

24
public static void main(String[] args) {
06

6
00

00

00
int[][] a = {
0
01

01

01

01
{1, 2},
07

07

07

07
24

24

24

24
{3, 4}
};
int sum = 0;
for (int i = 0; i < [Link]; i++)
for (int j = 0; j < a[0].length; j++)
sum += a[i][j];
[Link](sum);
}
}
6

6
Answer
00

00

00

00
01

01

01

01
12
07

07

07

07
24

24

24

24
Status : Wrong Marks : 0/1

15. What will be the output of the given code?

public class Main {


public static void main(String[] args) {
int[] arr = {1, 2, 3, 4, 5};
int n = [Link];
int temp = arr[0];
06

6
00

00

00
0
01

01

01

01
for (int i = 0; i < n - 1; i++) {
07

07

07

07
24

24

24

24
arr[i] = arr[i + 1];
}
arr[n - 1] = temp;

for (int num : arr) {


[Link](num + " ");
}
}
}
6

Answer
00

00

00

00
01

01

01

01

12345
07

07

07

07
24

24

24

24
24 24 24 24
07 07 07 07
01 01 01 01
00 0 00 0
6 06 6 06
Status : Wrong

24 24 24 24
07 07 07 07
01 01 01 01
00 00 00 00
6 6 6 6

24 24 24 24
07 07 07 07
01 01 01 01
00 00 00 00
6 6 6 6

24 24 24 24
07 07 07 07
Marks : 0/1

01 01 01 01
00 00 00 00
6 6 6 6
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 3_Q1

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
06

6
00

00

00
0

Rosh is intrigued by numerical patterns. Today, she stumbled upon a


01

01

01

01
07

07

07

puzzle while working with arrays. She wants to compute the sum of the 07
24

24

24

24
third-largest and second-smallest elements from a list of integers. She
seeks your help to implement a program that solves this for her efficiently.

Input Format
The first line of input is an integer N, representing the size of the array.

The second line of input consists of N space-separated integers, representing


the elements of the array.
Output Format
6

6
00

00

00

00

The output displays a single integer representing the sum of the third-largest and
01

01

01

01
07

07

07

07

second-smallest elements in the array.


24

24

24

24
06

6
00

00

00
0
01

01

01

01
07

07

07

07
24

24

24

24
Refer to the sample output for the formatting specifications.
Sample Test Case
Input: 10
10 20 30 40 50 60 70 80 90 100
Output: 100
Answer
// You are using Java
import [Link];
6

6
00

00

00

00
import [Link];
01

01

01

01
07

07

07

07
class main{
24

24

24

24
public static void main(String args[]){
Scanner s=new Scanner([Link]);
int b=[Link]();
int a[]=new int[b];
//a=[Link]();
for(int i=0;i<b;i++){
a[i]=[Link]();
}
int c;
[Link](a);
c=a[1]+a[b-3];
06

6
00

00

00
0

[Link](c);
01

01

01

01
07

07

07

07
}
24

24

24

24
}

Status : Correct Marks : 10/10


6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 3_Q2

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
06

6
00

00

00
0

Monica is interested in finding a treasure but the key to opening is to get


01

01

01

01
07

07

07

the sum of the main diagonal elements and secondary diagonal elements. 07
24

24

24

24

Write a program to help Monica find the diagonal sum of a square 2D array.

Note: The main diagonal of the array consists of the elements traversing
from the top-left corner to the bottom-right corner. The secondary diagonal
includes elements from the top-right corner to the bottom-left corner.

Input Format
The first line of input consists of an integer N, representing the number of rows
6

and columns.
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
The following N lines consist of N space-separated integers, representing the 2D
06

6
00

00

00
array elements.
0
01

01

01

01
07

07

07

07
Output Format
24

24

24

24
The first line of output prints "Sum of the main diagonal: " followed by an integer,
representing the sum of the main diagonal.

The second line prints "Sum of the secondary diagonal: " followed by an integer,
representing the sum of the secondary diagonal.

Refer to the sample output for formatting specifications.


6

6
00

00

00

00
01

01

01

01
Sample Test Case
07

07

07

07
24

24

24

24
Input: 3
123
456
789
Output: Sum of the main diagonal: 15
Sum of the secondary diagonal: 15
Answer
import [Link];
class main{
06

6
public static void main(String[] args) {
00

00

00
0

Scanner sc = new Scanner([Link]);


01

01

01

01
07

07

07

07
int n = [Link]();
24

24

24

24
int[][] matrix = new int[n][n];
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
matrix[i][j] = [Link]();
int mainDiagonalSum = 0;
int secondaryDiagonalSum = 0;
for (int i = 0; i < n; i++) {
mainDiagonalSum += matrix[i][i];
secondaryDiagonalSum += matrix[i][n - 1 - i];
}
6

[Link]("Sum of the main diagonal: " + mainDiagonalSum);


00

00

00

00

[Link]("Sum of the secondary diagonal: " +


01

01

01

01
07

07

07

07

secondaryDiagonalSum);
24

24

24

24
24 24 24 24
07 07 07 07

}
01 01 01 01 }
00 0 00 0
6 06 6 06

Status : Correct

24 24 24 24
07 07 07 07
01 01 01 01
00 00 00 00
6 6 6 6

24 24 24 24
07 07 07 07
01 01 01 01
00 00 00 00
6 6 6 6

24 24 24 24
07 07 07 07
Marks : 10/10

01 01 01 01
00 00 00 00
6 6 6 6
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 3_Q3

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
06

6
00

00

00
0

You are developing a warehouse management system for a shipping


01

01

01

01
07

07

07

company. The system uses an integer array to represent the weights of 07


24

24

24

24
packages in a specific order. To verify that the weight capacity is not
exceeded, the program needs to calculate the sum of the weights of the
first and last packages in the list.

Task:
Write a code to calculate the sum of the weights of the first and last
packages in the list. The program should take an integer array as input and
return the total weight of the first and last packages.
6

6
00

00

00

00

Input Format
01

01

01

01
07

07

07

07

The first line of the input is an integer N representing the size of the array.
24

24

24

24
06

6
00

00

00
The second line of the input is N space-separated integer values.
0
01

01

01

01
07

07

07

07
Output Format
24

24

24

24
The output is displayed in the following format:

"Sum of the first and last elements: <<Sum>>"

Refer to the sample output for formatting specifications.


Sample Test Case
6

6
00

00

00

00
Input: 5
01

01

01

01
10 20 30 40 50
07

07

07

07
24

24

24

24
Output: Sum of the first and last elements: 60
Answer
// You are using Java
import [Link].*;
class main{
public static void main(String args[]){
Scanner var=new Scanner([Link]);
int a=[Link]();
int[]b=new int[a];
06

6
for(int i=0;i<a;i++)
00

00

00
0

{
01

01

01

01
07

07

07

07
b[i]= [Link]();
24

24

24

24
}
[Link]("Sum of the first and last elements: %d ",b[0]+b[a-1]);

Status : Correct Marks : 10/10


6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 3_Q4

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
06

6
00

00

00
0

Sesha is developing a weather monitoring system for a region with


01

01

01

01
07

07

07

multiple weather stations. Each weather station collects temperature data 07


24

24

24

24
hourly and stores it in a 2D array.

Write a program that can add the temperature data from two different
weather stations to create a combined temperature record for the region.

Input Format
The first line of input consists of two space-separated integers N and M,
representing the number of rows and columns of the matrices, respectively.
6

The next N lines consist of M space-separated integers, representing the values


00

00

00

00

of the first matrix.


01

01

01

01
07

07

07

07
24

24

24

24
The following N lines consist of M space-separated integers, representing the
06

6
00

00

00
values of the second matrix.
0
01

01

01

01
07

07

07

07
Output Format
24

24

24

24
The output prints the addition of the two matrices in N rows and M columns,
representing the combined temperature record.

Refer to the sample output for formatting specifications.


Sample Test Case
Input: 3 3
6

6
00

00

00

00
123
01

01

01

01
456
07

07

07

07
24

24

24

24
789
111
222
333
Output: 2 3 4
678
10 11 12
Answer
// You are using Java
06

6
import [Link];
00

00

00
0

class main{
01

01

01

01
07

07

07

07
public static void main(String[] args) {
24

24

24

24
Scanner sc = new Scanner([Link]);
int N = [Link]();
int M = [Link]();
int[][] station1 = new int[N][M];
int[][] station2 = new int[N][M];
int[][] combined = new int[N][M];
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
station1[i][j] = [Link]();
}
6

}
00

00

00

00

for (int i = 0; i < N; i++) {


01

01

01

01
07

07

07

07

for (int j = 0; j < M; j++) {


24

24

24

24
station2[i][j] = [Link]();
06

6
00

00

00
}
0
01

01

01

01
}
07

07

07

07
for (int i = 0; i < N; i++) {
24

24

24

24
for (int j = 0; j < M; j++) {
combined[i][j] = station1[i][j] + station2[i][j];
}
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
[Link](combined[i][j] + " ");
}
[Link]();
}
6

6
00

00

00

00
01

01

01

01
[Link]();
07

07

07

07
}
24

24

24

24
}

Status : Correct Marks : 10/10


06

6
00

00

00
0
01

01

01

01
07

07

07

07
24

24

24

24
6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 3_Q5

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
06

6
00

00

00
0

Sharon is creating a program that finds the first repeated element in an


01

01

01

01
07

07

07

integer array. The program should efficiently identify the first element that 07
24

24

24

24
appears more than once in the given array. If no such element is found, it
should appropriately display a message.

Help Sharon to complete the program.

Input Format
The first line of input consists of an integer n, representing the number of
elements in the array.
6

The second line consists of n space-separated integers, representing the array


00

00

00

00

elements.
01

01

01

01
07

07

07

07
24

24

24

24
Output Format
06

6
00

00

00
0
01

01

01

01
If a repeated element is found, print the first element that appears more than
07

07

07

07
once.
24

24

24

24
If no repeated element is found, print "No repeated element found in the array".

Refer to the sample output for formatting specifications.


Sample Test Case
Input: 8
6

6
12 21 13 14 21 36 47 21
00

00

00

00
01

01

01

01
Output: 21
07

07

07

07
24

24

24

24
Answer
import [Link].*;
class main{
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
int n = [Link]();
int[] arr = new int[n];

for (int i = 0; i < n; i++) {


arr[i] = [Link]();
06

6
00

00

00
}
0
01

01

01

01
Set<Integer> seen = new HashSet<>();
07

07

07

boolean found = false; 07


24

24

24

24
for (int num : arr) {
if ([Link](num)) {
[Link](num);
found = true;
break;
} else {
[Link](num);
}
}
if (!found) {
6

6
00

00

00

00

[Link]("No repeated element found in the array");


01

01

01

01

}
07

07

07

07
24

24

24

24
24 24 24 24
07 07 07 07

}
01 01 01 01

}
00 0 00 0
6 06 6 06

Status : Correct
[Link]();

24 24 24 24
07 07 07 07
01 01 01 01
00 00 00 00
6 6 6 6

24 24 24 24
07 07 07 07
01 01 01 01
00 00 00 00
6 6 6 6

24 24 24 24
07 07 07 07
Marks : 10/10

01 01 01 01
00 00 00 00
6 6 6 6
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
REC_2028_OOPS using Java_Week 4_MCQ

Attempt : 1
Total Mark : 15
Marks Obtained : 8

Section 1 : MCQ

1. What will be the output for the following code?


06

6
00

00

00
0

class Main {
01

01

01

01
07

07

07

public static void main(String[] args) { 07


24

24

24

24
String languages[] = { "C", "C++", "Java", "Python", "Ruby"};
for (String sample: languages) {
[Link](sample);
}
}
}
Answer
C, C++, Java, Python, Ruby
6

Status : Wrong Marks : 0/1


00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
2. Predict the output for the following code.
06

6
00

00

00
0
01

01

01

01
class Main {
07

07

07

07
24

24

24

24
public static void main(String[] fruits) {
String fruit1 = new String("apple");
String fruit2 = new String("orange");
String fruit3 = new String("pear");
fruit3 = fruit1;
fruit2 = fruit3;
fruit1 = fruit2;
[Link](fruit1);
[Link](fruit2);
[Link](fruit3);
6

6
00

00

00

00
}
01

01

01

01
}
07

07

07

07
24

24

24

24
Answer
appleappleapple
Status : Correct Marks : 1/1

3. Predict the output for the following code:

public class Main {


public static void main(String[] args) {
06

6
00

00

00
float a = 10.0f;
0
01

01

01

01
String temp = [Link](a);
07

07

07

07
24

24

24

24
[Link](temp);
}
}
Answer
Error: no suitable method found for toString(float)
Status : Wrong Marks : 0/1

4. What will be the output of the following code?


6

6
00

00

00

00
01

01

01

01

class Main {
07

07

07

07
24

24

24

24
public static void main(String args[]) {
06

6
00

00

00
char c[] = {'j', 'a', 'v', 'a'};
0
01

01

01

01
String s1 = new String(c);
07

07

07

07
24

24

24

24
String s2 = new String(s1);
[Link](s1);
[Link](s2);
}
}
Answer
javajava
Status : Correct Marks : 1/1
6

6
00

00

00

00
01

01

01

01
5. What will be the output of the following program?
07

07

07

07
24

24

24

24
class Main {
public static void main(String[] args) {
String s = new String("5");
[Link](1 + 1111 + s + 1 + 1010);
}
}
Answer
1112531010
06

6
00

00

00
0

Status : Wrong Marks : 0/1


01

01

01

01
07

07

07

07
24

24

24

24

6. What will be the output of the following code?

class Main {
public static void main(String args[])
{
StringBuffer sb = new StringBuffer("Hello");
[Link]("buffer before = " + sb);
[Link]("charAt(1) before = " + [Link](1));
[Link](1, 'i');
6

6
00

00

00

00

[Link](2);
01

01

01

01

[Link]("buffer after = " + sb);


07

07

07

07
24

24

24

24
[Link]("charAt(1) after = " + [Link](1));
06

6
00

00

00
}
0
01

01

01

01
}
07

07

07

07
24

24

24

24
Answer
buffer before = HellocharAt(1) before = ebuffer after = HicharAt(1) after = i
Status : Correct Marks : 1/1

7. Predict the output for the following code.

public class Main {


public static void main(String[] args) {
6

6
00

00

00

00
String a = "java";
01

01

01

01
char temp = [Link](1);
07

07

07

07
24

24

24

24
[Link](temp);
}
}
Answer
a
Status : Correct Marks : 1/1

8. What will be the output of the following program?


06

6
00

00

00
0
01

01

01

01
class Main {
07

07

07

07
24

24

24

24
public static void main(String[] args) {
String greet = "Welcome\n";
[Link]("String: " + greet);
int length = [Link]();
[Link]("Length: " + length);
}
}
Answer
String: welcomeLength: 7
6

6
00

00

00

00

Status : Wrong Marks : 0/1


01

01

01

01
07

07

07

07
24

24

24

24
9. What will be the output of the following program?
06

6
00

00

00
0
01

01

01

01
class Main {
07

07

07

07
24

24

24

24
public static void main(String args[]) {
String name="Work Hard";
[Link]("Success");
[Link](name);
}
}
Answer
Work HardSuccess
Status : Wrong Marks : 0/1
6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
10. What will be the output of the following program?

public class Main {


public static void main(String[] args) {
String str = "1234.34";
int a = [Link](str);
[Link](a);
}
}
06

6
Answer
00

00

00
0
01

01

01

01
NumberFormatException
07

07

07

07
24

24

24

24
Status : Correct Marks : 1/1

11. Predict the output for the following code:

class Main {
public static void main(String args[]) {
StringBuffer sb = new StringBuffer("I Java!");
[Link](5, "like ");
[Link](sb);
6

6
00

00

00

00

}
01

01

01

01

}
07

07

07

07
24

24

24

24
Answer
06

6
00

00

00
0
01

01

01

01
I Javlike a!
07

07

07

07
Status : Correct Marks : 1/1
24

24

24

24
12. What is the output of the following code?

class Main
{
public static void main(String args[])
{
StringBuffer c = new StringBuffer("Hello");
6

6
[Link](0,2);
00

00

00

00
01

01

01

01
[Link](c);
07

07

07

07
}
24

24

24

24
}
Answer
llo
Status : Correct Marks : 1/1

13. What will be the output of the following program?


06

6
class Main {
00

00

00
0
01

01

01

01
public static void main(String args[]) {
07

07

07

StringBuffer sb = new StringBuffer("Hello"); 07


24

24

24

24
[Link]("buffer = " + sb);
[Link]("length = " + [Link]());
[Link]("capacity = " + [Link]());
}
}
Answer
buffer = Hellolength = 4capacity = 21
Status : Wrong Marks : 0/1
6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
14. What will be the output of the following program?
06

6
00

00

00
0
01

01

01

01
class Main {
07

07

07

07
24

24

24

24
public static void main(String[] args) {
String s1 = "EDUCATION";
String s2 = new String("EDUCATION");
String s3 = "EDUCATION";
if (s1 == s2) {
[Link]("s1 and s2 equal");
}
else {
[Link]("s1 and s2 not equal");
}
6

6
00

00

00

00
if (s1 == s3) {
01

01

01

01
[Link]("s1 and s3 equal");
07

07

07

07
24

24

24

24
}
else {
[Link]("s1 and s3 not equal");
}
}
}
Answer
s1 and s2 not equals1 and s3 equal
Status : Correct Marks : 1/1
06

6
00

00

00
0
01

01

01

01
07

07

07

07
24

24

24

24
15. What will be the output of the following code?

class Main {
public static void main(String args[]) {
String s1 = "Hello i love java";
String s2 = new String(s1);
[Link]((s1 == s2) + " " + [Link](s2));
}
}
6

Answer
00

00

00

00
01

01

01

01

true false
07

07

07

07
24

24

24

24
24 24 24 24
07 07 07 07
01 01 01 01
00 0 00 0
6 06 6 06
Status : Wrong

24 24 24 24
07 07 07 07
01 01 01 01
00 00 00 00
6 6 6 6

24 24 24 24
07 07 07 07
01 01 01 01
00 00 00 00
6 6 6 6

24 24 24 24
07 07 07 07
Marks : 0/1

01 01 01 01
00 00 00 00
6 6 6 6
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 4_Q1

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
06

6
00

00

00
0

In a publishing company, editors often need to quickly analyze passages of


01

01

01

01
07

07

07

text to check for punctuation usage. To assist them, you are asked to write 07
24

24

24

24
a program that counts the number of specific punctuation marks in each
passage.

The punctuation marks of interest are:


Commas (,)Periods (.)Question marks (?)
Input Format
The first line of input contains an integer T, representing the number of test
cases (passages).
6

6
00

00

00

00
01

01

01

01

Each of the next T lines contains a single passage of text.


07

07

07

07
24

24

24

24
Output Format
06

6
00

00

00
0
01

01

01

01
For each test case, print three integers separated by spaces, representing the
07

07

07

07
number of commas, periods, and question marks in the passage.
24

24

24

24
The first line of output corresponds to the first passage, the second line to the
second passage, and so on.

Refer to the sample output for formatting specifications.


Sample Test Case
6

6
Input: 1
00

00

00

00
01

01

01

01
Hello, world. How are you?
07

07

07

07
Output: 1 1 1
24

24

24

24
Answer
// You are using Java
import [Link];
class main{
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int T = [Link]([Link]());
for (int i = 0; i < T; i++) {
String passage = [Link]();
06

6
00

00

00
int commas = 0, periods = 0, questions = 0;
0
01

01

01

01
for (char c : [Link]()) {
07

07

07

if (c == ',') commas++; 07
24

24

24

24
else if (c == '.') periods++;
else if (c == '?') questions++;
}
[Link](commas + " " + periods + " " + questions);
}
}
}

Status : Correct Marks : 10/10


6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 4_Q2

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
06

6
00

00

00
0

Anu is developing a tool for a conference registration system. Participants


01

01

01

01
07

07

07

submit keywords related to their fields of interest. The organizer wants to 07


24

24

24

24
sort these keywords alphabetically to generate tags for session grouping.

Write a program that accepts at least five keywords as input arguments


and outputs them in sorted alphabetical order.

Input Format
The first line of input contains an integer n, representing the number of
keywords.
6

The second line of input contains n space-separated keywords (string).


00

00

00

00
01

01

01

01

Output Format
07

07

07

07
24

24

24

24
The output prints n space separated strings representing the sorted keyword in
06

6
00

00

00
alphabetical order.
0
01

01

01

01
07

07

07

07
24

24

24

24
Refer to the sample output for formatting specifications.
Sample Test Case
Input: 5
Blockchain Cloud AI Data Cybersecurity
Output: AI Blockchain Cloud Cybersecurity Data
Answer
6

6
00

00

00

00
// You are using Java
01

01

01

01
07

07

07

07
import [Link].*;
24

24

24

24
class main{
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int n = [Link]([Link]());
String[] keywords = [Link]().split(" ");
[Link](keywords);
for (int i = 0; i < n; i++) {
[Link](keywords[i]);
if (i < n - 1) [Link](" ");
}
}
06

6
00

00

00
0

}
01

01

01

01
07

07

07

07
24

24

24

24
Status : Correct Marks : 10/10
6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 4_Q3

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
06

6
00

00

00
0

Bechan Chacha is seeking help to filter out valid mobile numbers from a
01

01

01

01
07

07

07

list provided by his crush. He can only pick his crush's number if the list 07
24

24

24

24
contains valid mobile numbers.

A mobile number is considered valid if:

It has exactly 10 [Link] consists only of numeric values (0–9).It does not
begin with zero.
Your task is to determine whether each mobile number in the list is valid or
not.
6

6
00

00

00

00

Input Format
01

01

01

01
07

07

07

07

The first line contains an integer T, representing the number of mobile numbers
24

24

24

24
to check.
06

6
00

00

00
0
01

01

01

01
The next T lines each contain a string S, representing a mobile number.
07

07

07

07
24

24

24

24
Output Format
For each mobile number S, the output print "YES" if it is valid.

Otherwise, print "NO".

Refer to the sample output for formatting specifications.


6

6
Sample Test Case
00

00

00

00
01

01

01

01
Input: 1
07

07

07

07
24

24

24

24
9876543210
Output: YES
Answer
import [Link];
class main{
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int T = [Link]([Link]());
for (int i = 0; i < T; i++) {
06

6
String number = [Link]();
00

00

00
0

if ([Link]("[1-9][0-9]{9}")) {
01

01

01

01
07

07

07

07
[Link]("YES");
24

24

24

24
} else {
[Link]("NO");
}
}
}
}

Status : Correct Marks : 10/10


6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 4_Q4

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
06

6
00

00

00
0

Arjun is learning how to filter words from a sentence based on grammar


01

01

01

01
07

07

07

rules. He wants to identify the valid words in a sentence. 07


24

24

24

24

A word is considered valid if it satisfies all these conditions:

The word contains only alphabets (a–z, A–Z).The word length is at least 2
[Link] word should not contain digits or special characters.
Your task is to read a sentence and print all the valid words in it.

Input Format
The input contains a single line containing a sentence S.
6

6
00

00

00

00
01

01

01

01

Output Format
07

07

07

07
24

24

24

24
The output prints all the valid words separated by spaces.
06

6
00

00

00
0
01

01

01

01
If no valid word exists, print "No valid words."
07

07

07

07
24

24

24

24
Refer to the sample output for formatting specifications.
Sample Test Case
Input: Hello world1 123 ab" @#$ Hi
Output: Hello Hi
Answer
6

6
00

00

00

00
// You are using Java
01

01

01

01
07

07

07

07
import [Link].*;
24

24

24

24
class main{
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
String sentence = [Link]();
String[] words = [Link](" ");
List<String> validWords = new ArrayList<>();

for (String word : words) {


if ([Link]("[a-zA-Z]{2,}")) {
[Link](word);
}
06

6
00

00

00
0

}
01

01

01

01
07

07

07

07
24

24

24

24
if ([Link]()) {
[Link]("No valid words.");
} else {
[Link]([Link](" ", validWords));
}
}
}

Status : Correct Marks : 10/10


6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 4_Q5

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
06

6
00

00

00
0

In a secure banking system, customers are required to create PIN codes


01

01

01

01
07

07

07

for accessing their accounts. The bank wants to validate these PIN codes 07
24

24

24

24
before accepting them.

A PIN code is considered valid if:

It consists of exactly 4 [Link] characters must be numeric (0–9).It


cannot contain all identical digits (e.g., 1111 is invalid).
Your task is to determine whether each PIN code in the list is valid or not.

Input Format
6

6
00

00

00

00

The first line of input contains an integer T, representing the number of PIN
01

01

01

01

codes to check.
07

07

07

07
24

24

24

24
06

6
00

00

00
The next T lines each contain a string S, representing a PIN code.
0
01

01

01

01
07

07

07

07
Output Format
24

24

24

24
For each PIN code S, the output print "YES" if it is valid.

Otherwise, the output print "NO".

Refer to the sample output for formatting specifications.


Sample Test Case
6

6
00

00

00

00
Input: 1
01

01

01

01
1234
07

07

07

07
24

24

24

24
Output: YES
Answer
// You are using Java
import [Link];
class main{
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int T = [Link]([Link]());
for (int i = 0; i < T; i++) {
06

6
String pin = [Link]();
00

00

00
0

if ([Link]("\\d{4}") && !allSameDigits(pin)) {


01

01

01

01
07

07

07

07
[Link]("YES");
24

24

24

24
} else {
[Link]("NO");
}
}
}
static boolean allSameDigits(String pin) {
char first = [Link](0);
for (int i = 1; i < [Link](); i++) {
if ([Link](i) != first) return false;
}
6

return true;
00

00

00

00

}
01

01

01

01
07

07

07

07

}
24

24

24

24
24 24 24 24
07 07 07 07
01 01 01 01
00 0 00 0
6 06 6 06
Status : Correct

24 24 24 24
07 07 07 07
01 01 01 01
00 00 00 00
6 6 6 6

24 24 24 24
07 07 07 07
01 01 01 01
00 00 00 00
6 6 6 6

24 24 24 24
07 07 07 07
Marks : 10/10

01 01 01 01
00 00 00 00
6 6 6 6
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 5_MCQ

Attempt : 1
Total Mark : 15
Marks Obtained : 12

Section 1 : MCQ

1. What will be the output of the following code?


06

6
00

00

00
0

class A {
01

01

01

01
07

07

07

int p = 5; 07
24

24

24

24
int q = 2;
}

class Main {
public static void main(String[] args) {
A obj = new A();
[Link](obj.p + obj.q);
}
}
6

6
00

00

00

00

Answer
01

01

01

01
07

07

07

07

7
24

24

24

24
Status : Correct Marks : 1/1
06

6
00

00

00
0
01

01

01

01
07

07

07

07
2. What will be the output of the following code?
24

24

24

24
class Box {
int volume(int l, int b, int h) {
return l * b * h;
}
}

public class Main {


public static void main(String[] args) {
6

6
00

00

00

00
Box b = new Box();
01

01

01

01
[Link]([Link](2, 3, 4));
07

07

07

07
}
24

24

24

24
}
Answer
24
Status : Correct Marks : 1/1

3. What will be the output of the following code?


06

6
00

00

00
class A {
0
01

01

01

01
int x = 50;
07

07

07

} 07
24

24

24

24

public class Main {


public static void main(String[] args) {
A obj1 = new A();
A obj2 = obj1;
obj2.x = 100;
[Link](obj1.x);
}
}
6

6
00

00

00

00

Answer
01

01

01

01
07

07

07

07
24

24

24

24
100
06

6
00

00

00
0
01

01

01

01
Status : Correct Marks : 1/1
07

07

07

07
24

24

24

24
4. What will be the output of the following code?

class Box {
int length = 5;
int width = 4;

int area() {
return length * width;
}
6

6
00

00

00

00
01

01

01

01
07

07

07

07
public static void main(String[] args) {
24

24

24

24
Box b = new Box();
[Link]("Area = " + [Link]());
}
}
Answer
Area = 20
Status : Correct Marks : 1/1
06

6
00

00

00
0

5. What will be the output of the following code?


01

01

01

01
07

07

07

07
24

24

24

24
class MathUtils {
int add(int x) {
return x + x;
}
}

public class Main {


public static void main(String[] args) {
MathUtils m = new MathUtils();
[Link]([Link](5));
6

6
00

00

00

00

}
01

01

01

01

}
07

07

07

07
24

24

24

24
Answer
06

6
00

00

00
0
01

01

01

01
10
07

07

07

07
Status : Correct Marks : 1/1
24

24

24

24
6. What will be the output of the following code?

class Test {
private int value;
Test(int value) {
[Link] = value;
}
6

6
public int getValue() {
00

00

00

00
01

01

01

01
return value;
07

07

07

07
}
24

24

24

24
}
public class Main {
public static void main(String[] args) {
Test obj = new Test(10);
[Link]([Link]);
}
}
Answer
06

6
10
00

00

00
0
01

01

01

01
Status : Wrong Marks : 0/1
07

07

07

07
24

24

24

24

7. What will be the output of the following code?

class A {
int y = 30;
}

public class Main {


public static void main(String[] args) {
6

A a1 = new A();
00

00

00

00
01

01

01

01

A a2 = new A();
07

07

07

07
24

24

24

24
a1.y = 50;
06

6
00

00

00
[Link](a2.y);
0
01

01

01

01
}
07

07

07

07
24

24

24

24
}
Answer
30
Status : Correct Marks : 1/1

8. What will be the output of the following code?

class A {
6

6
00

00

00

00
int val = 20;
01

01

01

01
}
07

07

07

07
24

24

24

24
public class Main {
public static void main(String[] args) {
A obj1 = new A();
A obj2 = obj1;
[Link] += 5;
[Link]([Link]);
}
}
06

6
Answer
00

00

00
0
01

01

01

01
20
07

07

07

07
24

24

24

24
Status : Wrong Marks : 0/1

9. What will be the output of the following code?

class Person {
String name;
void setName(String n) {
name = n;
}
6

6
00

00

00

00

void printName() {
01

01

01

01

[Link](name);
07

07

07

07
24

24

24

24
}
06

6
00

00

00
}
0
01

01

01

01
07

07

07

07
24

24

24

24
class Test {
public static void main(String[] args) {
Person p = new Person();
[Link]();
}
}
Answer
null
Status : Correct Marks : 1/1
6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
10. What will be the output of the following code?

class Alpha {
void greet(String name) {
[Link]("Hello " + name);
}
}

public class Main {


public static void main(String[] args) {
06

6
00

00

00
Alpha obj = new Alpha();
0
01

01

01

01
[Link]("Anu");
07

07

07

07
24

24

24

24
}
}
Answer
Anu
Status : Wrong Marks : 0/1

11. What is the output of the following code?


6

6
00

00

00

00

class Box {
01

01

01

01

int height;
07

07

07

07
24

24

24

24
Box(int height) {
06

6
00

00

00
[Link] = height;
0
01

01

01

01
}
07

07

07

07
24

24

24

24
void modifyHeight(Box b) {
[Link] += 10;
}
}
public class Main {
public static void main(String[] args) {
Box b1 = new Box(20);
[Link](b1);
[Link]([Link]);
}
6

6
00

00

00

00
}
01

01

01

01
07

07

07

07
Answer
24

24

24

24
30
Status : Correct Marks : 1/1

12. What will be the output of the following code?

class Ball {
int size = 11;
}
06

6
00

00

00
0
01

01

01

01
class Game {
07

07

07

07
24

24

24

24
public static void main(String[] args) {
Ball b1 = new Ball();
Ball b2 = new Ball();
[Link] = 10;
[Link]([Link]);
}
}
Answer
11
6

6
00

00

00

00

Status : Correct Marks : 1/1


01

01

01

01
07

07

07

07
24

24

24

24
13. What will be the output of the following code?
06

6
00

00

00
0
01

01

01

01
class Sample {
07

07

07

07
24

24

24

24
int x = 10;

void display() {
[Link]("x = " + x);
}

public static void main(String[] args) {


Sample s = new Sample();
[Link]();
}
6

6
00

00

00

00
}
01

01

01

01
07

07

07

07
Answer
24

24

24

24
x = 10
Status : Correct Marks : 1/1

14. What will be the output of the following code?

class Person {
int age = 18;
}
06

6
00

00

00
0
01

01

01

01
public class Main {
07

07

07

07
24

24

24

24
public static void main(String[] args) {
Person p = new Person();
[Link] += 2;
[Link]("Age: " + [Link]);
}
}
Answer
Age: 20
Status : Correct Marks : 1/1
6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
15. What will be the output of the following code?
06

6
00

00

00
0
01

01

01

01
class Demo {
07

07

07

07
24

24

24

24
void printMessage() {
[Link]("Hello from Demo");
}
}

public class Main {


public static void main(String[] args) {
Demo d = new Demo();
[Link]();
}
6

6
00

00

00

00
}
01

01

01

01
07

07

07

07
Answer
24

24

24

24
Hello from Demo
Status : Correct Marks : 1/1
06

6
00

00

00
0
01

01

01

01
07

07

07

07
24

24

24

24
6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 5_Q2

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
06

6
00

00

00
0

You are working as a developer for CityBank, which wants to build a basic
01

01

01

01
07

07

07

account management system. 07


24

24

24

24

Each customer at the bank has:

An Account Number (integer)A Customer Name (string)An Initial Balance


(double)
The bank allows two types of transactions:

Deposit – increases the [Link] – decreases the balance only


if enough funds are available.
6

6
00

00

00

00

If the withdrawal amount is greater than the balance, the withdrawal


01

01

01

01
07

07

07

07

should not happen, and the balance should remain the same.
24

24

24

24
06

6
You are required to implement this system using:

00

00

00
0
01

01

01

01
07

07

07

07
A class with attributes for account details.A constructor to initialize
24

24

24

24
account [Link] methods to update details if [Link] methods
to retrieve [Link] of the class to represent customers.
Finally, display each customer’s account details after all transactions.

Input Format
The first line of input contains an integer N, representing the number of
customers.

For each customer:


6

6
00

00

00

00
01

01

01

01
- The next line contains the account number (integer).
07

07

07

07
24

24

24

24
- The following line contains the customer name (string).
- The next line contains the initial balance (double).
- The next line contains the deposit amount (double).
- The next line contains the withdrawal amount (double).
Output Format
For each customer, print the details in the following format:

1. Account Number: <account_number>


2. Customer Name: <customer_name>
3. Final Balance: <final_balance> (rounded to one decimal place)
06

6
00

00

00
0
01

01

01

01
07

07

07

07
24

24

24

24

Refer to the sample output for formatting specifications.


Sample Test Case
Input: 1
1234
Rahul Sharma
5000
2000
3000
6

6
00

00

00

00
01

01

01

01

Output: Account Number: 1234


07

07

07

07

Customer Name: Rahul Sharma


24

24

24

24
Final Balance: 4000.0
06

6
00

00

00
0
01

01

01

01
Answer
07

07

07

07
// You are using Java
24

24

24

24
import [Link].*;

class Account {
private int accountNumber;
private String customerName;
private double balance;

public Account(int accountNumber, String customerName, double balance) {


[Link] = accountNumber;
[Link] = customerName;
6

6
00

00

00

00
[Link] = balance;
01

01

01

01
}
07

07

07

07
24

24

24

24
public void setAccountNumber(int accountNumber) {
[Link] = accountNumber;
}

public void setCustomerName(String customerName) {


[Link] = customerName;
}

public void setBalance(double balance) {


[Link] = balance;
06

6
00

00

00
}
0
01

01

01

01
07

07

07

public int getAccountNumber() { 07


24

24

24

24
return accountNumber;
}

public String getCustomerName() {


return customerName;
}

public double getBalance() {


return balance;
}
6

6
00

00

00

00
01

01

01

01

public void deposit(double amount) {


07

07

07

07
24

24

24

24
balance += amount;
06

6
00

00

00
}
0
01

01

01

01
07

07

07

07
public void withdraw(double amount) {
24

24

24

24
if (amount <= balance) {
balance -= amount;
}
}
}

class main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int n = [Link]([Link]());
6

6
00

00

00

00
List<Account> accounts = new ArrayList<>();
01

01

01

01
07

07

07

07
for (int i = 0; i < n; i++) {
24

24

24

24
int accNo = [Link]([Link]());
String name = [Link]();
double initBalance = [Link]([Link]());
double depositAmt = [Link]([Link]());
double withdrawAmt = [Link]([Link]());

Account acc = new Account(accNo, name, initBalance);


[Link](depositAmt);
[Link](withdrawAmt);
[Link](acc);
06

6
00

00

00
}
0
01

01

01

01
07

07

07

for (Account a : accounts) { 07


24

24

24

24
[Link]("Account Number: " + [Link]());
[Link]("Customer Name: " + [Link]());
[Link]("Final Balance: %.1f\n", [Link]());
}
}
}

Status : Correct Marks : 10/10


6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 5_Q3

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
06

6
00

00

00
0

Neha is working as a developer for CityElectricity Board, which wants to


01

01

01

01
07

07

07

build a household electricity billing system. 07


24

24

24

24

Each customer’s electricity account has:

A Customer ID (integer)A Customer Name (string)Units Consumed (double)


The electricity bill is calculated based on these rules:

For the first 100 units 5 units charge per unitFor the next 100 units (101–
200) 7 units charge per unitFor units above 200 10 units charge per
unitIf the total bill exceeds 2000 units, a 5% discount is applied on the final
6

6
00

00

00

00

bill.
01

01

01

01
07

07

07

07

Neha has been asked to implement this system using:


24

24

24

24
06

6
A class with attributes for customer details.A constructor to initialize

00

00

00
0
01

01

01

01
customer [Link] methods to update details if [Link]
07

07

07

07
methods to retrieve [Link] of the class to represent customers.
24

24

24

24
Finally, display each customer’s details and final bill amount.

Input Format
The first line of input contains an integer N, representing the number of
customers.

For each customer:

- The next line contains the Customer ID (integer).


6

6
00

00

00

00
- The following line contains the Customer Name (string).
01

01

01

01
- The next line contains the Units Consumed (double).
07

07

07

07
24

24

24

24
Output Format
For each customer, print the details in the following format:

Customer ID: <customer_id>

Customer Name: <customer_name>

Final Bill: <final_bill> (rounded to one decimal place)


06

6
00

00

00
0
01

01

01

01
07

07

07

07
24

24

24

24
Refer to the sample output for formatting specifications.
Sample Test Case
Input: 1
1001
Ravi Kumar
80
Output: Customer ID: 1001
Customer Name: Ravi Kumar
Final Bill: 400.0
6

6
00

00

00

00

Answer
01

01

01

01
07

07

07

07

import [Link].*;
24

24

24

24
06

6
00

00

00
class Customer {
0
01

01

01

01
private int customerId;
07

07

07

07
private String customerName;
24

24

24

24
private double unitsConsumed;

public Customer(int customerId, String customerName, double


unitsConsumed) {
[Link] = customerId;
[Link] = customerName;
[Link] = unitsConsumed;
}

public void setCustomerId(int customerId) {


6

6
00

00

00

00
[Link] = customerId;
01

01

01

01
}
07

07

07

07
24

24

24

24
public void setCustomerName(String customerName) {
[Link] = customerName;
}

public void setUnitsConsumed(double unitsConsumed) {


[Link] = unitsConsumed;
}

public int getCustomerId() {


return customerId;
06

6
00

00

00
}
0
01

01

01

01
07

07

07

public String getCustomerName() { 07


24

24

24

24
return customerName;
}

public double getUnitsConsumed() {


return unitsConsumed;
}

public double calculateBill() {


double bill = 0;
double units = unitsConsumed;
6

6
00

00

00

00
01

01

01

01

if (units <= 100) {


07

07

07

07
24

24

24

24
bill = units * 5;
06

6
00

00

00
} else if (units <= 200) {
0
01

01

01

01
bill = 100 * 5 + (units - 100) * 7;
07

07

07

07
} else {
24

24

24

24
bill = 100 * 5 + 100 * 7 + (units - 200) * 10;
}

if (bill > 2000) {


bill = bill * 0.95;
}

return bill;
}
}
6

6
00

00

00

00
01

01

01

01
class main {
07

07

07

07
public static void main(String[] args) {
24

24

24

24
Scanner sc = new Scanner([Link]);
int n = [Link]([Link]());
List<Customer> customers = new ArrayList<>();

for (int i = 0; i < n; i++) {


int id = [Link]([Link]());
String name = [Link]();
double units = [Link]([Link]());
[Link](new Customer(id, name, units));
}
06

6
00

00

00
0
01

01

01

01
for (Customer c : customers) {
07

07

07

[Link]("Customer ID: " + [Link]()); 07


24

24

24

24
[Link]("Customer Name: " + [Link]());
[Link]("Final Bill: %.1f\n", [Link]());
}
}
}

Status : Correct Marks : 10/10


6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 5_Q4

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
06

6
00

00

00
0

You are working as a developer for CityCab, a taxi service company that
01

01

01

01
07

07

07

wants to build a ride fare management system. 07


24

24

24

24

Each customer booking has:

A Booking ID (integer)A Customer Name (string)A Distance Travelled in km


(double)
The fare calculation rules are:

Base Fare = 50 units (flat charge for every ride).Per km charge = 10 units/
[Link] the distance is greater than 20 km, a 10% discount is applied on the
6

6
00

00

00

00

total fare.
01

01

01

01
07

07

07

07

You are required to implement this system using:


24

24

24

24
06

6
A class with attributes for booking details.A constructor to initialize

00

00

00
0
01

01

01

01
booking [Link] methods to update details if [Link] methods
07

07

07

07
to retrieve [Link] of the class to represent customer rides.
24

24

24

24
Finally, display each booking’s details and final fare.

Input Format
The first line of input contains an integer N, representing the number of
bookings.

For each booking:

- The next line contains the booking ID (integer).


6

6
00

00

00

00
- The following line contains the customer's name (string).
01

01

01

01
- The next line contains the distance travelled (double).
07

07

07

07
24

24

24

24
Output Format
For each booking, print the details in the following format:

1. Booking ID: <booking_id>


2. Customer Name: <customer_name>
3. Final Fare: <final_fare> (rounded to one decimal place)
06

6
00

00

00
Refer to the sample output for formatting specifications.
0
01

01

01

01
07

07

07

Sample Test Case 07


24

24

24

24

Input: 1
1234
Rahul Sharma
15
Output: Booking ID: 1234
Customer Name: Rahul Sharma
Final Fare: 200.0
Answer
6

import [Link].*;
00

00

00

00
01

01

01

01
07

07

07

07

class Booking {
24

24

24

24
private int bookingId;
06

6
00

00

00
private String customerName;
0
01

01

01

01
private double distance;
07

07

07

07
24

24

24

24
public Booking(int bookingId, String customerName, double distance) {
[Link] = bookingId;
[Link] = customerName;
[Link] = distance;
}

public void setBookingId(int bookingId) {


[Link] = bookingId;
}
6

6
00

00

00

00
public void setCustomerName(String customerName) {
01

01

01

01
[Link] = customerName;
07

07

07

07
}
24

24

24

24
public void setDistance(double distance) {
[Link] = distance;
}

public int getBookingId() {


return bookingId;
}

public String getCustomerName() {


06

6
00

00

00
return customerName;
0
01

01

01

01
}
07

07

07

07
24

24

24

24
public double getDistance() {
return distance;
}

public double calculateFare() {


double fare = 50 + (distance * 10);
if (distance > 20) {
fare = fare * 0.9;
}
return fare;
6

6
00

00

00

00

}
01

01

01

01

}
07

07

07

07
24

24

24

24
06

6
00

00

00
class main {
0
01

01

01

01
public static void main(String[] args) {
07

07

07

07
Scanner sc = new Scanner([Link]);
24

24

24

24
int n = [Link]([Link]());
List<Booking> bookings = new ArrayList<>();

for (int i = 0; i < n; i++) {


int id = [Link]([Link]());
String name = [Link]();
double distance = [Link]([Link]());
[Link](new Booking(id, name, distance));
}
6

6
00

00

00

00
for (Booking b : bookings) {
01

01

01

01
[Link]("Booking ID: " + [Link]());
07

07

07

07
[Link]("Customer Name: " + [Link]());
24

24

24

24
[Link]("Final Fare: %.1f\n", [Link]());
}
}
}

Status : Correct Marks : 10/10


06

6
00

00

00
0
01

01

01

01
07

07

07

07
24

24

24

24
6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 5_Q5

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
06

6
00

00

00
0

Ram is working as a developer for BrightEdu Coaching Center, which wants


01

01

01

01
07

07

07

to build a student fee management system. 07


24

24

24

24

Each student’s enrollment has:

An Enrollment ID (integer)A Student Name (string)The Number of Subjects


(integer)
The fee calculation rules are:

Registration Fee = 1000 units (flat for every student).Per Subject Fee = 800
[Link] the student enrolls in more than 5 subjects, a 20% scholarship
6

6
00

00

00

00

(discount) is applied on the total fee.


01

01

01

01
07

07

07

07

Ram has been asked to implement this system using:


24

24

24

24
06

6
A class with attributes for student details.A constructor to initialize student

00

00

00
0
01

01

01

01
[Link] methods to update details if [Link] methods to
07

07

07

07
retrieve [Link] of the class to represent student enrollments.
24

24

24

24
Finally, display each student’s details and final fee.

Input Format
The first line of input contains an integer N, representing the number of students.

For each student:

- The next line contains the Enrollment ID (integer).


- The following line contains the student’s name (string).
6

6
00

00

00

00
- The next line contains the Number of subjects (integer).
01

01

01

01
07

07

07

07
Output Format
24

24

24

24
For each student, print the details in the following format:

- Enrollment ID: <enrollment_id>


- Student Name: <student_name>
- Final Fee: <final_fee> (rounded to one decimal place)

Refer to the sample output for formatting specifications.


06

6
00

00

00
0
01

01

01

01
Sample Test Case
07

07

07

07
24

24

24

24
Input: 1
1234
Ravi Kumar
3
Output: Enrollment ID: 1234
Student Name: Ravi Kumar
Final Fee: 3400.0
Answer
// You are using Java
6

import [Link].*;
00

00

00

00
01

01

01

01
07

07

07

07

class Student {
24

24

24

24
private int enrollmentId;
06

6
00

00

00
private String studentName;
0
01

01

01

01
private int numberOfSubjects;
07

07

07

07
24

24

24

24
public Student(int enrollmentId, String studentName, int numberOfSubjects) {
[Link] = enrollmentId;
[Link] = studentName;
[Link] = numberOfSubjects;
}

public void setEnrollmentId(int enrollmentId) {


[Link] = enrollmentId;
}
6

6
00

00

00

00
public void setStudentName(String studentName) {
01

01

01

01
[Link] = studentName;
07

07

07

07
}
24

24

24

24
public void setNumberOfSubjects(int numberOfSubjects) {
[Link] = numberOfSubjects;
}

public int getEnrollmentId() {


return enrollmentId;
}

public String getStudentName() {


06

6
00

00

00
return studentName;
0
01

01

01

01
}
07

07

07

07
24

24

24

24
public int getNumberOfSubjects() {
return numberOfSubjects;
}

public double calculateFee() {


double fee = 1000 + numberOfSubjects * 800;
if (numberOfSubjects > 5) {
fee = fee * 0.8;
}
return fee;
6

6
00

00

00

00

}
01

01

01

01

}
07

07

07

07
24

24

24

24
06

6
00

00

00
class main {
0
01

01

01

01
public static void main(String[] args) {
07

07

07

07
Scanner sc = new Scanner([Link]);
24

24

24

24
int n = [Link]([Link]());
List<Student> students = new ArrayList<>();

for (int i = 0; i < n; i++) {


int id = [Link]([Link]());
String name = [Link]();
int subjects = [Link]([Link]());
[Link](new Student(id, name, subjects));
}
6

6
00

00

00

00
for (Student s : students) {
01

01

01

01
[Link]("Enrollment ID: " + [Link]());
07

07

07

07
[Link]("Student Name: " + [Link]());
24

24

24

24
[Link]("Final Fee: %.1f\n", [Link]());
}
}
}

Status : Correct Marks : 10/10


06

6
00

00

00
0
01

01

01

01
07

07

07

07
24

24

24

24
6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
REC_2028_OOPS using Java_Week 6_MCQ

Attempt : 1
Total Mark : 15
Marks Obtained : 12

Section 1 : MCQ

1. What will be the output of the following program?


06

6
00

00

00
0

class A {
01

01

01

01
07

07

07

public int i; 07
24

24

24

24
private int j;
}
class B extends A {
void display() {
super.j = super.i + 1;
[Link](super.i + " " + super.j);
}
}
class inheritance {
public static void main(String args[]) {
6

6
00

00

00

00

B obj = new B();


01

01

01

01
07

07

07

07

obj.i=1;
24

24

24

24
obj.j=2;
06

6
00

00

00
[Link]();
0
01

01

01

01
}
07

07

07

07
24

24

24

24
}
Answer
Compile Time Error
Status : Correct Marks : 1/1

2. What will be the output of the following Java program?

class Test {
6

6
00

00

00

00
void display(int a, int b) {
01

01

01

01
[Link]("Method 1");
07

07

07

07
24

24

24

24
}
void display(double a, double b) {
[Link]("Method 2");
}
public static void main(String[] args) {
Test obj = new Test();
[Link](10, 10.0);
}
}
06

6
Answer
00

00

00
0
01

01

01

01
Method 2
07

07

07

07
24

24

24

24
Status : Correct Marks : 1/1

3. What will be the output of the following program?

class A {
int x = 10;
}

class B extends A {
6

6
00

00

00

00

int x = 20;
01

01

01

01

}
07

07

07

07
24

24

24

24
06

6
00

00

00
class C extends B {
0
01

01

01

01
int x = 30;
07

07

07

07
24

24

24

24
void display() {
[Link](x);
[Link](super.x);
}
}

class Test {
public static void main(String[] args) {
C obj = new C();
6

6
00

00

00

00
[Link]();
01

01

01

01
}
07

07

07

07
24

24

24

24
}
Answer
3020
Status : Correct Marks : 1/1

4. What will be the output of the following Java program?

class A {
06

6
00

00

00
void display() {
0
01

01

01

01
[Link]("Class A");
07

07

07

07
24

24

24

24
}
}

class B extends A {
void show() {
[Link]("Class B");
}
}

class C extends B {
6

6
00

00

00

00

void print() {
01

01

01

01

[Link]("Class C");
07

07

07

07
24

24

24

24
}
06

6
00

00

00
}
0
01

01

01

01
07

07

07

07
24

24

24

24
class Test {
public static void main(String[] args) {
C obj = new C();
[Link]();
[Link]();
[Link]();
}
}
Answer
6

6
00

00

00

00
Class AClass BClass C
01

01

01

01
07

07

07

07
Status : Correct Marks : 1/1
24

24

24

24
5. What will be the output of the following Java program?

class Vehicle {
void start() {
[Link]("Vehicle starts");
}
}
class Car extends Vehicle {
06

6
00

00

00
0
01

01

01

01
void start() {
07

07

07

07
24

24

24

24
[Link]("Car starts");
}
}
class ElectricCar extends Car {
void start() {
[Link]("Electric Car starts silently");
}
}
class Test {
public static void main(String[] args) {
6

6
00

00

00

00

Vehicle v = new ElectricCar();


01

01

01

01

[Link]();
07

07

07

07
24

24

24

24
}
06

6
00

00

00
}
0
01

01

01

01
07

07

07

07
Answer
24

24

24

24
Electric Car starts silently
Status : Correct Marks : 1/1

6. What will be the output of the following Java program?

class A {
int value = 10;
void display() {
6

6
00

00

00

00
[Link]("A's display: " + value);
01

01

01

01
}
07

07

07

07
24

24

24

24
}
class B extends A {
int value = 20;
void display() {
[Link]("B's display: " + value);
}
}
class Test {
public static void main(String[] args) {
A obj = new B();
06

6
00

00

00
[Link]();
0
01

01

01

01
[Link]("Value: " + [Link]);
07

07

07

07
24

24

24

24
}
}
Answer
B's display: 20 Value: 10
Status : Correct Marks : 1/1

7. What will be the output of the following Java program?


6

6
00

00

00

00

class Test {
01

01

01

01

void show(int a) {
07

07

07

07
24

24

24

24
[Link]("Integer method");
06

6
00

00

00
}
0
01

01

01

01
void show(String s) {
07

07

07

07
24

24

24

24
[Link]("String method");
}
public static void main(String[] args) {
Test obj = new Test();
[Link](null);
}
}
Answer
Compilation error due to ambiguous method call
6

6
00

00

00

00
Status : Wrong Marks : 0/1
01

01

01

01
07

07

07

07
24

24

24

24
8. What will be the output of the following code?

class A {
void display() {
[Link]("Display A");
}
}

class B extends A {
06

6
00

00

00
void display() {
0
01

01

01

01
[Link]("Display B");
07

07

07

07
24

24

24

24
}
}

class C extends B {
void display() {
[Link]();
}
}

class Test {
6

6
00

00

00

00

public static void main(String[] args) {


01

01

01

01

C obj = new C();


07

07

07

07
24

24

24

24
[Link]();
06

6
00

00

00
}
0
01

01

01

01
}
07

07

07

07
24

24

24

24
Answer
Display B
Status : Correct Marks : 1/1

9. What will be the output of the following Java program?

class Parent {
void show() {
6

6
00

00

00

00
[Link]("Parent class");
01

01

01

01
}
07

07

07

07
24

24

24

24
}
class Child extends Parent {
void show() {
[Link]("Child class");
}
}
class Test {
public static void main(String[] args) {
Parent obj = new Child();
[Link]();
06

6
00

00

00
}
0
01

01

01

01
}
07

07

07

07
24

24

24

24
Answer
Child class
Status : Correct Marks : 1/1

10. Select the correct keyword for implementing inheritance through the
class.

Answer
6

6
00

00

00

00

extends
01

01

01

01
07

07

07

07
24

24

24

24
Status : Correct Marks : 1/1
06

6
00

00

00
0
01

01

01

01
07

07

07

07
11. What will be the output of the following program?
24

24

24

24
class Vehicle {
String type = "Vehicle";
}

class Car extends Vehicle {


String type = "Car";
}
6

6
00

00

00

00
class Test {
01

01

01

01
public static void main(String[] args) {
07

07

07

07
Car c = new Car();
24

24

24

24
[Link]([Link]);
}
}
Answer
Car
Status : Correct Marks : 1/1
06

6
00

00

00
12. What will be the output of the following Java program?
0
01

01

01

01
07

07

07

class Vehicle { 07
24

24

24

24
void startEngine() {
[Link]("Vehicle engine started");
}
}

class Car extends Vehicle {


void startEngine() {
[Link]("Car engine started");
}
6

}
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
class Main {
06

6
00

00

00
public static void main(String[] args) {
0
01

01

01

01
Vehicle myVehicle = new Car();
07

07

07

07
24

24

24

24
[Link]();
}
}
Answer
Vehicle engine started
Status : Wrong Marks : 0/1

13. Which of the following is true about method overriding in Java?


6

6
00

00

00

00
01

01

01

01
Answer
07

07

07

07
24

24

24

24
The method must have the same name, same parameters, and must be in
different classes with an inheritance relationship
Status : Correct Marks : 1/1

14. Which of the following is the correct way for class B to inherit from
class A?

Answer
06

6
00

00

00
class B extends A {}
0
01

01

01

01
07

07

07

07
Status : Correct Marks : 1/1
24

24

24

24

15. What will be the output of the following code?

class A {
int sum(int x) {
return x + 2;
}
}
6

6
00

00

00

00

class B extends A {
01

01

01

01

int sum(int x) {
07

07

07

07
24

24

24

24
return [Link](x) * 2;
06

6
00

00

00
}
0
01

01

01

01
}
07

07

07

07
24

24

24

24
class C extends B {
int sum(int x) {
return [Link](x) - 3;
}
}

class Test {
public static void main(String[] args) {
C obj = new C();
6

6
00

00

00

00
[Link]([Link](4));
01

01

01

01
}
07

07

07

07
24

24

24

24
}
Answer
8
Status : Wrong Marks : 0/1
06

6
00

00

00
0
01

01

01

01
07

07

07

07
24

24

24

24
6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 6_Q1

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
06

6
00

00

00
0

Elsa subscribes to a premium service with a base monthly cost, a service


01

01

01

01
07

07

07

tax and an extra feature cost. Assist her in writing an inheritance program 07
24

24

24

24
that takes input for these values and calculates the total monthly cost.

Refer to the below class diagram:

Input Format
The first line of input consists of a double value, representing the base monthly
cost.
6

The second line consists of a double value, representing the service tax.
00

00

00

00
01

01

01

01
07

07

07

07

The third line consists of a double value, representing the extra feature cost.
24

24

24

24
Output Format
06

6
00

00

00
0
01

01

01

01
The output prints "Rs. X" where X is a double value, rounded off to two decimal
07

07

07

07
places.
24

24

24

24
Refer to the sample output for formatting specifications.
Sample Test Case
Input: 10.0
2.5
5.0
6

6
00

00

00

00
Output: Rs. 17.50
01

01

01

01
07

07

07

07
Answer
24

24

24

24
import [Link];
class Subscription
{
double baseMonthlyCost;
double serviceTax;

public Subscription(double baseMonthlyCost,double serviceTax){


[Link] = baseMonthlyCost;
[Link] = serviceTax;
}
06

6
00

00

00
0
01

01

01

01
07

07

07

07
public double total()
24

24

24

24
{
return baseMonthlyCost+serviceTax;
}
}
class PremiumSubscription extends Subscription
{
double extraFeatureCost;

public PremiumSubscription(double baseMonthlyCost,double serviceTax,


double extraFeatureCost)
{
6

6
00

00

00

00

super(baseMonthlyCost,serviceTax);
01

01

01

01
07

07

07

07

[Link] = extraFeatureCost;
24

24

24

24
}
06

6
00

00

00
public double calculateMonthlyCost()
0
01

01

01

01
{
07

07

07

07
return total()+extraFeatureCost;
24

24

24

24
}
}
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);

double baseMonthlyCost = [Link]();


double serviceTax = [Link]();
double extraFeatureCost = [Link]();
6

6
00

00

00

00
01

01

01

01
PremiumSubscription premiumSubscription = new
07

07

07

07
PremiumSubscription(baseMonthlyCost, serviceTax, extraFeatureCost);
24

24

24

24
double totalMonthlyCost = [Link]();

[Link]("Rs. %.2f%n", totalMonthlyCost);

[Link]();
}
}

Status : Correct Marks : 10/10


06

6
00

00

00
0
01

01

01

01
07

07

07

07
24

24

24

24
6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 6_Q2

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
06

6
00

00

00
0

Alice is managing an online store and wants to implement a program using


01

01

01

01
07

07

07

inheritance to calculate the selling price of products after applying 07


24

24

24

24
discounts.

Guide her by following the instructions:


Create a base class called Product with a public double attribute
[Link] a subclass called DiscountedProduct, which extends Product
and includes a private double attribute discount rate. This subclass has a
method called calculateSellingPrice() to determine the final selling price
after applying the discount.
Formula: Discounted selling price = price * (1 - discount rate)
6

6
00

00

00

00
01

01

01

01
07

07

07

07

Input Format
24

24

24

24
The first line of input consists of a double value p, the initial price of the product.
06

6
00

00

00
0
01

01

01

01
The second line consists of a double value d, the discount rate.
07

07

07

07
24

24

24

24
Output Format
The output prints "Rs. X", where X is a double value, representing the calculated
discounted selling price, rounded off to two decimal places.

If the discount rate is greater than 1, print "Not applicable".

Refer to the sample output for formatting specifications.


6

6
00

00

00

00
01

01

01

01
Sample Test Case
07

07

07

07
24

24

24

24
Input: 50.00
0.20
Output: Rs. 40.00
Answer
import [Link];
// You are using Java
class Product {
public double price;
06

6
00

00

00
public Product(double price) {
0
01

01

01

01
[Link] = price;
07

07

07

} 07
24

24

24

24
}

class DiscountedProduct extends Product {


private double discountRate;

public DiscountedProduct(double price, double discountRate) {


super(price);
[Link] = discountRate;
}
6

6
00

00

00

00
01

01

01

01

public double calculateSellingPrice() {


07

07

07

07
24

24

24

24
if (discountRate > 1) {
06

6
00

00

00
0
01

01

01

01
return -1;
07

07

07

07
} else {
24

24

24

24
return price * (1 - discountRate);
}
}
}
class ProductPricing {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);

double initialPrice = [Link]();


6

6
double discountRate = [Link]();
00

00

00

00
01

01

01

01
DiscountedProduct discountedProduct = new
07

07

07

07
DiscountedProduct(initialPrice, discountRate);
24

24

24

24
double sellingPrice = [Link]();

if (sellingPrice >= 0) {
[Link]("Rs. %.2f%n", sellingPrice);
} else {
[Link]("Not applicable");
}
[Link]();
}
}
06

6
00

00

00
0
01

01

01

01
Status : Correct Marks : 10/10
07

07

07

07
24

24

24

24
6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 6_Q3

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
06

6
00

00

00
0

Preethi is working on a project to automate sales tax calculations for items


01

01

01

01
07

07

07

in a store. She wants to create a program that takes the price of an item 07
24

24

24

24
and the sales tax rate as input and calculates the final price of the item
after applying the sales tax.

Write a program using the class SalesTaxCalculator, which contains an


overloaded method named calculateFinalPrice to handle both integer and
double inputs. The program should also include a Main class that takes
user input, calls the appropriate method from SalesTaxCalculator, and
prints the final price of the item.

Formula Used: Final price = price + ((price * sales tax rate) / 100)
6

6
00

00

00

00
01

01

01

01
07

07

07

07

Input Format
24

24

24

24
The first line of input consists of an integer price (the price of the item for integer
06

6
00

00

00
inputs).
0
01

01

01

01
07

07

07

07
The second line of input consists of an integer taxRate (the sales tax rate for
24

24

24

24
integer inputs).

The third line of input consists of a double price (the price of the item for double
inputs).

The fourth line of input consists of a double taxRate (the sales tax rate for
double inputs).
Output Format
The first line of output prints an integer, representing the final price of the item
6

6
00

00

00

00
after applying the sales tax for integer inputs (a and b).
01

01

01

01
07

07

07

07
24

24

24

24
The second line prints a double value, representing the final price of the item
after applying the sales tax for double-value inputs (m and n), rounded to two
decimal places.

Refer to the sample output for formatting specifications.


Sample Test Case
Input: 100
06

6
00

00

00
0

10
01

01

01

01
100.0
07

07

07

07
24

24

24

24
5.0
Output: 110
105.00
Answer
import [Link];
// You are using Java
// You are using Java
class SalesTaxCalculator
{
6

6
00

00

00

00

public static int calculateFinalPrice(int price,int taxRate)


01

01

01

01

{
07

07

07

07
24

24

24

24
return price + (price*taxRate)/100;
06

6
00

00

00
}
0
01

01

01

01
public static double calculateFinalPrice(double price,double taxRate)
07

07

07

07
{
24

24

24

24
return price + (price*taxRate)/100;
}
}
class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
int intPrice = [Link]();
int intTaxRate = [Link]();
double doublePrice = [Link]();
6

6
double doubleTaxRate = [Link]();
00

00

00

00
01

01

01

01
07

07

07

07
int finalPriceInt = [Link](intPrice,
24

24

24

24
intTaxRate);
double finalPriceDouble =
[Link](doublePrice, doubleTaxRate);

[Link](finalPriceInt);
[Link]("%.2f", finalPriceDouble);
}
}

Status : Correct Marks : 10/10


06

6
00

00

00
0
01

01

01

01
07

07

07

07
24

24

24

24
6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 6_Q4

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
06

6
00

00

00
0

[Link] wants to create a program to calculate the volume of a Cuboid


01

01

01

01
07

07

07

and a Cube using method overriding. 07


24

24

24

24

Implements a base class Cuboid with attributes for length, width, and
height. Include a method calculateVolume() that computes the volume of
the cuboid.

Extends the base class with a subclass Cube representing a cube, where
all sides are equal. Override the calculateVolume() method in the Cube
class to compute the volume of the cube.

The program should take user input for the dimensions of the cuboid and
6

6
00

00

00

00

the side length of the cube and display the calculated volumes with two
01

01

01

01
07

07

07

07

decimal places.
24

24

24

24
06

6
Input Format

00

00

00
0
01

01

01

01
The first line of input consists of 3 space-separated double values, representing
07

07

07

07
24

the cuboid length, width, and height, respectively.

24

24

24
The second line consists of a double value, representing the side length of the
cube.
Output Format
The first line of output prints the volume of the cuboid, rounded off to two
decimal places.

The second line prints the volume of the cube, rounded off to two decimal
places.
6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
Refer to the sample output for formatting specifications.
Sample Test Case
Input: 60.0 60.0 60.0
50.0
Output: Volume of Cuboid: 216000.00
Volume of Cube: 125000.00
Answer
06

6
00

00

00
0

import [Link];
01

01

01

01
07

07

07

// You are using Java 07


24

24

24

24
class Cuboid
{
double length;
double width;
double height;
public Cuboid(double length,double width,double height)
{
[Link] = length;
[Link] = width;
[Link] = height;
6

6
00

00

00

00

}
01

01

01

01

public double calculateVolume()


07

07

07

07
24

24

24

24
{
06

6
00

00

00
return length*width*height;
0
01

01

01

01
}
07

07

07

07
24

24

24

24
}
class Cube extends Cuboid
{
public Cube(double side)
{
super(side,side,side);
}
public double calculateVolume()
{
return length*width*height;
6

6
00

00

00

00
}
01

01

01

01
}
07

07

07

07
24

24

24

24
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);

double cuboidLength = [Link]();


double cuboidWidth = [Link]();
double cuboidHeight = [Link]();

// Regular object instantiation for Cuboid


Cuboid cuboid = new Cuboid(cuboidLength, cuboidWidth, cuboidHeight);
06

6
[Link]("Volume of Cuboid: %.2f\n", [Link]());
00

00

00
0
01

01

01

01
07

07

07

double cubeSide = [Link]();


07
24

24

24

24

// Upcasting - Using superclass reference for subclass object (DMD)


Cuboid cube = new Cube(cubeSide); // Upcasting
[Link]("Volume of Cube: %.2f", [Link]()); // Calls
Cube's method dynamically

[Link]();
}
}
6

Status : Correct Marks : 10/10


00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 6_Q5

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem statement:
06

6
00

00

00
0

Tim was tasked with developing a grocery shopping app. You have a class
01

01

01

01
07

07

07

hierarchy that includes Item, Produce, and OrganicProduce. Your goal is to 07


24

24

24

24
calculate the total cost of a shopping list, which may contain a mix of
regular produce and organic produce items. Additionally, you need to apply
discounts to organic items. Apply a 10% discount on organic produce items

Class Hierarchy:
Item: Base class for all items.
Produce: Subclass of Item for regular produce items.
OrganicProduce: Subclass of Produce for organic produce items.
6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06

6
Input Format

00

00

00
0
01

01

01

01
The first line of input consists of an integer, 'n'.
07

07

07

07
24

24

24

24
For each 'n' item, the user will provide:

- A string 'type' representing the item type ('Regular' or 'Organic').


- A string 'name' represents the item name.
- A double 'price' represents the item price.
Output Format
The output will display the total cost of the shopping list, including discounts on
organic items.
6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
Refer to the sample output for format specifications.
Sample Test Case
Input: 1
Regular Banana 1.99
Output: 1.99
Answer
import [Link];
06

6
00

00

00
class Item {
0
01

01

01

01
protected String name;
07

07

07

protected double price; 07


24

24

24

24

public Item(String name, double price) {


[Link] = name;
[Link] = price;
}

public double calculateCost() {


return price;
}
}
6

6
00

00

00

00

class Produce extends Item {


01

01

01

01
07

07

07

07
24

24

24

24
public Produce(String name, double price) {
06

6
00

00

00
super(name, price);
0
01

01

01

01
}
07

07

07

07
24

24

24

24
@Override
public double calculateCost() {
return price;
}
}
class OrganicProduce extends Produce {

public OrganicProduce(String name, double price) {


super(name, price);
6

6
00

00

00

00
}
01

01

01

01
07

07

07

07
@Override
24

24

24

24
public double calculateCost() {
return price * 0.9;
}
}
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);

int n = [Link]();
06

6
[Link](); // Consume newline
00

00

00
0
01

01

01

01
07

07

07

double totalCost = 0.0;


07
24

24

24

24

for (int i = 0; i < n; i++) {


String type = [Link]();
String name = [Link]();
double price = [Link]();

if ([Link]("Regular")) {
Item item = new Produce(name, price);
totalCost += [Link]();
} else if ([Link]("Organic")) {
6

Item item = new OrganicProduce(name, price);


00

00

00

00
01

01

01

01

totalCost += [Link]();
07

07

07

07

}
24

24

24

24
24 24 24 24
07 07 07 07

}
01 01 01 01

}
00 0 00 0 }
6 06 6 06

Status : Correct

24 24 24 24
07 07 07 07
01 01 01 01
00 00 00 00
6 6 6 6
[Link]("%.2f%n", totalCost);

24 24 24 24
07 07 07 07
01 01 01 01
00 00 00 00
6 6 6 6

24 24 24 24
07 07 07 07
Marks : 10/10

01 01 01 01
00 00 00 00
6 6 6 6
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
REC_2028_OOPS using Java_Week 7_MCQ

Attempt : 1
Total Mark : 15
Marks Obtained : 15

Section 1 : MCQ

1. What happens when an implementing class does not override a default


06

6
method from an interface?
00

00

00
0
01

01

01

01
07

07

07

Answer
07
24

24

24

24
The default method's implementation from the interface will be used.
Status : Correct Marks : 1/1

2. Consider a class implementing an interface and extending a class, both


having a method with the same name. Which method gets called?

Answer
The method from the superclass
6

6
00

00

00

00
01

01

01

01

Status : Correct Marks : 1/1


07

07

07

07
24

24

24

24
3. Can a Java interface contain both default and static methods?
06

6
00

00

00
0
01

01

01

01
Answer
07

07

07

07
24

24

24

24
Yes, an interface can have both default and static methods.
Status : Correct Marks : 1/1

4. What is the output of the following code?

interface X {
default void show() {
[Link]("X's Default Method");
6

6
}
00

00

00

00
01

01

01

01
}
07

07

07

07
24

24

24

24
interface Y {
default void show() {
[Link]("Y's Default Method");
}
}

class Z implements X, Y {
public void show() {
[Link]("Z's Method");
06

6
}
00

00

00
0
01

01

01

01
}
07

07

07

07
24

24

24

24
public class Main {
public static void main(String[] args) {
Z obj = new Z();
[Link]();
}
}
Answer
Z's Method
6

Status : Correct Marks : 1/1


00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
5. What is the output of the following code?
06

6
00

00

00
0
01

01

01

01
interface A {
07

07

07

07
24

24

24

24
default void show() {
[Link]("A's Default Method");
}
}

class B {
public void show() {
[Link]("B's Method");
}
}
6

6
00

00

00

00
01

01

01

01
class C extends B implements A {
07

07

07

07
24

24

24

24
}

public class Main {


public static void main(String[] args) {
C obj = new C();
[Link]();
}
}
Answer
06

6
00

00

00
B's Method
0
01

01

01

01
07

07

07

07
Status : Correct Marks : 1/1
24

24

24

24

6. Which of the following statements about Java interfaces is true?

Answer
A class can implement multiple interfaces.
Status : Correct Marks : 1/1
6

7. Which of the following statements is true regarding default methods in


00

00

00

00
01

01

01

01

Java interfaces?
07

07

07

07
24

24

24

24
06

6
Answer

00

00

00
0
01

01

01

01
A default method can be overridden in a class implementing the interface.
07

07

07

07
24

24

24

24
Status : Correct Marks : 1/1

8. What is the output of the following code?

interface A {
static void display() {
[Link]("Static method in A");
}
}
6

6
00

00

00

00
01

01

01

01
class B implements A {
07

07

07

07
24

24

24

24
static void display() {
[Link]("Static method in B");
}
}

public class Main {


public static void main(String[] args) {
[Link]();
}
}
06

6
00

00

00
0
01

01

01

01
Answer
07

07

07

07
24

24

24

24
Static method in B
Status : Correct Marks : 1/1

9. Which of the following is the correct way to declare an interface in


Java?

Answer
interface Vehicle { void start();}
6

6
00

00

00

00

Status : Correct Marks : 1/1


01

01

01

01
07

07

07

07
24

24

24

24
10. How do you call a static method from an interface MyInterface?
06

6
00

00

00
0
01

01

01

01
Answer
07

07

07

07
24

24

24

24
[Link]();
Status : Correct Marks : 1/1

11. What is the primary purpose of static methods in Java interfaces?

Answer
They allow an interface to provide helper methods without requiring an
implementing class.
6

6
00

00

00

00
Status : Correct Marks : 1/1
01

01

01

01
07

07

07

07
24

24

24

24
12. How can a class explicitly call a default method from an interface if
there is a naming conflict?

Answer
Using [Link]();
Status : Correct Marks : 1/1
06

6
13. What is the output of the following code?
00

00

00
0
01

01

01

01
07

07

07

interface A { 07
24

24

24

24
default void show() {
[Link]("A's Default Method");
}
}

interface B {
default void show() {
[Link]("B's Default Method");
}
6

}
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
class C implements A, B {
06

6
00

00

00
public void show() {
0
01

01

01

01
[Link]();
07

07

07

07
24

24

24

24
}
}

public class Main {


public static void main(String[] args) {
C obj = new C();
[Link]();
}
}
6

6
Answer
00

00

00

00
01

01

01

01
A's Default Method
07

07

07

07
24

24

24

24
Status : Correct Marks : 1/1

14. If a class implements two interfaces that have the same default
method, what must the class do?

Answer
The class must override the method to resolve ambiguity.
Status : Correct Marks : 1/1
06

6
00

00

00
0
01

01

01

01
07

07

07

15. What is the output of the following code? 07


24

24

24

24

interface MathOperations {
static int square(int x) {
return x * x;
}
}

public class Main {


public static void main(String[] args) {
6

[Link]([Link](5));
00

00

00

00
01

01

01

01

}
07

07

07

07
24

24

24

24
24 24 24 24
07 07 07 07
}

25
01 01 01 01
00 0 00 0
6 06 6 Answer
06

Status : Correct

24 24 24 24
07 07 07 07
01 01 01 01
00 00 00 00
6 6 6 6

24 24 24 24
07 07 07 07
01 01 01 01
00 00 00 00
6 6 6 6

24 24 24 24
07 07 07 07
Marks : 1/1

01 01 01 01
00 00 00 00
6 6 6 6
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 7_Q1

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement:
06

6
00

00

00
0

Rajiv is analyzing the energy consumption in his household and wants to


01

01

01

01
07

07

07

calculate the total cost based on the daily energy usage. He is given the 07
24

24

24

24
rate per unit of electricity and the energy consumed for multiple days. To
structure this calculation efficiently, he decides to use an interface-based
approach.

Implement an interface CostCalculator with the necessary methods to


retrieve energy details and compute the cost. The calculations should be
handled in the EnergyConsumptionTracker class, while the
EnergyConsumptionApp class should only handle input and output.

Formula
6

6
00

00

00

00
01

01

01

01

Energy Cost for one day = Energy Consumed per day * Rate Per Unit
07

07

07

07
24

24

24

24
06

6
Input Format

00

00

00
0
01

01

01

01
The first line of input consists of the rate per unit as an 'R' (a double value).
07

07

07

07
24

24

24

24
The second line of input consists of the number of days 'N' (an integer).

The third line of input consists of the daily energy consumption values for each
day 'D" (double values), separated by space.
Output Format
The first line of the output prints: "Day-wise Energy Cost:"

The next N lines of the output print the day-wise energy costs(double type) and
the total energy cost (double type) in Indian Rupees in the following format: "Day
6

6
00

00

00

00
[day_number]: Rs. [energy_cost]"
01

01

01

01
07

07

07

07
24

24

24

24
The last line of the output prints: "Total Energy Cost: Rs. [total_cost]"

Note: energy_cost and total_cost are rounded off to two decimal points

Refer to the sample output for the formatting specifications.


06

6
00

00

00
0
01

01

01

01
Sample Test Case
07

07

07

07
24

24

24

24
Input: 0.01
3
10.0 20.0 30.0
Output: Day-wise Energy Cost:
Day 1: Rs. 0.10
Day 2: Rs. 0.20
Day 3: Rs. 0.30
Total Energy Cost: Rs. 0.60
Answer
6

import [Link];
00

00

00

00
01

01

01

01

// You are using Java


07

07

07

07
24

24

24

24
interface CostCalculator{
06

6
00

00

00
void getEnergyDetails (Scanner scanner);
0
01

01

01

01
void calculateAndDisplayCost();
07

07

07

07
}
24

24

24

24
class EnergyConsumptionTracker implements CostCalculator{
private double ratePerUnit;
private int numDays;
private double[] energyConsumption;

public EnergyConsumptionTracker(double ratePerUnit,int numDays){


[Link]=ratePerUnit;
[Link]=numDays;
[Link]= new double[numDays];
}
6

6
00

00

00

00
@Override
01

01

01

01
public void getEnergyDetails(Scanner scanner){
07

07

07

07
for(int i=0;i<numDays;i++){
24

24

24

24
energyConsumption[i]=[Link]();
}
}
@Override
public void calculateAndDisplayCost(){
[Link]("Day-wise Energy Cost:");
double totalCost=0;
for(int i=0;i<numDays;i++){
double dailyCost=energyConsumption[i]*ratePerUnit;
totalCost+=dailyCost;
06

6
00

00

00
[Link]("Day %d: Rs.%.2f%n",i+1,dailyCost);
0
01

01

01

01
07

07

07

} 07
24

24

24

24
[Link]("Total Energy Cost: Rs.%.2f%n",totalCost);
}
}
class EnergyConsumptionApp {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);

double ratePerUnit = [Link]();


int numDays = [Link]();
6

6
00

00

00

00
01

01

01

01

CostCalculator tracker = new EnergyConsumptionTracker(ratePerUnit,


07

07

07

07

numDays);
24

24

24

24
24 24 24 24
07 07 07 07

}
01 01 01 01

}
00 0 00 0
6 06 6 06

Status : Correct
[Link]();

24 24 24 24
07 07 07 07
01 01 01 01
00 00 00 00
6 6 6 6
[Link](scanner);
[Link]();

24 24 24 24
07 07 07 07
01 01 01 01
00 00 00 00
6 6 6 6

24 24 24 24
07 07 07 07
Marks : 10/10

01 01 01 01
00 00 00 00
6 6 6 6
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 7_Q2

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
06

6
00

00

00
0

Jaheer is working on a health monitoring system to help individuals


01

01

01

01
07

07

07

calculate their Body Mass Index (BMI). He has implemented a basic BMI 07
24

24

24

24
calculator and an interface called HealthCalculator. It should have a
method called calculateBMI.

You are tasked with creating a program that takes weight and height as
input, calculates the BMI using the BMICalculator class, and displays the
result. If the height or weight is less than or equal to zero, then return -1.

Formula: BMI = weight / (height * height)

Input Format
6

6
00

00

00

00
01

01

01

01

The first line of input consists of a double value W, the person's weight in
07

07

07

07

kilograms.
24

24

24

24
06

6
00

00

00
The second line consists of a double value H, the height of the person in meters.
0
01

01

01

01
07

07

07

07
Output Format
24

24

24

24
The output displays "BMI: " followed by a double value, representing the
calculated BMI, rounded off to two decimal places.

Refer to the sample output for formatting specifications.


Sample Test Case
Input: 70.0
6

6
00

00

00

00
1.75
01

01

01

01
07

07

07

07
Output: BMI: 22.86
24

24

24

24
Answer
import [Link];
// You are using Java
interface HealthCalculator {
double calculateBMI(double weight, double height);
}
class BMICalculator implements HealthCalculator {
public double calculateBMI(double weight, double height) {
if (weight <= 0 || height <= 0) {
06

6
00

00

00
return -1;
0
01

01

01

01
}
07

07

07

return weight / (height * height); 07


24

24

24

24
}
}

class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);

double weight = [Link]();


double height = [Link]();
6

6
00

00

00

00

BMICalculator bmiCalculator = new BMICalculator();


01

01

01

01
07

07

07

07
24

24

24

24
24 24 24 24
07 07 07 07

}
01 01 01 01

}
00 0 00 0
6 06 6 06

Status : Correct
[Link]();

24 24 24 24
07 07 07 07
01 01 01 01
00 00 00 00
6 6 6 6
[Link]("BMI: %.2f\n", bmi);

24 24 24 24
07 07 07 07
01 01 01 01
00 00 00 00
6 6 6 6
double bmi = [Link](weight, height);

24 24 24 24
07 07 07 07
Marks : 10/10

01 01 01 01
00 00 00 00
6 6 6 6
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 7_Q3

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
06

6
00

00

00
0

A financial analyst, Alex, needs a program to calculate simple interest for


01

01

01

01
07

07

07

various financial transactions. He requires a straightforward tool that takes 07


24

24

24

24
in the principal amount, interest rate, and time in years and computes the
interest.

The formula to be used is: Interest = Principal × Rate × Time / 100

Implement this functionality using the InterestCalculator interface and the


SimpleInterestCalculator class.

Input Format
6

The first line of input consists of the principal amount P as a double value.
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
The second line of input consists of the annual interest rate r as a double value.
06

6
00

00

00
0
01

01

01

01
The third line of input consists of the number of years t as a positive integer,
07

07

07

07
which is an integer value.
24

24

24

24
Output Format
The output displays the calculated simple interest in the following format:
"Simple Interest: [interest_value]", Here, [interest_value] should be replaced with
the actual interest value calculated by the program.

Refer to the sample output for the formatting specifications.


6

6
00

00

00

00
01

01

01

01
Sample Test Case
07

07

07

07
24

24

24

24
Input: 1000.00
5.00
2
Output: Simple Interest: 100.0
Answer
import [Link];
// You are using Java
interface InterestCalculator{
double simpleInterest(double principal,double rate,int time);
06

6
00

00

00
}
0
01

01

01

01
class SimpleInterestCalculator implements InterestCalculator{
07

07

07

@Override 07
24

24

24

24
public double simpleInterest(double principal, double rate,int time){
return (principal*rate*time)/100; } }
class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);

double principal = [Link]();

double rate = [Link]();


6

6
00

00

00

00

int time = [Link]();


01

01

01

01
07

07

07

07
24

24

24

24
InterestCalculator calculator = new SimpleInterestCalculator();
06

6
00

00

00
0
01

01

01

01
double interest = [Link](principal, rate, time);
07

07

07

07
24

24

24

24
[Link]("Simple Interest: " + interest);

}
}

Status : Correct Marks : 10/10


6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06

6
00

00

00
0
01

01

01

01
07

07

07

07
24

24

24

24
6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 7_Q4

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
06

6
00

00

00
0

Maria, a software developer, is working on an inventory management


01

01

01

01
07

07

07

system project using Java that utilizes an inventory interface to manage a 07


24

24

24

24
store's products.

The interface should define two methods: addProduct, which adds a


product by accepting its name, price, and quantity, and
calculateTotalValue, which computes the total value of all products in the
inventory. Implement the interface in a class called SimpleInventory, which
internally manages a list of Product objects.

Each Product object should encapsulate the product's name, price, and
quantity and include a method to calculate its value as price × quantity.
6

6
00

00

00

00

The system should allow users to dynamically add products to the


01

01

01

01
07

07

07

07

inventory and calculate the total value of all products stored.


24

24

24

24
06

6
Help Maria achieve the task.

00

00

00
0
01

01

01

01
07

07

07

07
Input Format
24

24

24

24
The first line of input consists of an integer to choose one of the following
options:

1 - to add a product to the inventory.

2 - to calculate and view the total inventory value.

3 - to exit the program.

For Choice 1 (Add Product):


6

6
00

00

00

00
01

01

01

01
The next input line is the string representing the product name as a string (single
07

07

07

07
24

24

24

24
or multi-word, without quotes).

The next line is a double value representing the price as a decimal value

The next line is an integer value representing the quantity as an integer

For Choices 2 and 3, no additional input is required


Output Format
The output displays the results of the commands as follows:
06

6
00

00

00
0

- For the addProduct command, the program should display "Product added to
01

01

01

01
07

07

07

07
inventory."
24

24

24

24
- For choice 2, the program should display "Total inventory value [totalvalue].
"The total value should be displayed with one decimal place. If there is no
product in the inventory, print the total as 0.0.
- For choice 3, the program should exit

If the choice is not 1, 2, or 3, then print "Invalid choice. Please select a valid
option (1/2/3).".
6

6
00

00

00

00

Refer to the sample output for the formatting specifications.


01

01

01

01
07

07

07

07
24

24

24

24
Sample Test Case
06

6
00

00

00
0
01

01

01

01
Input: 1
07

07

07

07
Laptop
24

24

24

24
800.0
3
2
5
3
Output: Product added to inventory.
Total inventory value: $2400.0
Invalid choice. Please select a valid option (1/2/3).
Answer
6

6
import [Link];
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
import [Link];
import [Link];
interface Inventory {
void addProduct(String name, double price, int quantity);
double calculateTotalValue();
}
class Product {
private String name;
private double price;
private int quantity;
public Product(String name, double price, int quantity) {
06

6
00

00

00
0

[Link] = name; [Link] = price; [Link] = quantity;


01

01

01

01
}
07

07

07

07
24

24

24

24
public double getValue() {
return price * quantity;
}

} class SimpleInventory implements Inventory {


private List<Product> products;
public SimpleInventory(int capacity) {
products = new ArrayList<>(capacity);

} @Override
public void addProduct(String name, double price, int quantity) {
6

6
00

00

00

00

[Link](new Product(name, price, quantity));


01

01

01

01

[Link]("Product added to inventory.");


07

07

07

07
24

24

24

24
}
06

6
00

00

00
@Override
0
01

01

01

01
public double calculateTotalValue() {
07

07

07

07
double total = 0.0; for (Product product : products) {
24

24

24

24
total += [Link]();
}
return [Link](total * 10.0) / 10.0;

}
}
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
6

6
Inventory inventory = new SimpleInventory(10);
00

00

00

00
01

01

01

01
while (true) {
07

07

07

07
int choice = [Link]();
24

24

24

24
if (choice == 1) {
[Link]();
String productName = [Link]();
double price = [Link]();
int quantity = [Link]();
[Link](productName, price, quantity);
} else if (choice == 2) {
double totalValue = [Link]();
[Link]("Total inventory value: $" + totalValue);
} else if (choice == 3) {
06

6
break;
00

00

00
0
01

01

01

01
} else {
07

07

07

[Link]("Invalid choice. Please select a valid option


07
24

24

24

24
(1/2/3).");
}
}
[Link]();
}
}

Status : Correct Marks : 10/10


6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 7_Q5

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
06

6
00

00

00
0

Raj is curious about how old he is in the current year.


01

01

01

01
07

07

07

07
24

24

24

24
He has asked you to create a simple program that calculates a person's
age based on their birth year. You decide to implement this functionality
using the AgeCalculator interface and the HumanAgeCalculator class.

Note: The current year is 2024. Calculate the current age by using the
formula: current year - birth year.

Input Format
The input consists of an integer representing the birth year.
6

6
00

00

00

00

Output Format
01

01

01

01
07

07

07

07
24

24

24

24
The output displays "You are X years old." where X is an integer representing the
06

6
00

00

00
calculated age based on the entered birth year.
0
01

01

01

01
07

07

07

07
24

24

24

24
Refer to the sample output for formatting specifications.
Sample Test Case
Input: 1934
Output: You are 90 years old.
Answer
import [Link];
6

6
00

00

00

00
01

01

01

01
// You are using Java
07

07

07

07
interface AgeCalculator{
24

24

24

24
int calculateAge(int birthYear);
}
class HumanAgeCalculator implements AgeCalculator{
private static final int CURRENT_YEAR=2024;
@Override
public int calculateAge(int birthYear){
return CURRENT_YEAR-birthYear;
}
}
class AgeCalculatorApp {
06

6
00

00

00
0

public static void main(String[] args) {


01

01

01

01
07

07

07

07
Scanner scanner = new Scanner([Link]);
24

24

24

24

AgeCalculator ageCalculator = new HumanAgeCalculator();

int birthYear = [Link]();


int age = [Link](birthYear);

[Link]("You are " + age + " years old.");


}
}

Status : Correct Marks : 10/10


6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
REC_2028_OOPS using Java_Week 8_MCQ

Attempt : 1
Total Mark : 15
Marks Obtained : 15

Section 1 : MCQ

1. What is the purpose of a custom exception in Java?


06

6
00

00

00
0

Answer
01

01

01

01
07

07

07

To create user-defined exceptions for specific scenarios 07


24

24

24

24

Status : Correct Marks : 1/1

2. How do you create an unchecked custom exception?

Answer
By extending RuntimeException
Status : Correct Marks : 1/1
6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
3. What will be the output for the following code?
06

6
00

00

00
0
01

01

01

01
class InvalidUsernameException extends Exception {
07

07

07

07
24

24

24

24
public InvalidUsernameException(String message) {
super(message);
}
}

class Test {
public static void main(String[] args) {
try {
String username = "abc";
if ([Link]() < 5) {
6

6
00

00

00

00
throw new InvalidUsernameException("Username must be at
01

01

01

01
least 5 characters long");
07

07

07

07
24

24

24

24
}
} catch (InvalidUsernameException e) {
[Link]([Link]());
}
}
}
Answer
Username must be at least 5 characters long
Status : Correct Marks : 1/1
06

6
00

00

00
0
01

01

01

01
07

07

07

07
24

24

24

24
4. What will be the output of the following code?

class MyException extends Exception {


public MyException() {
super("Default Exception Message");
}
}

class Test {
public static void main(String[] args) {
6

6
00

00

00

00

try {
01

01

01

01

throw new MyException();


07

07

07

07
24

24

24

24
} catch (MyException e) {
06

6
00

00

00
[Link]([Link]());
0
01

01

01

01
}
07

07

07

07
24

24

24

24
}
}
Answer
Default Exception Message
Status : Correct Marks : 1/1

5. What will be the output for the following code?


6

6
00

00

00

00
import [Link].*;
01

01

01

01
07

07

07

07
24

24

24

24
class TemperatureTooHighException extends Exception {
public TemperatureTooHighException(String message) {
super(message);
}
}

class Test {
public static void main(String[] args) {
try {
int temperature = 110;
06

6
00

00

00
if (temperature > 100) {
0
01

01

01

01
throw new TemperatureTooHighException("Temperature too
07

07

07

07
24

24

24

24
high");
}
} catch (TemperatureTooHighException e) {
[Link]([Link]());
}
}
}
Answer
Temperature too high
6

6
00

00

00

00

Status : Correct Marks : 1/1


01

01

01

01
07

07

07

07
24

24

24

24
6. What will be the output for the following code?
06

6
00

00

00
0
01

01

01

01
class NegativeBalanceException extends Exception {
07

07

07

07
24

24

24

24
public NegativeBalanceException(String message) {
super(message);
}
}

class Test {
public static void main(String[] args) {
try {
double balance = -500;
if (balance < 0) {
6

6
00

00

00

00
throw new NegativeBalanceException("Balance cannot be
01

01

01

01
negative");
07

07

07

07
24

24

24

24
}
} catch (NegativeBalanceException e) {
[Link]("Error: " + [Link]());
}
}
}
Answer
Error: Balance cannot be negative
Status : Correct Marks : 1/1
06

6
00

00

00
0
01

01

01

01
07

07

07

07
24

24

24

24
7. what is the output of the following code?

class MyException extends Exception {


public MyException(String message) {
super(message);
}
}

class Test {
public static void main(String[] args) {
6

6
00

00

00

00

try {
01

01

01

01

throw new MyException("Error occurred");


07

07

07

07
24

24

24

24
} catch (MyException e) {
06

6
00

00

00
[Link](e);
0
01

01

01

01
}
07

07

07

07
24

24

24

24
}
}
Answer
MyException: Error occurred
Status : Correct Marks : 1/1

8. What will happen if a checked custom exception is thrown inside a


method without being caught or declared?
6

6
00

00

00

00
01

01

01

01
Answer
07

07

07

07
24

24

24

24
Compilation Error
Status : Correct Marks : 1/1

9. Which of the following is true about custom exceptions?

Answer
Custom exceptions must extend either Exception or RuntimeException
Status : Correct Marks : 1/1
06

6
00

00

00
0
01

01

01

01
07

07

07

07
24

24

24

24
10. Which keyword is used to explicitly throw a custom exception?

Answer
throw
Status : Correct Marks : 1/1

11. What will be the output for the following code?


6

import [Link].*;
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
class UnderageException extends Exception {
06

6
00

00

00
public UnderageException(String message) {
0
01

01

01

01
super(message);
07

07

07

07
24

24

24

24
}
}

class Test {
public static void main(String[] args) {
try {
int age = 17;
if (age < 18) {
throw new UnderageException("Underage, cannot proceed");
}
6

6
00

00

00

00
} catch (UnderageException e) {
01

01

01

01
[Link]([Link]());
07

07

07

07
24

24

24

24
}
}
}
Answer
Underage, cannot proceed
Status : Correct Marks : 1/1

12. What will be the output for the following code?


06

6
00

00

00
0
01

01

01

01
class InvalidVotingAgeException extends Exception {
07

07

07

07
24

24

24

24
public InvalidVotingAgeException(String message) {
super(message);
}
}

class Test {
public static void main(String[] args) {
try {
int age = 15;
if (age < 18) {
6

6
00

00

00

00

throw new InvalidVotingAgeException("You are not eligible to


01

01

01

01

vote");
07

07

07

07
24

24

24

24
}
06

6
00

00

00
[Link]("Eligible to vote");
0
01

01

01

01
} catch (InvalidVotingAgeException e) {
07

07

07

07
24

24

24

24
[Link]([Link]());
}
}
}
Answer
You are not eligible to vote
Status : Correct Marks : 1/1
6

6
00

00

00

00
13. What will be the output for the following code?
01

01

01

01
07

07

07

07
24

24

24

24
import [Link].*;

class NegativeAgeException extends Exception {


public NegativeAgeException(String message) {
super(message);
}
}

class Test {
public static void main(String[] args) {
06

6
00

00

00
try {
0
01

01

01

01
int age = -5;
07

07

07

07
24

24

24

24
if (age < 0) {
throw new NegativeAgeException("Age cannot be negative");
}
} catch (NegativeAgeException e) {
[Link]([Link]());
}
}
}
Answer
6

6
00

00

00

00

Age cannot be negative


01

01

01

01
07

07

07

07

Status : Correct Marks : 1/1


24

24

24

24
14. what is the output of the following code?
06

6
00

00

00
0
01

01

01

01
class MyException extends Exception {
07

07

07

07
24

24

24

24
public MyException(String message) {
super(message);
}
}

class Test {
static void check() throws MyException {
throw new MyException("Custom Exception Occurred");
}
6

6
00

00

00

00
public static void main(String[] args) {
01

01

01

01
try {
07

07

07

07
24

24

24

24
check();
} catch (Exception e) {
[Link]([Link]());
}
}
}
Answer
Custom Exception Occurred
Status : Correct Marks : 1/1
06

6
00

00

00
0
01

01

01

01
07

07

07

07
24

24

24

24
15. What will be the output for the following code?

import [Link].*;

class OutOfStockException extends Exception {


public OutOfStockException(String message) {
super(message);
}
}
6

6
00

00

00

00

class Test {
01

01

01

01

public static void main(String[] args) {


07

07

07

07
24

24

24

24
try {
06

6
00

00

00
int stock = 0;
0
01

01

01

01
if (stock == 0) {
07

07

07

07
24

24

24

24
throw new OutOfStockException("Item is out of stock");
}
} catch (OutOfStockException e) {
[Link]([Link]());
}
}
}
Answer
Item is out of stock
6

6
00

00

00

00
Status : Correct Marks : 1/1
01

01

01

01
07

07

07

07
24

24

24

24
06

6
00

00

00
0
01

01

01

01
07

07

07

07
24

24

24

24
6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 8_Q1

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
06

6
00

00

00
0

Write a program to validate the email address and display suitable


01

01

01

01
07

07

07

exceptions if there is any mistake. 07


24

24

24

24

Create 3 custom exception classes as below


DotExceptionAtTheRateExceptionDomainException
A typical email address should have a " . " character, and a "@" character,
and also the domain name should be valid. Valid domain names for
practice be 'in', 'com', 'net', or 'biz'.

Display Invalid Dot usage, Invalid @ usage, or Invalid Domain message


based on email id.
6

6
00

00

00

00
01

01

01

01
07

07

07

07

Get the email address from the user, validate the email by checking the
24

24

24

24
above-mentioned criteria, and print the validity status of the input email
06

6
00

00

00
address.
0
01

01

01

01
07

07

07

07
24

24

24

24
Input Format
The first line of input contains the email to be validated.
Output Format
The output prints a Valid email address or an Invalid email address along with
the suitable exception

If email ends with . or contains not exactly one . after @, it throws:

DotException: Invalid Dot usage


6

6
00

00

00

00
01

01

01

01
Invalid email address
07

07

07

07
24

24

24

24
If @ appears not exactly once, it throws:

AtTheRateException: Invalid @ usage

Invalid email address


06

6
00

00

00
0
01

01

01

01
07

07

07

If the part after the last dot is not among accepted domains: 07
24

24

24

24

DomainException: Invalid Domain

Invalid email address

If all conditions satisfied then print:


6

6
00

00

00

00

Valid email address


01

01

01

01
07

07

07

07
24

24

24

24
06

6
00

00

00
0
01

01

01

01
07

07

07

07
Refer to the sample input and output for format specifications.
24

24

24

24
Sample Test Case
Input: sample@[Link]
Output: Valid email address
Answer
// You are using Java
import [Link];
class DotException extends Exception{
DotException(String message){
6

6
00

00

00

00
super(message);
01

01

01

01
07

07

07

07
}
24

24

24

24
}

class AtTheRateException extends Exception{


AtTheRateException(String message){
super(message);
}
}

class DomainException extends Exception{


DomainException(String message){
super(message);
06

6
00

00

00
0

}
01

01

01

01
07

07

07

07
}
24

24

24

24
public class Main{
public static void main(String args[]){
Scanner s=new Scanner([Link]);
String email=[Link]();
try{
validate(email);
[Link]("Valid email address");
}
catch(DotException e){
[Link]("DotException: "+[Link]());
[Link]("Invalid email address");
6

6
00

00

00

00

}
01

01

01

01
07

07

07

07

catch(AtTheRateException e){
24

24

24

24
[Link]("AtTheRateException: "+[Link]());
06

6
00

00

00
[Link]("Invalid email address");
0
01

01

01

01
}
07

07

07

07
catch(DomainException e){
24

24

24

24
[Link]("DomainException: "+[Link]());
[Link]("Invalid email address");
}
}
static void validate(String email) throws
DotException,AtTheRateException,DomainException{
if([Link](".")||[Link](".")||[Link]("..")){
throw new DotException("Invalid Dot usage");
}
int atCount=[Link]()-[Link]("@", "").length();
6

6
00

00

00

00
if(atCount!=1 || [Link]("@")||[Link]("@")||
01

01

01

01
[Link]("@@")){
07

07

07

07
throw new AtTheRateException("Invalid @ usage");
24

24

24

24
}
int atIndex = [Link]("@");
String afterAt = [Link](atIndex + 1);
int dotCountAfterAt = [Link]() - [Link](".", "").length();
if (dotCountAfterAt != 1) {
throw new DotException("Invalid Dot usage");
}

int lastDotIndex = [Link](".");


String domain = [Link](lastDotIndex + 1);
06

6
00

00

00
if (!([Link]("in") || [Link]("com") || [Link]("net") ||
0
01

01

01

01
[Link]("biz"))) {
07

07

07

throw new DomainException("Invalid Domain"); 07


24

24

24

24
}
}
}

Status : Correct Marks : 10/10


6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 8_Q2

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
06

6
00

00

00
0

Elsa, a busy professional, is using a scheduling application to plan her


01

01

01

01
07

07

07

meetings efficiently. The application requires users to input meeting 07


24

24

24

24
durations in minutes, ensuring that the duration is a positive integer and
does not exceed 240 minutes (4 hours). Elsa needs a program to assist her
in scheduling meetings securely with proper exception handling.

Create a Java class named [Link] a custom


exception:InvalidDurationException for invalid meeting duration
[Link] the main method to interactively take user input for a
meeting [Link] the validateMeetingDuration method to
validate the meeting duration based on the specified rules and throw a
custom exception if the validation [Link] appropriate success or error
6

6
00

00

00

00

messages based on the meeting duration.


01

01

01

01
07

07

07

07
24

24

24

24
Implement a custom exception, InvalidDurationException, to handle cases
06

6
00

00

00
where the entered meeting duration does not meet the specified criteria.
0
01

01

01

01
07

07

07

07
24

24

24

24
Input Format
The input consists of an integer value 'n', representing the meeting duration.
Output Format
The output is displayed in the following format:

If the entered meeting duration meets the specified criteria, the program outputs

"Meeting scheduled successfully!"


6

6
00

00

00

00
If the entered meeting duration is invalid, the program outputs an error message
01

01

01

01
indicating the issue.
07

07

07

07
24

24

24

24
"Error: Invalid meeting duration. Please enter a positive integer not exceeding
240 minutes (4 hours)."

Refer to the sample output for formatting specifications.


Sample Test Case
Input: 120
06

6
00

00

00
0

Output: Meeting scheduled successfully!


01

01

01

01
07

07

07

Answer 07
24

24

24

24
// You are using Java
import [Link];
class InvalidDurationException extends Exception{
public InvalidDurationException(String message){
super(message);
}
}
public class Main{
public static void main(String args[]){
Scanner s=new Scanner([Link]);
6

6
00

00

00

00

int duration=[Link]();
01

01

01

01

try{
07

07

07

07
24

24

24

24
validateMeetingDuration(duration);
06

6
00

00

00
[Link]("Meeting scheduled successfully!");
0
01

01

01

01
}
07

07

07

07
catch(InvalidDurationException e){
24

24

24

24
[Link]("Error: "+[Link]());
}
}
static void validateMeetingDuration(int n) throws InvalidDurationException{
if(n<=0||n>240){
throw new InvalidDurationException("Invalid meeting [Link]
enter a positive integer not exceeding 240 minutes(4hours).");
}
}
}
6

6
00

00

00

00
01

01

01

01
Status : Correct Marks : 10/10
07

07

07

07
24

24

24

24
06

6
00

00

00
0
01

01

01

01
07

07

07

07
24

24

24

24
6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 8_Q3

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
06

6
00

00

00
0

In a user registration system, there is a requirement to implement a


01

01

01

01
07

07

07

username validation module. Users attempting to register must adhere to 07


24

24

24

24
specific criteria for their usernames to be considered valid.

Your task is to develop a program that takes user input for a desired
username and validates it according to the following rules:
The username must not contain any [Link] username must be at
least 5 characters long.
Implement a custom exception, InvalidUsernameException, to handle
cases where the entered username does not meet the specified criteria.
6

6
00

00

00

00

Input Format
01

01

01

01
07

07

07

07
24

24

24

24
The input consists of a string S, representing the desired username.
06

6
00

00

00
0
01

01

01

01
Output Format
07

07

07

07
24

24

24

24
If the username is valid, print "Username is valid: [S]".

If the username is invalid:

1. If the username is short, print "Invalid Username: Username must be at least 5


characters long"
2. If the username contains spaces, print "Invalid Username: Username cannot
contain spaces"
6

6
00

00

00

00
01

01

01

01
Refer to the sample output for formatting specifications.
07

07

07

07
24

24

24

24
Sample Test Case
Input: John
Output: Invalid Username: Username must be at least 5 characters long
Answer
// You are using Java
import [Link];
class InvalidUsernameException extends Exception{
public InvalidUsernameException(String message){
06

6
super(message);
00

00

00
0

}
01

01

01

01
07

07

07

07
}
24

24

24

24
public class Main{
public static void main(String args[]){
Scanner s=new Scanner([Link]);
String username=[Link]();
try{
validateUsername(username);
[Link]("Username is valid: "+username);
}
catch(InvalidUsernameException e){
[Link]([Link]());
6

}
00

00

00

00

}
01

01

01

01
07

07

07

07

static void validateUsername(String s) throws InvalidUsernameException{


24

24

24

24
if([Link](" ")){
06

6
00

00

00
throw new InvalidUsernameException("Invalid Username: Username
0
01

01

01

01
cannot contain spaces");
07

07

07

07
}
24

24

24

24
if([Link]()<5){
throw new InvalidUsernameException("Invalid Username: Username must
be at least 5 characters long");
}
}
}

Status : Correct Marks : 10/10


6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06

6
00

00

00
0
01

01

01

01
07

07

07

07
24

24

24

24
6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 8_Q4

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
06

6
00

00

00
0

A local municipality is implementing an online voting system for a


01

01

01

01
07

07

07

community event and wants to ensure that only eligible voters (those aged 07
24

24

24

24
18 or older) can participate.

Your task is to develop a program that validates the age of individuals


attempting to vote online. If the user's age is below 18, the program should
throw a custom exception, InvalidAgeException, preventing them from
casting their vote. If the input is invalid, catch the appropriate
InputMismatchException and print the in-built exception message.

Input Format
6

The input consists of an integer representing the age.


00

00

00

00
01

01

01

01
07

07

07

07

Output Format
24

24

24

24
If the age is 18 or older, print "Eligible to vote"
06

6
00

00

00
0
01

01

01

01
If the age is below 18, print "Exception occurred: InvalidAgeException: Age is not
07

07

07

07
valid to vote"
24

24

24

24
If there is any other type of exception, print "An error occurred: " followed by the
in-built exception message.

Refer to the sample output for formatting specifications.


Sample Test Case
6

6
00

00

00

00
Input: 20
01

01

01

01
07

07

07

07
Output: Eligible to vote
24

24

24

24
Answer
// You are using Java
import [Link];
import [Link];

class InvalidAgeException extends Exception{


public InvalidAgeException(String message){
super(message);
}
}
06

6
00

00

00
0

public class Main{


01

01

01

01
07

07

07

07
public static void main(String args[]){
24

24

24

24
Scanner s=new Scanner([Link]);
try{
int age=[Link]();
if(age<18){
throw new InvalidAgeException("Age is not valid to vote");
}
[Link]("Eligible to vote");
}
catch(InvalidAgeException e){
[Link]("Exception occurred: InvalidAgeException:
"+[Link]());
6

6
00

00

00

00

}
01

01

01

01
07

07

07

07

catch(Exception e){
24

24

24

24
24 24 24 24
07 07 07 07

}
01 01 01 01

}
00 0 00 0
6 06 6 } 06

Status : Correct

24 24 24 24
07 07 07 07
01 01 01 01
00 00 00 00
6 6 6 6
[Link]("An error occurred: "+e);

24 24 24 24
07 07 07 07
01 01 01 01
00 00 00 00
6 6 6 6

24 24 24 24
07 07 07 07
Marks : 10/10

01 01 01 01
00 00 00 00
6 6 6 6
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 8_Q5

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
06

6
00

00

00
0

In a file management system, users are required to provide a valid file


01

01

01

01
07

07

07

name when creating new files. The system enforces specific rules for file 07
24

24

24

24
names to maintain consistency and avoid potential issues. Your task is to
implement a Java program named FileNameValidator that takes user input
for a file name and validates it according to the specified rules.

Rules for Valid File Name:


The file name must consist of alphanumeric characters (letters and digits)
[Link] file name must have a minimum length of 3 characters.
Implement a custom exception, FileNameValidator, to handle cases where
the entered filename does not meet the specified criteria.
6

6
00

00

00

00
01

01

01

01
07

07

07

07

Input Format
24

24

24

24
The input consists of a string S, representing the desired filename.
06

6
00

00

00
0
01

01

01

01
Output Format
07

07

07

07
24

24

24

24
The output is displayed in the following format:

If the entered file name meets the specified criteria, the program outputs

"Valid file name"

If the entered file name does not meet the criteria and triggers the
InvalidFileNameException, the program outputs

"Error: Invalid file name. It must be alphanumeric and have a minimum length of
3 characters."
6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
Refer to the sample output for formatting specifications.
Sample Test Case
Input: myfile123
Output: Valid file name
Answer
// You are using Java
06

6
import [Link];
00

00

00
0
01

01

01

01
07

07

07

07
class InvalidFileNameException extends Exception {
24

24

24

24
public InvalidFileNameException(String message) {
super(message);
}
}

class FileNameValidator {
public static void validateFileName(String fileName) throws
InvalidFileNameException {
if ([Link]() < 3 || ![Link]("[A-Za-z0-9]+")) {
throw new InvalidFileNameException("Error: Invalid file name. It must be
6

alphanumeric and have a minimum length of 3 characters.");


00

00

00

00

}
01

01

01

01
07

07

07

07

}
24

24

24

24
06

6
00

00

00
public static void main(String[] args) {
0
01

01

01

01
Scanner sc = new Scanner([Link]);
07

07

07

07
String fileName = [Link]();
24

24

24

24
try {
validateFileName(fileName);
[Link]("Valid file name");
} catch (InvalidFileNameException e) {
[Link]([Link]());
}
}
}

Status : Correct Marks : 10/10


6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06

6
00

00

00
0
01

01

01

01
07

07

07

07
24

24

24

24
6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
REC_2028_OOPS using Java_Week 9_MCQ

Attempt : 1
Total Mark : 15
Marks Obtained : 15

Section 1 : MCQ

1. What does the addFirst() method of LinkedList do?


06

6
00

00

00
0

Answer
01

01

01

01
07

07

07

Adds an element to the beginning of the list 07


24

24

24

24

Status : Correct Marks : 1/1

2. What will be the output of the following code?

import [Link].*;
class Main {
public static void main(String[] args) {
ArrayList<Integer> list = new ArrayList<>();
6

6
00

00

00

00

[Link](10);
01

01

01

01

[Link](20);
07

07

07

07
24

24

24

24
[Link](30);
06

6
00

00

00
[Link](1);
0
01

01

01

01
[Link](list);
07

07

07

07
24

24

24

24
}
}
Answer
[10, 30]
Status : Correct Marks : 1/1

3. What is Collection in Java?


6

6
00

00

00

00
Answer
01

01

01

01
07

07

07

07
A group of objects
24

24

24

24
Status : Correct Marks : 1/1

4. Which of the following methods removes and returns the last element
from a LinkedList?

Answer
removeLast()
Status : Correct Marks : 1/1
06

6
00

00

00
0
01

01

01

01
07

07

07

07
24

24

24

24
5. What will be the output of the following code?

import [Link];

public class Main {


public static void main(String[] args) {
ArrayList<String> list = new ArrayList<>();
[Link]("Apple");
[Link]("Banana");
[Link]("Apple");
6

6
00

00

00

00

[Link](list);
01

01

01

01
07

07

07

07
24

24

24

24
}
06

6
00

00

00
}
0
01

01

01

01
07

07

07

07
Answer
24

24

24

24
[Banana]
Status : Correct Marks : 1/1

6. What will be the output of the following code?

import [Link].*;
class Main {
public static void main(String[] args) {
6

6
00

00

00

00
ArrayList<Integer> list = new ArrayList<>();
01

01

01

01
[Link](1);
07

07

07

07
24

24

24

24
[Link](2);
[Link](3);
[Link](4);
[Link](2, 10);
[Link](list);
}
}
Answer
[1, 2, 10, 4]
06

6
00

00

00
0

Status : Correct Marks : 1/1


01

01

01

01
07

07

07

07
24

24

24

24

7. What will be the output of the following code?

import [Link].*;
public class Main {
public static void main(String[] args) {
Stack<Integer> s = new Stack<>();
[Link](10);
[Link](20);
[Link](30);
6

6
00

00

00

00

[Link]([Link]());
01

01

01

01

}
07

07

07

07
24

24

24

24
}
06

6
00

00

00
0
01

01

01

01
Answer
07

07

07

07
24

24

24

24
30
Status : Correct Marks : 1/1

8. What will be the output of the following code?

import [Link].*;
class Main {
public static void main(String[] args) {
ArrayList<Integer> list = new ArrayList<>();
6

6
00

00

00

00
[Link](1);
01

01

01

01
[Link](2);
07

07

07

07
24

24

24

24
[Link](3);
[Link](4);
[Link](5);
[Link]([Link](3));
}
}
Answer
4
Status : Correct Marks : 1/1
06

6
00

00

00
0
01

01

01

01
07

07

07

07
24

24

24

24
9. What will be the output of the following code?

import [Link].*;
class Main {
public static void main(String[] args) {
ArrayList<String> list = new ArrayList<>();
[Link]("apple");
[Link]("banana");
[Link]("cherry");
[Link]("banana");
6

6
00

00

00

00

[Link]([Link]("banana"));
01

01

01

01

}
07

07

07

07
24

24

24

24
}
06

6
00

00

00
0
01

01

01

01
Answer
07

07

07

07
24

24

24

24
3
Status : Correct Marks : 1/1

10. What is the correct way to create an ArrayList in Java?

Answer
ArrayList&lt;String&gt; list = new ArrayList&lt;&gt;();
Status : Correct Marks : 1/1
6

6
00

00

00

00
01

01

01

01
07

07

07

07
11. What will be the output of the following code?
24

24

24

24
import [Link].*;
public class Main {
public static void main(String[] args) {
Stack<Integer> stack = new Stack<>();
for (int i = 1; i <= 3; i++)
[Link](i * 2);
[Link]();
[Link](10);
06

6
[Link]([Link]());
00

00

00
0
01

01

01

01
}
07

07

07

} 07
24

24

24

24

Answer
10
Status : Correct Marks : 1/1

12. How can you access the first element of an ArrayList named as list?

Answer
6

6
00

00

00

00

[Link](0);
01

01

01

01
07

07

07

07

Status : Correct Marks : 1/1


24

24

24

24
13. What will be the output of the following code?
06

6
00

00

00
0
01

01

01

01
import [Link].*;
07

07

07

07
24

24

24

24
class Main {
public static void main(String[] args) {
ArrayList<String> list = new ArrayList<>();
[Link]("Java");
[Link]("Python");
[Link]("Java");
[Link]("C++");
[Link]([Link]("Java"));
}
}
6

6
00

00

00

00
01

01

01

01
Answer
07

07

07

07
24

24

24

24
0
Status : Correct Marks : 1/1

14. Which method is used to add an element to the top of the stack?

Answer
push()
Status : Correct Marks : 1/1
06

6
00

00

00
0
01

01

01

01
07

07

07

15. What will be the output of the following code? 07


24

24

24

24

import [Link];

public class Main {


public static void main(String[] args) {
ArrayList<Integer> list = new ArrayList<>();
[Link](10);
[Link](20);
[Link](30);
6

[Link]("Size of the list: " + [Link]());


00

00

00

00
01

01

01

01

}
07

07

07

07
24

24

24

24
24 24 24 24
07 07 07 07
01
00
01
0
01
00
01
0 }
6 06 6 Answer
06

Status : Correct
Size of the list: 3

24 24 24 24
07 07 07 07
01 01 01 01
00 00 00 00
6 6 6 6

24 24 24 24
07 07 07 07
01 01 01 01
00 00 00 00
6 6 6 6

24 24 24 24
07 07 07 07
Marks : 1/1

01 01 01 01
00 00 00 00
6 6 6 6
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 9_Q1

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
06

6
00

00

00
0

Bobby is tasked with processing a sequence of numbers from a


01

01

01

01
07

07

07

monitoring system. He needs to extract a strictly increasing subsequence 07


24

24

24

24
using an ArrayList. The program should dynamically add numbers to the
ArrayList only if they are greater than the last number currently stored in
the list. Bobby aims to efficiently utilize the dynamic resizing and indexing
features of the ArrayList to solve this problem.

Help Bobby implement this solution.

Input Format
The first line of input consists of an integer N, representing the number of
6

elements.
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
The second line consists of N space-separated integers, representing the
06

6
00

00

00
elements.
0
01

01

01

01
07

07

07

07
Output Format
24

24

24

24
The output prints the list of integers in increasing sequence, ignoring out-of-
order elements.

Refer to the sample output for the formatting specifications.


Sample Test Case
Input: 7
6

6
00

00

00

00
3 5 9 1 11 7 13
01

01

01

01
07

07

07

07
Output: [3, 5, 9, 11, 13]
24

24

24

24
Answer
// You are using Java
import [Link].*;

class IncreasingSubsequence {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int n = [Link]();
ArrayList<Integer> result = new ArrayList<>();
06

6
for (int i = 0; i < n; i++) {
00

00

00
0

int num = [Link]();


01

01

01

01
07

07

07

07
if ([Link]() || num > [Link]([Link]() - 1)) {
24

24

24

24
[Link](num);
}
}
[Link](result);
}
}

Status : Correct Marks : 10/10


6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 9_Q2

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
06

6
00

00

00
0

Vikram loves listening to music and wants to create a simple playlist


01

01

01

01
07

07

07

manager using Java Collections. The playlist supports the following 07


24

24

24

24
operations:

"ADD <song>" Adds the song to the end of the playlist."REMOVE <song>"
Removes the first occurrence of the song from the playlist. If the song is
not found, do nothing."SHOW" Displays all songs in the playlist in order. If
the playlist is empty, print "EMPTY"."NEXT" Moves to the next song in the
playlist and prints its name. If the playlist is empty, print "EMPTY".
The playlist maintains a "current song" position that starts at the first song
when it's added. The NEXT command moves to the next song and prints it,
6

6
00

00

00

00

wrapping around to the first song after reaching the last song. When
01

01

01

01

removing songs, the current position adjusts accordingly to maintain


07

07

07

07
24

24

24

24
proper navigation.
06

6
00

00

00
0
01

01

01

01
Help Vikram implement this playlist manager.
07

07

07

07
24

24

24

24
Input Format
The first line of the input consists of an integer n, the number of operations.

The next n lines, each containing a command:

- "ADD <song>"
- "REMOVE <song>"
- "SHOW"
- "NEXT"
6

6
00

00

00

00
Output Format
01

01

01

01
07

07

07

07
For each "SHOW" command, print the songs in order, separated by spaces.
24

24

24

24
For each "NEXT" command, print the next song in the playlist.

If no song exists, print "EMPTY".

Refer to the sample output for formatting specifications.


06

6
Sample Test Case
00

00

00
0
01

01

01

01
Input: 7
07

07

07

ADD song1 07
24

24

24

24
ADD song2
SHOW
NEXT
REMOVE song2
SHOW
NEXT
Output: song1 song2
song2
song1
song1
6

6
00

00

00

00
01

01

01

01

Answer
07

07

07

07
24

24

24

24
import [Link];
06

6
00

00

00
import [Link];
0
01

01

01

01
07

07

07

07
class PlaylistManager {
24

24

24

24
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int n = [Link]([Link]());
LinkedList<String> playlist = new LinkedList<>();
int currentIndex = -1;

for (int i = 0; i < n; i++) {


String line = [Link]();
if ([Link]("ADD ")) {
String song = [Link](4);
6

6
00

00

00

00
[Link](song);
01

01

01

01
if (currentIndex == -1) {
07

07

07

07
currentIndex = 0;
24

24

24

24
}
} else if ([Link]("REMOVE ")) {
String song = [Link](7);
int index = [Link](song);
if (index != -1) {
[Link](index);
if ([Link]()) {
currentIndex = -1;
} else if (index < currentIndex) {
currentIndex--;
06

6
00

00

00
} else if (index == currentIndex) {
0
01

01

01

01
if (currentIndex >= [Link]()) {
07

07

07

currentIndex = 0; 07
24

24

24

24
}
}
}
} else if ([Link]("SHOW")) {
if ([Link]()) {
[Link]("EMPTY");
} else {
for (String s : playlist) {
[Link](s + " ");
}
6

6
00

00

00

00

[Link]();
01

01

01

01

}
07

07

07

07
24

24

24

24
} else if ([Link]("NEXT")) {
06

6
00

00

00
if ([Link]()) {
0
01

01

01

01
[Link]("EMPTY");
07

07

07

07
} else {
24

24

24

24
currentIndex = (currentIndex + 1) % [Link]();
[Link]([Link](currentIndex));
}
}
}
}
}

Status : Correct Marks : 10/10


6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06

6
00

00

00
0
01

01

01

01
07

07

07

07
24

24

24

24
6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 9_Q3

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
06

6
00

00

00
0

Assist Pranitha in developing a program that takes an integer N as input,


01

01

01

01
07

07

07

representing the number of names to be read. Then read N names and 07


24

24

24

24
store them in an ArrayList. Finally, input a search string and output the
frequency of that string in the list of names.

Note: Some parts of the code are provided as snippets, and you need to
complete the remaining sections by writing the necessary code.

Input Format
The first line of input consists of an integer N, representing the number of names
to be read.
6

6
00

00

00

00
01

01

01

01

The following N lines consist of N names, as a string.


07

07

07

07
24

24

24

24
The last line consists of a string, representing the name to be searched.
06

6
00

00

00
0
01

01

01

01
Output Format
07

07

07

07
24

24

24

24
The output prints a single integer, representing the frequency of the specified
name in the given list.

If the specified name is not found, print 0.

Refer to the sample output for formatting specifications.


Sample Test Case
6

6
00

00

00

00
Input: 5
01

01

01

01
Alice
07

07

07

07
24

24

24

24
Bob
Ankit
Alice
Pranitha
Alice
Output: 2
Answer
// You are using Java
import [Link];
06

6
import [Link];
00

00

00
0
01

01

01

01
07

07

07

07
class NameFrequency {
24

24

24

24
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int n = [Link]([Link]());
ArrayList<String> names = new ArrayList<>();

for (int i = 0; i < n; i++) {


[Link]([Link]());
}

String searchName = [Link]();


6

int count = 0;
00

00

00

00
01

01

01

01
07

07

07

07

for (String name : names) {


24

24

24

24
24 24 24 24
07 07 07 07

}
01 01 01 01

}
00 0 00 0

}
6 06 6 06
}

Status : Correct
count++;

24 24 24 24
07 07 07 07
01 01 01 01
[Link](count);

00 00 00 00
6 6 6 6
if ([Link](searchName)) {

24 24 24 24
07 07 07 07
01 01 01 01
00 00 00 00
6 6 6 6

24 24 24 24
07 07 07 07
Marks : 10/10

01 01 01 01
00 00 00 00
6 6 6 6
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
REC_2028_OOPS using Java_Week 10_MCQ

Attempt : 1
Total Mark : 15
Marks Obtained : 14

Section 1 : MCQ

1. Which method retrieves the lowest key in a TreeMap?


06

6
00

00

00
0

Answer
01

01

01

01
07

07

07

firstKey() 07
24

24

24

24

Status : Correct Marks : 1/1

2. Which of the following is true about HashMap?

Answer
It is not synchronized
Status : Correct Marks : 1/1
6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
3. Which of the following is true about TreeMap?
06

6
00

00

00
0
01

01

01

01
Answer
07

07

07

07
24

24

24

24
It is synchronized
Status : Wrong Marks : 0/1

4. Which of the following allows null keys in Java?

Answer
HashMap
Status : Correct Marks : 1/1
6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
5. How does HashSet check for duplicate elements?

Answer
Using equals() and hashCode()
Status : Correct Marks : 1/1

6. What is the time complexity of retrieving an element from a HashSet?


06

6
Answer
00

00

00
0
01

01

01

01
O(1)
07

07

07

07
24

24

24

24
Status : Correct Marks : 1/1

7. What happens when you add duplicate elements to a HashSet?

Answer
The duplicate is ignored
Status : Correct Marks : 1/1
6

6
00

00

00

00
01

01

01

01

8. What will be the output of the following code?


07

07

07

07
24

24

24

24
06

6
import [Link].*;

00

00

00
0
01

01

01

01
class Main {
07

07

07

07
public static void main(String[] args) {
24

24

24

24
HashMap<String, Integer> map = new HashMap<>();
[Link]("A", 1);
[Link]("B", 2);
[Link]("C", 3);
[Link]([Link]("B"));
}
}
Answer
6

6
true
00

00

00

00
01

01

01

01
Status : Correct Marks : 1/1
07

07

07

07
24

24

24

24
9. What happens if two keys have the same hash code in a HashMap?

Answer
A linked list is used to store values with the same hash
Status : Correct Marks : 1/1

10. What will happen if you add elements in descending order in a


06

6
00

00

00
TreeSet?
0
01

01

01

01
07

07

07

07
24

24

24

24
Answer
They are sorted in ascending order
Status : Correct Marks : 1/1

11. Which method removes all elements from a Set?

Answer
clear()
6

6
00

00

00

00

Status : Correct Marks : 1/1


01

01

01

01
07

07

07

07
24

24

24

24
12. What will be the output of the following code?
06

6
00

00

00
0
01

01

01

01
import [Link].*;
07

07

07

07
24

24

24

24
class Main {
public static void main(String[] args) {
HashMap<String, Integer> map = new HashMap<>();
[Link]("X", 10);
[Link]("Y", 20);
[Link]("Z", 30);
[Link]("Y");
[Link](map);
}
}
6

6
00

00

00

00
01

01

01

01
Answer
07

07

07

07
24

24

24

24
{X=10, Z=30}
Status : Correct Marks : 1/1

13. What will happen if you add a null element to a TreeSet?

Answer
An exception occurs
Status : Correct Marks : 1/1
06

6
00

00

00
0
01

01

01

01
07

07

07

14. What will be the output of the following code? 07


24

24

24

24

import [Link].*;
class Main {
public static void main(String[] args) {
HashMap<String, String> map = new HashMap<>();
[Link]("A", "Apple");
[Link]("B", "Banana");
[Link]("C", "Cherry");
[Link]("B", "Blueberry");
6

[Link](map);
00

00

00

00
01

01

01

01

}
07

07

07

07
24

24

24

24
}
06

6
00

00

00
0
01

01

01

01
Answer
07

07

07

07
24

24

24

24
{A=Apple, B=Blueberry, C=Cherry}
Status : Correct Marks : 1/1

15. Which statement is true about HashSet and TreeSet?

Answer
TreeSet provides sorted elements
Status : Correct Marks : 1/1
6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06

6
00

00

00
0
01

01

01

01
07

07

07

07
24

24

24

24
6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 10_Q1

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : COD

1. Problem Statement
06

6
00

00

00
0

A city traffic management system needs to track vehicles entering a toll


01

01

01

01
07

07

07

booth. Each vehicle is uniquely identified by its registration number. The 07


24

24

24

24
system should allow adding vehicles to a record, ensuring that no
duplicate registration numbers exist. The vehicles should be stored in a
HashSet, which does not guarantee any specific order.

Your task is to implement a program using a HashSet that allows adding


vehicle details and displaying the records.

Input Format
The first line of input contains an integer N - the number of vehicles.
6

6
00

00

00

00
01

01

01

01

The next N lines contain details of each vehicle in the format: "RegNumber
07

07

07

07
24

24

24

24
OwnerName VehicleType"
06

6
00

00

00
0
01

01

01

01
1. RegNumber (String) - A unique registration number (Alphanumeric).
07

07

07

07
2. OwnerName (String) - The name of the vehicle owner.
24

24

24

24
3. VehicleType (String, Car, Bike, or Truck) - The type of vehicle.

If a vehicle with the same registration number is already present, ignore the
duplicate entry.
Output Format
The output prints the unique vehicle records in any order (since HashSet does
not maintain order).

Output format: "RegNumber OwnerName VehicleType"


6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
Refer to the sample output for formatting specifications.
Sample Test Case
Input: 5
KA01AB1234 John Car
MH02CD5678 Alice Bike
DL03EF9012 Bob Truck
TN04GH3456 Mike Car
KA01AB1234 John Car
06

6
00

00

00
0

Output: TN04GH3456 Mike Car


01

01

01

01
07

07

07

07
KA01AB1234 John Car
24

24

24

24
MH02CD5678 Alice Bike
DL03EF9012 Bob Truck
Answer
// You are using Java
import [Link].*;

class Vehicle {
String regNumber;
String ownerName;
6

String vehicleType;
00

00

00

00
01

01

01

01
07

07

07

07

Vehicle(String regNumber, String ownerName, String vehicleType) {


24

24

24

24
[Link] = regNumber;
06

6
00

00

00
[Link] = ownerName;
0
01

01

01

01
[Link] = vehicleType;
07

07

07

07
}
24

24

24

24
public String toString() {
return regNumber + " " + ownerName + " " + vehicleType;
}

public boolean equals(Object o) {


if (this == o) return true;
if (!(o instanceof Vehicle)) return false;
Vehicle v = (Vehicle) o;
return [Link]([Link]);
6

6
00

00

00

00
}
01

01

01

01
07

07

07

07
public int hashCode() {
24

24

24

24
return [Link]();
}
}
class TollBoothTracker {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int n = [Link]([Link]());
Set<Vehicle> vehicles = new HashSet<>();
for (int i = 0; i < n; i++) {
String[] parts = [Link]().split(" ");
06

6
00

00

00
[Link](new Vehicle(parts[0], parts[1], parts[2]));
0
01

01

01

01
}
07

07

07

for (Vehicle v : vehicles) { 07


24

24

24

24
[Link](v);
}
}
}

Status : Correct Marks : 10/10


6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 10_Q2

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : COD

1. Problem Statement
06

6
00

00

00
0

John is organizing a fruit festival, and the quantities of various fruits are
01

01

01

01
07

07

07

stored in a HashMap where fruit names are keys and quantities are values. 07
24

24

24

24

Help him develop a program to find the total quantity of fruits for the
festival by summing up the values in the HashMap.

Input Format
The input consists of fruit quantities in the format 'fruitName:quantity', where
fruitName is the name of the fruit(a string), and quantity is a double value
representing the quantity.
6

The input is terminated by entering "done".


00

00

00

00
01

01

01

01

Output Format
07

07

07

07
24

24

24

24
The output prints a double value, representing the sum of values in the
06

6
00

00

00
HashMap, rounded off to two decimal places.
0
01

01

01

01
07

07

07

07
If the value is not numeric, print "Invalid input".
24

24

24

24
If any special characters other than ':' are entered, print "Invalid format".

Refer to the sample output for formatting specifications.


Sample Test Case
Input: Banana:15.2
6

6
00

00

00

00
Orange:56.3
01

01

01

01
Mango:47.3
07

07

07

07
24

24

24

24
done
Output: 118.80
Answer
// You are using Java
import [Link].*;
class FruitFestival {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
Map<String, Double> fruitMap = new HashMap<>();
while (true) {
06

6
00

00

00
0

String line = [Link]();


01

01

01

01
07

07

07

07
if ([Link]("done")) break;
24

24

24

24
if (![Link](":") || [Link](".*[^a-zA-Z0-9:. ].*")) {
[Link]("Invalid format");
return;
}
String[] parts = [Link](":");
if ([Link] != 2) {
[Link]("Invalid format");
return;
}
String fruit = parts[0];
String qtyStr = parts[1];
6

6
00

00

00

00

try {
01

01

01

01
07

07

07

07

double qty = [Link](qtyStr);


24

24

24

24
[Link](fruit, qty);
06

6
00

00

00
} catch (NumberFormatException e) {
0
01

01

01

01
[Link]("Invalid input");
07

07

07

07
return;
24

24

24

24
}
}
double total = 0;
for (double val : [Link]()) {
total += val;
}
[Link]("%.2f\n", total);
}
}
6

6
00

00

00

00
Status : Correct Marks : 10/10
01

01

01

01
07

07

07

07
24

24

24

24
06

6
00

00

00
0
01

01

01

01
07

07

07

07
24

24

24

24
6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 10_Q3

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : COD

1. Problem Statement
06

6
00

00

00
0

Priya is analyzing encrypted messages in a research project. She wants to


01

01

01

01
07

07

07

analyze the frequency of each character in a given paragraph. The 07


24

24

24

24
characters should be stored in a TreeMap so that the output is sorted in
ascending order of characters automatically.

You are required to build a Java program that:


Uses a TreeMap<Character, Integer> to count how many times each
character appears in the [Link] spaces and considers only
alphabets (case-sensitive).Outputs the frequencies of characters in sorted
order.
You must use a TreeMap in the class named MessageAnalyzer.
6

6
00

00

00

00
01

01

01

01
07

07

07

07

Input Format
24

24

24

24
The first line of input contains an integer n, the number of lines in the message.
06

6
00

00

00
0
01

01

01

01
The next n lines each contain a string (the encrypted message line).
07

07

07

07
24

24

24

24
Output Format
The first line of output prints: "Character Frequency:"

Then print each character and its frequency in the format: "<character>: <count>"

Refer to the sample output for formatting specifications.


6

6
Sample Test Case
00

00

00

00
01

01

01

01
Input: 2
07

07

07

07
24

24

24

24
Hello World
Java
Output: Character Frequency:
H: 1
J: 1
W: 1
a: 2
d: 1
e: 1
l: 3
06

6
o: 2
00

00

00
0

r: 1
01

01

01

01
07

07

07

07
v: 1
24

24

24

24
Answer
// You are using Java
import [Link].*;
class MessageAnalyzer {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int n = [Link]([Link]());
TreeMap<Character, Integer> freqMap = new TreeMap<>();
for (int i = 0; i < n; i++) {
6

String line = [Link]();


00

00

00

00

for (char ch : [Link]()) {


01

01

01

01
07

07

07

07

if ([Link](ch)) {
24

24

24

24
[Link](ch, [Link](ch, 0) + 1);
06

6
00

00

00
}
0
01

01

01

01
}
07

07

07

07
}
24

24

24

24
[Link]("Character Frequency:");
for ([Link]<Character, Integer> entry : [Link]()) {
[Link]([Link]() + ": " + [Link]());
}
}
}

Status : Correct Marks : 10/10


6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06

6
00

00

00
0
01

01

01

01
07

07

07

07
24

24

24

24
6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 10_Q4

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : COD

1. Problem Statement
06

6
00

00

00
0

In a ticket reservation system, you store the available seat numbers in a


01

01

01

01
07

07

07

TreeSet. Users input their desired seat number, and the program checks 07
24

24

24

24
whether the chosen seat is available.

Using a TreeSet ensures quick and efficient verification of seat availability,


ensuring a smooth and organized ticket booking process.

Input Format
The first line of input contains a single integer n, representing the number of
available seats.
6

The second line contains n space-separated integers, representing the available


00

00

00

00

seat numbers.
01

01

01

01
07

07

07

07
24

24

24

24
The third line contains an integer m, representing the seat number that needs to
06

6
00

00

00
be searched.
0
01

01

01

01
07

07

07

07
Output Format
24

24

24

24
The output displays "[m] is present!" if the given seat is available. Otherwise, it
displays "[m] is not present!"

Refer to the sample output for the formatting specifications.


Sample Test Case
Input: 4
6

6
00

00

00

00
2456
01

01

01

01
5
07

07

07

07
24

24

24

24
Output: 5 is present!
Answer
import [Link].*;
class TicketReservation {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int n = [Link]();
TreeSet<Integer> seats = new TreeSet<>();
for (int i = 0; i < n; i++) {
06

6
[Link]([Link]());
00

00

00
0

}
01

01

01

01
07

07

07

07
int m = [Link]();
24

24

24

24
if ([Link](m)) {
[Link](m + " is present!");
} else {
[Link](m + " is not present!");
}
}
}

Status : Correct Marks : 10/10


6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
REC_2028_OOPS using Java_Week 11

Attempt : 1
Total Mark : 20
Marks Obtained : 10

Section 1 : Project

1. Problem Statement
06

6
00

00

00
0

Create a JDBC-based Hospital Management System that handles runtime


01

01

01

01
07

07

07

input to manage patient records. The system should allow users to: 07
24

24

24

24

Add a new patient (patient ID, name, age, status).


Update a patient’s status.
View a specific patient’s record by patient ID.
Display all patient records in the database.
Exit the application.

The system should connect to a MySQL database using the following


6

6
00

00

00

00

default credentials:
01

01

01

01
07

07

07

07
24

24

24

24
06

6
DB URL: jdbc:mysql://localhost/ri_db

00

00

00
0
01

01

01

01
USER: test
07

07

07

07
24

24

24

24
PWD: test123
The patients table has already been created with the following structure:
Table Name: patients

Input Format
The first line of input consists of an integer choice, representing the operation to
be performed:
6

6
00

00

00

00
01

01

01

01
(1 for Add Patient, 2 for Update Patient Status, 3 for View Patient Record, 4 for
07

07

07

07
Display All Patients, 5 for Exit)
24

24

24

24
For choice 1 (Add Patient):

- The second line consists of an integer patient_id.


- The third line consists of a string name.
- The fourth line consists of an integer age.
- The fifth line consists of a string status.
06

6
00

00

00
0
01

01

01

01
For choice 2 (Update Patient Status):
07

07

07

07
24

24

24

24
- The second line consists of an integer patient_id.
- The third line consists of a string new_status.

For choice 3 (View Patient Record):

- The second line consists of an integer patient_id.

For choice 4 (Display All Patients):

- No additional inputs are required.


6

6
00

00

00

00
01

01

01

01

For choice 5 (Exit):


07

07

07

07
24

24

24

24
06

6
00

00

00
- No additional inputs are required.
0
01

01

01

01
07

07

07

07
Output Format
24

24

24

24
For choice 1 (Add Patient):

- Print "Patient added successfully" if the patient was added.


- Print "Failed to add patient." if the insertion failed.

For choice 2 (Update Patient Status):

- Print "Patient status updated successfully" if the update was successful.


- Print "Patient not found." if the specified patient ID does not exist.
6

6
00

00

00

00
For choice 3 (View Patient Record):
01

01

01

01
07

07

07

07
24

24

24

24
- Display the patient details in the format:
- ID: [patient_id] | Name: [name] | Age: [age] | Status: [status]
- Print "Patient not found." if the specified patient ID does not exist.

For choice 4 (Display All Patients):

- Display each patient on a new line in the format:


- ID | Name | Age | Status
- If no records are available, print nothing (or handle it with an appropriate
message if desired).
06

6
00

00

00
0

For choice 5 (Exit):


01

01

01

01
07

07

07

07
24

24

24

24
- Print "Exiting Hospital Management System."

For invalid input:

- Print "Invalid choice. Please try again."


Sample Test Case
Input: 1
101
John Doe
45
6

6
00

00

00

00

Admitted
01

01

01

01

4
07

07

07

07
24

24

24

24
5
06

6
00

00

00
0
Output: Patient added successfully
01

01

01

01
ID | Name | Age | Status
07

07

07

07
24

24

24

24
101 | John Doe | 45 | Admitted
Exiting Hospital Management System.
Answer
import [Link].*;
import [Link];

class HospitalManagementSystem {
public static void main(String[] args) {
try (Connection conn = [Link]("jdbc:mysql://
localhost/ri_db", "test", "test123");
6

6
00

00

00

00
Scanner scanner = new Scanner([Link])) {
01

01

01

01
07

07

07

07
24

24

24

24
boolean running = true;

while (running) {

int choice = [Link]();

switch (choice) {
case 1:
addPatient(conn, scanner);
break;
case 2:
06

6
00

00

00
0

updatePatientStatus(conn, scanner);
01

01

01

01
break;
07

07

07

07
24

24

24

24
case 3:
viewPatientRecord(conn, scanner);
break;
case 4:
displayAllPatients(conn);
break;
case 5:
[Link]("Exiting Hospital Management System.");
running = false;
break;
default:
6

6
00

00

00

00

[Link]("Invalid choice. Please try again.");


01

01

01

01

}
07

07

07

07
24

24

24

24
}
06

6
00

00

00
} catch (SQLException e) {
0
01

01

01

01
[Link]();
07

07

07

07
}
24

24

24

24
}
import [Link].*;
import [Link];

public class HospitalManagementSystem {


private static final String DB_URL = "jdbc:mysql://localhost/ri_db";
private static final String USER = "test";
private static final String PWD = "test123";
6

6
public static void main(String[] args) {
00

00

00

00
01

01

01

01
Scanner sc = new Scanner([Link]);
07

07

07

07
24

24

24

24
try (Connection conn = [Link](DB_URL, USER, PWD))
{
while (true) {
int choice = [Link]([Link]().trim());

switch (choice) {
case 1: // Add Patient
int id = [Link]([Link]().trim());
String name = [Link]().trim();
int age = [Link]([Link]().trim());
06

6
String status = [Link]().trim();
00

00

00
0
01

01

01

01
07

07

07

07
String insertSQL = "INSERT INTO patients (patient_id, name, age,
24

24

24

24
status) VALUES (?, ?, ?, ?)";
try (PreparedStatement ps = [Link](insertSQL)) {
[Link](1, id);
[Link](2, name);
[Link](3, age);
[Link](4, status);
int rows = [Link]();
[Link](rows > 0 ? "Patient added successfully" :
"Failed to add patient.");
}
6

break;
00

00

00

00
01

01

01

01
07

07

07

07

case 2: // Update Patient Status


24

24

24

24
int updateId = [Link]([Link]().trim());
06

6
00

00

00
String newStatus = [Link]().trim();
0
01

01

01

01
07

07

07

07
String updateSQL = "UPDATE patients SET status = ? WHERE
24

24

24

24
patient_id = ?";
try (PreparedStatement ps = [Link](updateSQL)) {
[Link](1, newStatus);
[Link](2, updateId);
int rows = [Link]();
[Link](rows > 0 ? "Patient status updated
successfully" : "Patient not found.");
}
break;
6

6
00

00

00

00
case 3: // View Patient Record
01

01

01

01
int viewId = [Link]([Link]().trim());
07

07

07

07
24

24

24

24
String selectSQL = "SELECT * FROM patients WHERE patient_id
= ?";
try (PreparedStatement ps = [Link](selectSQL)) {
[Link](1, viewId);
ResultSet rs = [Link]();
if ([Link]()) {
[Link]("ID: %d | Name: %s | Age: %d | Status: %s%n",
[Link]("patient_id"),
[Link]("name"),
[Link]("age"),
06

6
00

00

00
[Link]("status"));
0
01

01

01

01
} else {
07

07

07

[Link]("Patient not found."); 07


24

24

24

24
}
}
break;

case 4: // Display All Patients


String allSQL = "SELECT * FROM patients";
try (Statement stmt = [Link]()) {
ResultSet rs = [Link](allSQL);
boolean hasRecords = false;
while ([Link]()) {
6

6
00

00

00

00

hasRecords = true;
01

01

01

01

[Link]("%d | %s | %d | %s%n",
07

07

07

07
24

24

24

24
[Link]("patient_id"),
06

6
00

00

00
[Link]("name"),
0
01

01

01

01
[Link]("age"),
07

07

07

07
[Link]("status"));
24

24

24

24
}
if (!hasRecords) {
// Optional: [Link]("No patient records found.");
}
}
break;

case 5: // Exit
[Link]("Exiting Hospital Management System.");
return;
6

6
00

00

00

00
01

01

01

01
default:
07

07

07

07
[Link]("Invalid choice. Please try again.");
24

24

24

24
}
}
} catch (SQLException e) {
[Link]("Database error: " + [Link]());
} catch (Exception e) {
[Link]("Unexpected error: " + [Link]());
}
}
}
06

6
}
00

00

00
0
01

01

01

01
07

07

07

Status : Wrong
07
Marks : 0/10
24

24

24

24

2. Problem Statement

In Café Central, the menu is cataloged and stored in a database.

To efficiently manage the restaurant's menu using Java and JDBC, you
must build a Restaurant Management System that supports:
Adding new menu items
6

6
00

00

00

00

Updating menu item prices


01

01

01

01
07

07

07

07
24

24

24

24
Viewing details of a menu item
06

6
00

00

00
0
01

01

01

01
Displaying all menu items in sorted order
07

07

07

07
24

24

24

24
You are given two files:
File 1: [Link] (POJO Class)

This class represents the MenuItem entity.


A MenuItem contains the following details:

Field Description
itemId Unique Menu Item ID (Integer)
6

6
00

00

00

00
name Item Name (String)
01

01

01

01
07

07

07

07
category Item Category (String)
24

24

24

24
price Item Price (Double)

Students must write code in the marked area:


class MenuItem {
private int itemId;
private String name;
private String category;
06

6
00

00

00
0

private double price;


01

01

01

01
07

07

07

07
24

24

24

24
public MenuItem() {}

public MenuItem(int itemId, String name, String category, double price) {


// write your code here
}

// Include getters and setters


}
6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
Expected in this part:
06

6
00

00

00
0
01

01

01

01
Assign parameter values to instance variables inside the constructor.
07

07

07

07
24

24

24

24
Add getters and setters for all attributes.

File 2: [Link] (Data Access Layer)


This class handles all database operations using JDBC.
Students must complete the missing JDBC logic in the following methods:

class MenuItemDAO {

public void addMenuItem(Connection conn, MenuItem menuItem)


6

6
00

00

00

00
throws SQLException {
01

01

01

01
07

07

07

07
// write your code here
24

24

24

24
}

public void updateItemPrice(Connection conn, int itemId, double


newPrice) throws SQLException {
// write your code here
}

public void deleteMenuItem(Connection conn, int itemId) throws


06

6
00

00

00
SQLException {
0
01

01

01

01
07

07

07

// write your code here 07


24

24

24

24

public MenuItem viewItemDetails(Connection conn, int itemId) throws


SQLException {
// write your code here
}

public List<MenuItem> displayAllMenuItems(Connection conn) throws


6

6
00

00

00

00

SQLException {
01

01

01

01
07

07

07

07
24

24

24

24
// write your code here
06

6
00

00

00
0
01

01

01

01
}
07

07

07

07
24

24

24

24
private MenuItem mapToMenuItem(ResultSet rs) throws SQLException {
return new MenuItem(
// write your code here
);
}
}
6

6
00

00

00

00
01

01

01

01
Expected in this part:
07

07

07

07
24

24

24

24
Write SQL queries for INSERT, UPDATE, DELETE, SELECT.
Execute queries using PreparedStatement or Statement.
Map ResultSet rows to MenuItem objects using mapToMenuItem().
Return a List<MenuItem> where required.
The system should connect to a MySQL database using the following
default credentials:
06

6
DB URL: jdbc:mysql://localhost/ri_db
00

00

00
0
01

01

01

01
USER: test
07

07

07

07
24

24

24

24
PWD: test123

The menu table has already been created with the following structure:
Table Name: menu

Input Format
The first line of input consists of an integer choice, representing the operation to
be performed (1 for Add Item, 2 for Restock item, 3 for reduce item, 4 for Display,
6

6
00

00

00

00

5 for Exit).
01

01

01

01
07

07

07

07
24

24

24

24
For choice 1 (Add Menu Item):
06

6
00

00

00
0
01

01

01

01
- The second line consists of an integer item_id.
07

07

07

07
- The third line consists of a string name.
24

24

24

24
- The fourth line consists of a string category.
- The fifth line consists of a double price.

For choice 2 (Update Item Price):

- The second line consists of an integer item_id.


- The third line consists of a double new_price.

For choice 3 (View Item Details):


6

6
00

00

00

00
- The second line consists of an integer item_id.
01

01

01

01
07

07

07

07
For choice 4 (Display All Menu Items):
24

24

24

24
- No additional inputs are required.

For choice 5 (Exit):

- No additional inputs are required.


Output Format
For choice 1 (Add Menu Item):
06

6
00

00

00
0

- Print "Menu item added successfully" if the item was added.


01

01

01

01
- Print "Failed to add item." if the insertion failed.
07

07

07

07
24

24

24

24
For choice 2 (Update Item Price):

- Print "Item price updated successfully" if the price update was successful.
- Print "Item not found." if the specified item ID does not exist.

For choice 3 (View Item Details):

- Display the item details in the format:


- ID: [item_id] | Name: [name] | Category: [category] | Price: [price]
- Print "Item not found." if the specified item ID does not exist.
6

6
00

00

00

00
01

01

01

01

For choice 4 (Display All Menu Items):


07

07

07

07
24

24

24

24
06

6
00

00

00
- Display each item on a new line in the format:
0
01

01

01

01
- ID | Name | Category | Price
07

07

07

07
- If no items are available, print nothing (or handle with an appropriate message
24

24

24

24
if desired).

For choice 5 (Exit):

- Print "Exiting Restaurant Management System."

For invalid input:

- Print "Invalid choice. Please try again."


6

6
Sample Test Case
00

00

00

00
01

01

01

01
Input: 1
07

07

07

07
24

24

24

24
11
Margherita Pizza
Main Course
12.99
4
5
Output: Menu item added successfully
ID | Name | Category | Price
11 | Margherita Pizza | Main Course | 12.99
Exiting Restaurant Management System.
06

6
00

00

00
Answer
0
01

01

01

01
07

07

07

07
import [Link].*;
24

24

24

24
import [Link];

class RestaurantManagementSystem {
public static void main(String[] args) {
try (Connection conn = [Link]("jdbc:mysql://
localhost/ri_db", "test", "test123");
Scanner scanner = new Scanner([Link])) {

boolean running = true;

while (running) {
6

6
00

00

00

00

int choice = [Link]();


01

01

01

01
07

07

07

07
24

24

24

24
switch (choice) {
06

6
00

00

00
case 1:
0
01

01

01

01
addMenuItem(conn, scanner);
07

07

07

07
break;
24

24

24

24
case 2:
updateItemPrice(conn, scanner);
break;
case 3:
viewItemDetails(conn, scanner);
break;
case 4:
displayAllMenuItems(conn);
break;
case 5:
6

6
00

00

00

00
[Link]("Exiting Restaurant Management System.");
01

01

01

01
running = false;
07

07

07

07
break;
24

24

24

24
default:
[Link]("Invalid choice. Please try again.");
}
}
} catch (SQLException e) {
[Link]();
}
}
public static void addMenuItem(Connection conn, Scanner scanner) {
06

6
try {
00

00

00
0
01

01

01

01
int itemId = [Link]();
07

07

07

[Link](); // Consume newline


07
24

24

24

24
String name = [Link]();
String category = [Link]();
double price = [Link]();

String sql = "INSERT INTO menu (item_id, name, category, price) VALUES
(?, ?, ?, ?)";
PreparedStatement pstmt = [Link](sql);
[Link](1, itemId);
[Link](2, name);
[Link](3, category);
6

[Link](4, price);
00

00

00

00
01

01

01

01
07

07

07

07

int rowsAffected = [Link]();


24

24

24

24
if (rowsAffected > 0) {
06

6
00

00

00
[Link]("Menu item added successfully");
0
01

01

01

01
} else {
07

07

07

07
[Link]("Failed to add item.");
24

24

24

24
}
[Link]();
} catch (SQLException e) {
[Link]("Failed to add item.");
}
}

public static void updateItemPrice(Connection conn, Scanner scanner) {


try {
int itemId = [Link]();
6

6
00

00

00

00
double newPrice = [Link]();
01

01

01

01
07

07

07

07
String sql = "UPDATE menu SET price = ? WHERE item_id = ?";
24

24

24

24
PreparedStatement pstmt = [Link](sql);
[Link](1, newPrice);
[Link](2, itemId);

int rowsAffected = [Link]();


if (rowsAffected > 0) {
[Link]("Item price updated successfully");
} else {
[Link]("Item not found.");
}
06

6
00

00

00
[Link]();
0
01

01

01

01
} catch (SQLException e) {
07

07

07

[Link]("Item not found."); 07


24

24

24

24
}
}

public static void viewItemDetails(Connection conn, Scanner scanner) {


try {
int itemId = [Link]();

String sql = "SELECT * FROM menu WHERE item_id = ?";


PreparedStatement pstmt = [Link](sql);
[Link](1, itemId);
6

6
00

00

00

00
01

01

01

01

ResultSet rs = [Link]();
07

07

07

07
24

24

24

24
if ([Link]()) {
06

6
00

00

00
int id = [Link]("item_id");
0
01

01

01

01
String name = [Link]("name");
07

07

07

07
String category = [Link]("category");
24

24

24

24
double price = [Link]("price");

[Link]("ID: %d | Name: %s | Category: %s | Price: %.2f%n",


id, name, category, price);
} else {
[Link]("Item not found.");
}
[Link]();
[Link]();
} catch (SQLException e) {
6

6
00

00

00

00
[Link]("Item not found.");
01

01

01

01
}
07

07

07

07
}
24

24

24

24
public static void displayAllMenuItems(Connection conn) {
try {
String sql = "SELECT * FROM menu ORDER BY item_id";
Statement stmt = [Link]();
ResultSet rs = [Link](sql);

[Link]("ID | Name | Category | Price");


while ([Link]()) {
int id = [Link]("item_id");
06

6
00

00

00
String name = [Link]("name");
0
01

01

01

01
String category = [Link]("category");
07

07

07

double price = [Link]("price"); 07


24

24

24

24

[Link]("%d | %s | %s | %.2f%n",
id, name, category, price);
}
[Link]();
[Link]();
} catch (SQLException e) {
[Link]();
}
}
6

6
00

00

00

00

}
01

01

01

01
07

07

07

07

//
24

24

24

24
24 24 24 24
07 07 07 07
01 01 01 01
00 0 00 0
6 06 6 06
Status : Correct

24 24 24 24
07 07 07 07
01 01 01 01
00 00 00 00
6 6 6 6

24 24 24 24
07 07 07 07
01 01 01 01
00 00 00 00
6 6 6 6

24 24 24 24
07 07 07 07
Marks : 10/10

01 01 01 01
00 00 00 00
6 6 6 6
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
REC_Week 12_Java_Lamba Expressions_MCQ

Attempt : 1
Total Mark : 10
Marks Obtained : 9

Section 1 : MCQ

1. What is the return type of a lambda expression in Java?


06

6
00

00

00
0

Answer
01

01

01

01
07

07

07

The return type is inferred from the context 07


24

24

24

24

Status : Correct Marks : 1/1

2. Which of the following is a valid lambda expression in Java?

Answer
(x) -&gt; x * 2
Status : Wrong Marks : 0/1
6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
3. Can a lambda expression in Java have a body with multiple statements?
06

6
00

00

00
0
01

01

01

01
Answer
07

07

07

07
24

24

24

24
Yes, if the statements are enclosed in curly braces
Status : Correct Marks : 1/1

4. What is a lambda expression in Java?

Answer
A way to define anonymous methods
Status : Correct Marks : 1/1
6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
5. What is the syntax for a basic lambda expression in Java?

Answer
(parameters) -&gt; expression
Status : Correct Marks : 1/1

6. Can a lambda expression have more than one parameter?


06

6
Answer
00

00

00
0
01

01

01

01
Yes, it can have multiple parameters
07

07

07

07
24

24

24

24
Status : Correct Marks : 1/1

7. Which of the following interfaces is NOT a functional interface in Java?

Answer
Iterable
Status : Correct Marks : 1/1
6

6
00

00

00

00
01

01

01

01

8. Which functional interface in Java takes two arguments and returns a


07

07

07

07
24

24

24

24
result?
06

6
00

00

00
0
01

01

01

01
Answer
07

07

07

07
24

24

24

24
BiFunction
Status : Correct Marks : 1/1

9. Which functional interface is commonly used with lambda expressions


in Java?

Answer
Runnable
6

6
00

00

00

00
Status : Correct Marks : 1/1
01

01

01

01
07

07

07

07
24

24

24

24
10. Can a lambda expression in Java have a body with multiple
statements?

Answer
Yes, if the statements are enclosed in curly braces
Status : Correct Marks : 1/1
06

6
00

00

00
0
01

01

01

01
07

07

07

07
24

24

24

24
6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 12_Q1

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
06

6
00

00

00
0

Sabrina is working on a project that involves analyzing a set of numbers. In


01

01

01

01
07

07

07

her exploration, she encounters scenarios where extracting even numbers 07


24

24

24

24
and finding their sum is essential.

Create a program that calculates the sum of even numbers from a given
array of integers using a lambda expression.

Input Format
The first line of input consists of an integer N, representing the size of the array.

The second line consists of N space-separated integers, representing the


6

elements of the array.


00

00

00

00
01

01

01

01

Output Format
07

07

07

07
24

24

24

24
The output prints the sum of the even integers from the array.
06

6
00

00

00
0
01

01

01

01
07

07

07

07
24

24

24

24
Refer to the sample output for formatting specifications.
Sample Test Case
Input: 3
29 37 45
Output: 0
Answer
// You are using Java
6

6
00

00

00

00
import [Link].*;
01

01

01

01
07

07

07

07
import [Link].*;
24

24

24

24
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);

int N = [Link]();
int[] numbers = new int[N];

for (int i = 0; i < N; i++) {


numbers[i] = [Link]();
}
06

6
00

00

00
0
01

01

01

01
07

07

07

07
int sum = [Link](numbers)
24

24

24

24
.filter(n -> n % 2 == 0)
.sum();

[Link](sum);
[Link]();
}
}

Status : Correct Marks : 10/10


6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 12_Q2

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
06

6
00

00

00
0

Alex is learning about Java’s functional interfaces and lambda expressions.


01

01

01

01
07

07

07

07
24

24

24

24
He wants to write a simple program that prints the square of each number
in an array using a predefined functional interface.
Help Alex complete this task using the Consumer functional interface.

Input Format
- The first line contains an integer N, the number of elements in the array.
- The second line contains N space-separated integers.
Output Format
6

6
00

00

00

00

- Print the squares of all elements in the array, separated by a space.


01

01

01

01
07

07

07

07
24

24

24

24
06

6
00

00

00
0
01

01

01

01
07

07

07

07
Refer to the sample output for formatting specifications.
24

24

24

24
Sample Test Case
Input: 4
1234
Output: 1 4 9 16
Answer
// You are using Java
import [Link].*;
import [Link];
6

6
00

00

00

00
class SquarePrinter {
01

01

01

01
07

07

07

07
public static void main(String[] args) {
24

24

24

24
Scanner scanner = new Scanner([Link]);

int n = [Link]();
int[] arr = new int[n];

for (int i = 0; i < n; i++) {


arr[i] = [Link]();
}

Consumer<Integer> squareConsumer = x -> [Link]((x * x) + " ");


06

6
00

00

00
0

for (int num : arr) {


01

01

01

01
07

07

07

07
[Link](num);
24

24

24

24
}
}
}

Status : Correct Marks : 10/10


6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 12_Q3

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
06

6
00

00

00
0

In the mystical realm of programming, there exists a magical incantation to


01

01

01

01
07

07

07

reveal hidden words. 07


24

24

24

24

Elara, the skilled enchantress, wishes to summon a word using her spell
and then reverse its characters to uncover its enchanted reflection.
Write a program that uses the predefined functional interface
Supplier<String> and a lambda expression to:

Supply (generate) a string, and


Display its reversed form.
6

6
00

00

00

00
01

01

01

01

Input Format
07

07

07

07
24

24

24

24
No input is required from the user.
06

6
00

00

00
0
01

01

01

01
The string must be supplied internally using a Supplier<String>.
07

07

07

07
24

24

24

24
Output Format
Print the reversed version of the supplied string.

Refer to the sample output for formatting specifications.


Sample Test Case
Input: Wizard!!
6

6
00

00

00

00
Output: !!draziW
01

01

01

01
07

07

07

07
Answer
24

24

24

24
import [Link];
import [Link];

class EnchantedReflection {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
String input = [Link]();

Supplier<String> spellSupplier = () -> input;


06

6
00

00

00
0

String spell = [Link]();


01

01

01

01
07

07

07

07
String reversed = new StringBuilder(spell).reverse().toString();
24

24

24

24

[Link](reversed);
}
}

Status : Correct Marks : 10/10


6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24
06 Rajalakshmi Engineering College

6
00

00

00
0
01

01

01

01
07

07

07

07
Name: Abhinandan ER Scan to verify results
24

24

24

24
Email: 240701006@[Link]
Roll no: 240701006
Phone: 9488757514
Branch: REC
Department: CSE - Section 8
Batch: 2028
Degree: B.E - CSE
6

6
00

00

00

00
2024_28_III_OOPS Using Java Lab
01

01

01

01
07

07

07

07
24

24

24

24
2028_REC_OOPS using Java_Week 12_Q4

Attempt : 1
Total Mark : 10
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
06

6
00

00

00
0

Abi is working on a text analysis project where she needs to categorize


01

01

01

01
07

07

07

words based on their length. 07


24

24

24

24

Words that have three or fewer characters are considered “Short”, while

words with more than three characters are classified as “Long.”


Write a Java program that takes a sentence as input, analyzes each word,
and prints a list showing whether each word is “Short” or “Long.”

Use the predefined functional interface Function<String, String> along with


a lambda expression for categorization.
6

6
00

00

00

00
01

01

01

01

Input Format
07

07

07

07
24

24

24

24
A single line containing a sentence (words separated by spaces).
06

6
00

00

00
0
01

01

01

01
Output Format
07

07

07

07
24

24

24

24
- A single line with each word categorized as "Short" or "Long", separated by
spaces.

Refer to the sample output for formatting specifications.


Sample Test Case
Input: I love my cat
6

6
Output: Short Long Short Short
00

00

00

00
01

01

01

01
Answer
07

07

07

07
24

24

24

24
// You are using Java
import [Link].*;
import [Link];
class WordLengthCategorizer {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
String sentence = [Link]();

String[] words = [Link](" ");


06

6
Function<String, String> categorize = word -> [Link]() <= 3 ? "Short" :
00

00

00
0

"Long";
01

01

01

01
07

07

07

07
24

24

24

24
for (String word : words) {
[Link]([Link](word) + " ");
}
}
}

Status : Correct Marks : 10/10


6

6
00

00

00

00
01

01

01

01
07

07

07

07
24

24

24

24

Common questions

Powered by AI

The logic involves iterating through the array elements and using the modulus operator to check for even numbers. The \(% 2 == 0\) condition filters out the even numbers, and their sum is calculated by accumulating these values during the loop iteration .

The pyramid pattern program structures its output by using nested loops to print an increasing sequence of numbers for each row. The inner loops manage spaces for alignment and increasing numbers 1 through \(2*i-1\), where \(i\) is the current row number, generating a pyramid form .

The taxi fare management system calculates the total fare using a base fare of 50 units and 10 units per km. If the distance exceeds 20 km, a 10% discount is applied to the total fare. This calculation ensures cost-effectiveness for longer distances, as implemented in the Java class method managing customer rides .

The restaurant management system uses SQL connections to handle menu items. The system processes various choices, such as adding an item via insertion into a menu database with prepared statements, updating, and displaying items. Successful operations or errors are managed by conditional outputs .

Lambda expressions are utilized by defining a \(Consumer<Integer>\) to perform the action of squaring each element and printing it. The \(for\) loop then iterates through the array, applying the \(accept()\) method of the consumer to produce and print the squares of the elements .

The program uses the \(Supplier<String>\) functional interface combined with a lambda expression to generate and then reverse a string. The reverse is likely achieved via methods such as StringBuilder's reverse function. No user input is required as the string is internally supplied .

The electricity billing system calculates the final bill by applying different rates to the units consumed. The first 100 units cost 5 units per unit, the next 100 units cost 7, and units above 200 cost 10. A 5% discount is applied if the total charge exceeds 2000 units after these calculations. This logic is implemented in the method \(calculateBill()\) in the \(Customer\) class .

Miles' program checks if either of two integers is both less than or equal to zero and odd. This is done by using two boolean conditions: \(condition1 = (input1 \leq 0 \&\& input1 \% 2 \neq 0)\) and \(condition2 = (input2 \leq 0 \&\& input2 \% 2 \neq 0)\). The program prints 'true' if either condition1 or condition2 is true .

Joey uses the technique of creating a mask with bitwise left shift and subtraction to extract the lowest N bits from an integer. The mask is generated using the expression \((1 << N) - 1\), and the operation is performed with bitwise AND, \(x \& mask\).

The strategy uses nested for loops to generate a number with unique digits. The outer loops iterate over possible hundreds, tens, and units places, respectively, ensuring each digit is unique. A check for divisibility by 3 is performed using \((i * 100 + j * 10 + k) \% 3 == 0\). Once a valid number is found, it is printed, and the process continues until N valid codes are generated .

You might also like