OOP Java Lab MCQs and Coding Tasks
OOP Java Lab MCQs and Coding Tasks
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
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
import [Link].*;
class OperatorPrecedenceExample {
6
6
00
00
00
00
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
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
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
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
6
00
00
00
0
01
01
01
01
class TestClass {
07
07
07
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
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
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
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
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
01
01
01
07
07
07
24
24
24
closest to the optimal temperature of 100 degrees Celsius using the
relational operator.
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
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.
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
01
01
01
07
07
07
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
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);
}
}
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
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
}
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
01
01
01
07
07
07
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
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
}
}
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
01
01
01
07
07
07
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.
Input Format
The first line of input consists of an integer X, representing the given integer.
6
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
01
01
01
07
07
07
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
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];
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]());
[Link](condition1 || condition2);
}
}
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
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
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
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
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");
}
}
}
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
01
01
01
07
07
07
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.
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.
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
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.");
}
}
}
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
01
01
01
07
07
07
24
24
24
She knows how many days each of them would take to complete the entire
project individually:
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:
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
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);
}
}
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
6
00
00
00
0
class Test {
01
01
01
01
07
07
07
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
6
00
00
00
if(score >= 90) {
0
01
01
01
01
[Link]("Grade: A");
07
07
07
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
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
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
01
01
01
07
07
07
07
24
24
24
24
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
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
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
6
00
00
00
00
01
01
01
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
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
01
01
01
07
07
07
24
24
24
Input Format
6
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:
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
01
01
01
07
07
07
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.
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.
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 ");
}
}
}
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
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;
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
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>".
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);
}
}
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
01
01
01
07
07
07
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
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.");
}
}
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.
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
01
01
01
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
24
24
24
enchanting pattern is fashioned using a for loop and is customized based
on user input.
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.
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
01
01
01
07
07
07
07
if (num % 3 == 0) {
24
24
24
24
[Link](num);
count++;
if (count == N) break;
}
}
}
}
}
}
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
6
00
00
00
0
class Sample {
01
01
01
01
07
07
07
24
24
24
int[][] data = {
{1, 2},
{3, 4}
};
int sum = 0;
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
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
01
01
01
07
07
07
07
24
24
24
24
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
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?
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
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
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
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
6
00
00
00
00
class Q {
01
01
01
01
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
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
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;
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
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.
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
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
}
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
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.
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
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
00
00
00
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
01
01
01
07
07
07
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:
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]);
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
01
01
01
07
07
07
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
00
00
00
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.
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
01
01
01
07
07
07
07
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
}
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
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.
Input Format
The first line of input consists of an integer n, representing the number of
elements in the array.
6
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".
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];
6
00
00
00
}
0
01
01
01
01
Set<Integer> seen = new HashSet<>();
07
07
07
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
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
6
00
00
00
0
class Main {
01
01
01
01
07
07
07
24
24
24
String languages[] = { "C", "C++", "Java", "Python", "Ruby"};
for (String sample: languages) {
[Link](sample);
}
}
}
Answer
C, C++, Java, Python, Ruby
6
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
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
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
01
01
01
07
07
07
07
24
24
24
24
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
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
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
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
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?
6
Answer
00
00
00
0
01
01
01
01
NumberFormatException
07
07
07
07
24
24
24
24
Status : Correct Marks : 1/1
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
6
class Main {
00
00
00
0
01
01
01
01
public static void main(String args[]) {
07
07
07
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
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.
6
00
00
00
00
01
01
01
01
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.
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);
}
}
}
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
01
01
01
07
07
07
24
24
24
sort these keywords alphabetically to generate tags for session grouping.
Input Format
The first line of input contains an integer n, representing the number of
keywords.
6
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.
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.
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");
}
}
}
}
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
01
01
01
07
07
07
24
24
24
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<>();
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));
}
}
}
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
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.
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.
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
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
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;
}
}
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
6
00
00
00
class A {
0
01
01
01
01
int x = 50;
07
07
07
} 07
24
24
24
24
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
01
01
01
07
07
07
07
24
24
24
24
class MathUtils {
int add(int x) {
return x + x;
}
}
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
class A {
int y = 30;
}
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
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
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);
}
}
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
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
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
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);
}
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
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");
}
}
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
24
24
24
6
00
00
00
00
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.
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:
6
00
00
00
0
01
01
01
01
07
07
07
07
24
24
24
24
6
00
00
00
00
01
01
01
01
07
07
07
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;
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;
}
6
00
00
00
}
0
01
01
01
01
07
07
07
24
24
24
return accountNumber;
}
6
00
00
00
00
01
01
01
01
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]());
6
00
00
00
}
0
01
01
01
01
07
07
07
24
24
24
[Link]("Account Number: " + [Link]());
[Link]("Customer Name: " + [Link]());
[Link]("Final Balance: %.1f\n", [Link]());
}
}
}
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
01
01
01
07
07
07
24
24
24
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
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.
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:
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;
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;
}
6
00
00
00
}
0
01
01
01
01
07
07
07
24
24
24
return customerName;
}
6
00
00
00
00
01
01
01
01
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;
}
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<>();
6
00
00
00
0
01
01
01
01
for (Customer c : customers) {
07
07
07
24
24
24
[Link]("Customer Name: " + [Link]());
[Link]("Final Bill: %.1f\n", [Link]());
}
}
}
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
24
24
24
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
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.
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:
6
00
00
00
Refer to the sample output for formatting specifications.
0
01
01
01
01
07
07
07
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;
}
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;
}
6
00
00
00
return customerName;
0
01
01
01
01
}
07
07
07
07
24
24
24
24
public double getDistance() {
return distance;
}
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<>();
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]());
}
}
}
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
01
01
01
07
07
07
24
24
24
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
01
01
01
07
07
07
07
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.
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:
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;
}
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;
}
6
00
00
00
return studentName;
0
01
01
01
01
}
07
07
07
07
24
24
24
24
public int getNumberOfSubjects() {
return numberOfSubjects;
}
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<>();
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]());
}
}
}
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
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
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
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
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
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
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
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
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
01
01
01
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
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";
}
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");
}
}
}
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
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
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
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.
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;
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;
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]);
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]();
}
}
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
01
01
01
07
07
07
24
24
24
discounts.
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.
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
}
6
00
00
00
00
01
01
01
01
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]);
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
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.
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.
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
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);
}
}
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
01
01
01
07
07
07
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
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
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
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]);
6
[Link]("Volume of Cuboid: %.2f\n", [Link]());
00
00
00
0
01
01
01
01
07
07
07
24
24
24
[Link]();
}
}
6
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
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:
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
24
24
24
6
00
00
00
00
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 {
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
24
24
24
if ([Link]("Regular")) {
Item item = new Produce(name, price);
totalCost += [Link]();
} else if ([Link]("Organic")) {
6
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
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
Answer
The method from the superclass
6
6
00
00
00
00
01
01
01
01
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
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
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
}
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
Answer
A class can implement multiple interfaces.
Status : Correct Marks : 1/1
6
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
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");
}
}
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
Answer
interface Vehicle { void start();}
6
6
00
00
00
00
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
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
}
}
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
24
24
24
interface MathOperations {
static int square(int x) {
return x * x;
}
}
[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
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.
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
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
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;
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]);
6
00
00
00
00
01
01
01
01
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
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.
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.
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
24
24
24
}
}
class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
6
00
00
00
00
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
01
01
01
07
07
07
24
24
24
in the principal amount, interest rate, and time in years and computes the
interest.
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.
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]);
6
00
00
00
00
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);
}
}
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
01
01
01
07
07
07
24
24
24
store's products.
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
01
01
01
07
07
07
07
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:
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
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
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
01
01
01
}
07
07
07
07
24
24
24
24
public double getValue() {
return price * quantity;
}
} @Override
public void addProduct(String name, double price, int quantity) {
6
6
00
00
00
00
01
01
01
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
24
24
24
(1/2/3).");
}
}
[Link]();
}
}
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
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
01
01
01
07
07
07
07
Scanner scanner = new Scanner([Link]);
24
24
24
24
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
6
00
00
00
0
Answer
01
01
01
01
07
07
07
24
24
24
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 Test {
public static void main(String[] args) {
6
6
00
00
00
00
try {
01
01
01
01
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
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
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 Test {
public static void main(String[] args) {
6
6
00
00
00
00
try {
01
01
01
01
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
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
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
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
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
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 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
01
01
01
07
07
07
07
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].*;
6
00
00
00
00
class Test {
01
01
01
01
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
01
01
01
07
07
07
24
24
24
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
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:
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
6
00
00
00
00
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
}
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");
}
6
00
00
00
if (!([Link]("in") || [Link]("com") || [Link]("net") ||
0
01
01
01
01
[Link]("biz"))) {
07
07
07
24
24
24
}
}
}
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
01
01
01
07
07
07
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.
6
00
00
00
00
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
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)."
6
00
00
00
0
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
01
01
01
07
07
07
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]".
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
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");
}
}
}
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
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.
Input Format
6
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.
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];
6
00
00
00
0
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
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.
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
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 || ) {
throw new InvalidFileNameException("Error: Invalid file name. It must be
6
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]());
}
}
}
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
6
00
00
00
0
Answer
01
01
01
01
07
07
07
24
24
24
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
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];
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
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
01
01
01
07
07
07
07
24
24
24
24
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
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
Answer
ArrayList<String> list = new ArrayList<>();
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
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
24
24
24
import [Link];
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
01
01
01
07
07
07
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.
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.
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
01
01
01
07
07
07
07
if ([Link]() || num > [Link]([Link]() - 1)) {
24
24
24
24
[Link](num);
}
}
[Link](result);
}
}
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
01
01
01
07
07
07
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
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.
- "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.
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;
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));
}
}
}
}
}
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
01
01
01
07
07
07
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
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.
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<>();
int count = 0;
00
00
00
00
01
01
01
01
07
07
07
07
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
6
00
00
00
0
Answer
01
01
01
01
07
07
07
firstKey() 07
24
24
24
24
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
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
Answer
00
00
00
0
01
01
01
01
O(1)
07
07
07
07
24
24
24
24
Status : Correct Marks : 1/1
Answer
The duplicate is ignored
Status : Correct Marks : 1/1
6
6
00
00
00
00
01
01
01
01
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
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
Answer
clear()
6
6
00
00
00
00
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
Answer
An exception occurs
Status : Correct Marks : 1/1
06
6
00
00
00
0
01
01
01
01
07
07
07
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
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
01
01
01
07
07
07
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.
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).
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
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
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;
}
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
24
24
24
[Link](v);
}
}
}
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
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".
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
01
01
01
07
07
07
07
if ([Link]("done")) break;
24
24
24
24
if ( || [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
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
01
01
01
07
07
07
24
24
24
characters should be stored in a TreeMap so that the output is sorted in
ascending order of characters automatically.
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>"
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
00
00
00
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]());
}
}
}
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
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.
Input Format
The first line of input contains a single integer n, representing the number of
available seats.
6
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!"
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!");
}
}
}
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
01
01
01
07
07
07
input to manage patient records. The system should allow users to: 07
24
24
24
24
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):
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.
6
00
00
00
00
01
01
01
01
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):
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.
6
00
00
00
0
01
01
01
07
07
07
07
24
24
24
24
- Print "Exiting Hospital Management System."
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) {
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
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];
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
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
24
24
24
}
}
break;
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
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
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)
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)
6
00
00
00
0
01
01
01
07
07
07
07
24
24
24
24
public MenuItem() {}
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.
class MenuItemDAO {
6
00
00
00
00
throws SQLException {
01
01
01
01
07
07
07
07
// write your code here
24
24
24
24
}
6
00
00
00
SQLException {
0
01
01
01
01
07
07
07
24
24
24
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.
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.
6
00
00
00
0
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.
6
00
00
00
00
01
01
01
01
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).
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])) {
while (running) {
6
6
00
00
00
00
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
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
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.");
}
}
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);
6
00
00
00
[Link]();
0
01
01
01
01
} catch (SQLException e) {
07
07
07
24
24
24
}
}
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");
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);
6
00
00
00
String name = [Link]("name");
0
01
01
01
01
String category = [Link]("category");
07
07
07
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
6
00
00
00
0
Answer
01
01
01
01
07
07
07
24
24
24
Answer
(x) -> 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
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) -> expression
Status : Correct Marks : 1/1
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
Answer
Iterable
Status : Correct Marks : 1/1
6
6
00
00
00
00
01
01
01
01
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
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
01
01
01
07
07
07
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.
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];
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]();
}
}
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
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
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];
6
00
00
00
0
01
01
01
07
07
07
07
[Link](num);
24
24
24
24
}
}
}
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
01
01
01
07
07
07
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:
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.
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]();
6
00
00
00
0
01
01
01
07
07
07
07
String reversed = new StringBuilder(spell).reverse().toString();
24
24
24
24
[Link](reversed);
}
}
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
01
01
01
07
07
07
24
24
24
Words that have three or fewer characters are considered “Short”, while
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.
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]();
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) + " ");
}
}
}
6
00
00
00
00
01
01
01
01
07
07
07
07
24
24
24
24
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 .