Java Week6
Java Week6
7
01
01
01
10
01
01
01
0
10
10
10
10
Name: Arul Amudhan G Scan to verify results
24
24
24
24
Email: 241001017@[Link]
Roll no: 241001017
Phone: 7397782797
Branch: REC
Department: IT - Section 4
Batch: 2028
Degree: B.E - IT
7
17
17
01
01
10
0
2024_28_III_OOPS Using Java Lab
01
01
01
00
10
10
10
1
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
7
7
01
01
01
01
Elsa subscribes to a premium service with a base monthly cost, a service
01
01
01
01
10
10
10
tax and an extra feature cost. Assist her in writing an inheritance program 10
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.
7
The second line consists of a double value, representing the service tax.
01
01
01
1
10
01
01
01
0
10
10
10
10
The third line consists of a double value, representing the extra feature cost.
24
24
24
24
Output Format
17
7
01
01
01
10
01
01
01
The output prints "Rs. X" where X is a double value, rounded off to two decimal
0
10
10
10
10
places.
24
24
24
24
Refer to the sample output for formatting specifications.
Sample Test Case
Input: 10.0
2.5
5.0
7
17
17
01
01
Output: Rs. 17.50
10
0
01
01
01
00
10
10
10
Answer
1
24
24
24
24
import [Link];
class Subscription{
double monthlyCost;
double serviceTax;
double extraFeatureCost;
7
01
01
01
01
[Link] = xCost;
01
01
01
01
10
10
10
10
}
24
24
24
24
}
7
01
01
01
1
10
}
01
01
01
0
10
10
10
10
}
24
24
24
24
public class Main {
17
7
01
01
01
public static void main(String[] args) {
10
01
01
01
0
10
10
10
24
24
24
24
double baseMonthlyCost = [Link]();
double serviceTax = [Link]();
double extraFeatureCost = [Link]();
17
17
01
01
10
0
01
01
01
00
[Link]();
10
10
10
1
}
24
24
24
24
}
7
01
01
01
01
01
01
01
01
10
10
10
10
24
24
24
24
7
7
01
01
01
1
10
01
01
01
0
10
10
10
10
24
24
24
24
17 Rajalakshmi Engineering College
7
01
01
01
10
01
01
01
0
10
10
10
10
Name: Arul Amudhan G Scan to verify results
24
24
24
24
Email: 241001017@[Link]
Roll no: 241001017
Phone: 7397782797
Branch: REC
Department: IT - Section 4
Batch: 2028
Degree: B.E - IT
7
17
17
01
01
10
0
2024_28_III_OOPS Using Java Lab
01
01
01
00
10
10
10
1
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
7
7
01
01
01
01
Alice is managing an online store and wants to implement a program using
01
01
01
01
10
10
10
24
24
24
discounts.
7
01
01
01
1
10
01
01
01
0
10
10
10
10
Input Format
24
24
24
24
The first line of input consists of a double value p, the initial price of the product.
17
7
01
01
01
10
01
01
01
0
10
10
10
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.
17
17
01
01
10
0
01
01
01
Sample Test Case
00
10
10
10
1
24
24
24
24
Input: 50.00
0.20
Output: Rs. 40.00
Answer
import [Link];
class Product{
public double price;
}
7
7
01
01
01
01
class DiscountedProduct extends Product{
01
01
01
01
private double discRate;
10
10
10
10
24
24
24
24
7
01
01
01
1
10
class ProductPricing {
01
01
01
0
10
10
10
10
24
24
24
Scanner scanner = new Scanner([Link]);
17
7
01
01
01
10
01
01
01
0
10
10
10
double discountRate = [Link]();
24
24
24
24
DiscountedProduct discountedProduct = new
DiscountedProduct(initialPrice, discountRate);
double sellingPrice = [Link]();
if (sellingPrice >= 0) {
[Link]("Rs. %.2f%n", sellingPrice);
} else {
[Link]("Not applicable");
}
[Link]();
7
17
17
01
01
}
10
0
01
01
01
00
}
10
10
10
1
24
24
24
24
Status : Correct Marks : 10/10
7
7
01
01
01
01
01
01
01
01
10
10
10
10
24
24
24
24
7
7
01
01
01
1
10
01
01
01
0
10
10
10
10
24
24
24
24
17 Rajalakshmi Engineering College
7
01
01
01
10
01
01
01
0
10
10
10
10
Name: Arul Amudhan G Scan to verify results
24
24
24
24
Email: 241001017@[Link]
Roll no: 241001017
Phone: 7397782797
Branch: REC
Department: IT - Section 4
Batch: 2028
Degree: B.E - IT
7
17
17
01
01
10
0
2024_28_III_OOPS Using Java Lab
01
01
01
00
10
10
10
1
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
7
7
01
01
01
01
Preethi is working on a project to automate sales tax calculations for items
01
01
01
01
10
10
10
in a store. She wants to create a program that takes the price of an item 10
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)
7
7
01
01
01
1
10
01
01
01
0
10
10
10
10
Input Format
24
24
24
24
The first line of input consists of an integer price (the price of the item for integer
17
7
01
01
01
inputs).
10
01
01
01
0
10
10
10
10
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
7
17
17
01
01
10
0
after applying the sales tax for integer inputs (a and b).
01
01
01
00
10
10
10
1
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.
7
01
01
01
01
10
01
01
01
01
100.0
10
10
10
10
24
24
24
24
5.0
Output: 110
105.00
Answer
import [Link];
class SalesTaxCalculator{
public static int calculateFinalPrice(int price, int taxRate){
return price + ((price*taxRate)/100);
}
7
7
01
01
01
1
10
01
01
01
10
10
10
24
24
24
24
return price + ((price*taxRate)/100);
17
7
01
01
01
}
10
01
01
01
0
}
10
10
10
10
24
24
24
24
class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
int intPrice = [Link]();
int intTaxRate = [Link]();
double doublePrice = [Link]();
double doubleTaxRate = [Link]();
17
17
double finalPriceDouble =
01
01
10
0
01
01
01
[Link](doublePrice, doubleTaxRate);
00
10
10
10
1
24
24
24
24
[Link](finalPriceInt);
[Link]("%.2f", finalPriceDouble);
}
}
7
01
01
01
01
01
01
01
01
10
10
10
10
24
24
24
24
7
7
01
01
01
1
10
01
01
01
0
10
10
10
10
24
24
24
24
17 Rajalakshmi Engineering College
7
01
01
01
10
01
01
01
0
10
10
10
10
Name: Arul Amudhan G Scan to verify results
24
24
24
24
Email: 241001017@[Link]
Roll no: 241001017
Phone: 7397782797
Branch: REC
Department: IT - Section 4
Batch: 2028
Degree: B.E - IT
7
17
17
01
01
10
0
2024_28_III_OOPS Using Java Lab
01
01
01
00
10
10
10
1
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
7
7
01
01
01
01
[Link] wants to create a program to calculate the volume of a Cuboid
01
01
01
01
10
10
10
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
7
7
01
01
01
1
10
the side length of the cube and display the calculated volumes with two
01
01
01
0
10
10
10
10
decimal places.
24
24
24
24
17
7
Input Format
01
01
01
10
01
01
01
0
10
10
10
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.
7
17
17
01
01
10
0
01
01
01
00
10
10
10
1
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
7
7
01
01
01
01
import [Link];
01
01
01
01
10
10
10
class Cuboid{ 10
24
24
24
24
double length;
double breadth;
double height;
7
01
01
01
1
10
01
01
01
10
10
10
24
24
24
24
return length * breadth * height;
17
7
01
01
01
}
10
01
01
01
0
}
10
10
10
10
24
24
24
24
class Cube extends Cuboid{
@Override
public double calculateVolume() {
return length * length * length;
7
17
17
01
01
}
10
0
01
01
01
00
}
10
10
10
1
24
24
24
24
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
7
[Link]("Volume of Cuboid: %.2f\n", [Link]());
01
01
01
01
01
01
01
01
10
10
10
24
24
24
[Link]();
}
}
7
01
01
1
10
01
01
01
0
10
10
10
10
24
24
24
24
17 Rajalakshmi Engineering College
7
01
01
01
10
01
01
01
0
10
10
10
10
Name: Arul Amudhan G Scan to verify results
24
24
24
24
Email: 241001017@[Link]
Roll no: 241001017
Phone: 7397782797
Branch: REC
Department: IT - Section 4
Batch: 2028
Degree: B.E - IT
7
17
17
01
01
10
0
2024_28_III_OOPS Using Java Lab
01
01
01
00
10
10
10
1
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:
7
7
01
01
01
01
Tim was tasked with developing a grocery shopping app. You have a class
01
01
01
01
10
10
10
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.
7
7
01
01
01
1
10
01
01
01
0
10
10
10
10
24
24
24
24
17
7
Input Format
01
01
01
10
01
01
01
0
10
10
10
24
24
24
24
For each 'n' item, the user will provide:
17
17
01
01
10
0
01
01
01
00
10
10
10
1
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];
7
7
01
01
01
01
class Item{
01
01
01
01
protected String name;
10
10
10
24
24
24
7
01
01
01
1
10
01
01
01
10
10
10
24
24
24
24
public Produce(String name, double price){
17
7
01
01
01
super(name, price);
10
01
01
01
0
}
10
10
10
10
24
24
24
24
@Override
public double calculateCost(){
return [Link];
}
}
17
17
01
01
public OrganicProduce(String name, double price){
10
0
01
01
01
00
super(name, price);
10
10
10
1
}
24
24
24
24
@Override
public double calculateCost(){
double finalPrice = [Link] * (1 - DISCOUNT_RATE);
return finalPrice;
}
}
public class Main {
public static void main(String[] args) {
7
7
Scanner sc = new Scanner([Link]);
01
01
01
01
01
01
01
01
10
10
10
int n = [Link]();
10
24
24
24
24
[Link](); // Consume newline
if ([Link]("Regular")) {
7
01
01
1
10
01
01
01
totalCost += [Link]();
0
10
10
10
10
} else if ([Link]("Organic")) {
24
24
24
24
Item item = new OrganicProduce(name, price);
17
7
01
01
01
totalCost += [Link]();
10
01
01
01
0
}
10
10
10
10
}
24
24
24
24
[Link]("%.2f%n", totalCost);
}
}
17
17
01
01
10
0
01
01
01
00
10
10
10
1
24
24
24
24
7
7
01
01
01
01
01
01
01
01
10
10
10
10
24
24
24
24
7
7
01
01
01
1
10
01
01
01
0
10
10
10
10
24
24
24
24
17 Rajalakshmi Engineering College
7
01
01
01
10
01
01
01
0
10
10
10
10
Name: Arul Amudhan G Scan to verify results
24
24
24
24
Email: 241001017@[Link]
Roll no: 241001017
Phone: 7397782797
Branch: REC
Department: IT - Section 3
Batch: 2028
Degree: B.E - IT
7
17
17
01
01
10
0
2024_28_III_OOPS Using Java Lab
01
01
01
00
10
10
10
1
24
24
24
24
REC_2028_OOPS using Java_Week 6_MCQ
Attempt : 1
Total Mark : 15
Marks Obtained : 14
Section 1 : MCQ
7
01
01
01
01
class Test {
01
01
01
01
10
10
10
void show(int a) { 10
24
24
24
24
[Link]("Integer method");
}
void show(String s) {
[Link]("String method");
}
public static void main(String[] args) {
Test obj = new Test();
[Link](null);
}
}
7
7
01
01
01
1
10
01
01
01
Answer
10
10
10
10
24
24
24
24
Compilation error due to ambiguous method call
17
7
01
01
01
10
01
01
01
Status : Wrong Marks : 0/1
0
10
10
10
10
24
24
24
24
2. What will be the output of the following Java program?
class A {
int value = 10;
void display() {
[Link]("A's display: " + value);
}
}
class B extends A {
7
17
17
01
01
10
0
int value = 20;
01
01
01
00
10
10
10
void display() {
1
24
24
24
24
[Link]("B's display: " + value);
}
}
class Test {
public static void main(String[] args) {
A obj = new B();
[Link]();
[Link]("Value: " + [Link]);
}
}
7
7
01
01
01
01
01
01
01
01
Answer
10
10
10
10
24
24
24
24
B's display: 20 Value: 10
Status : Correct Marks : 1/1
class A {
int x = 10;
}
7
7
01
01
01
1
10
class B extends A {
01
01
01
int x = 20;
10
10
10
10
24
24
24
24
}
17
7
01
01
01
10
01
01
01
0
class C extends B {
10
10
10
10
24
24
24
24
int x = 30;
void display() {
[Link](x);
[Link](super.x);
}
}
class Test {
public static void main(String[] args) {
7
17
17
01
01
C obj = new C();
10
0
01
01
01
00
[Link]();
10
10
10
1
24
24
24
24
}
}
Answer
3020
Status : Correct Marks : 1/1
7
01
01
01
01
class Vehicle {
01
01
01
01
void startEngine() {
10
10
10
10
24
24
24
24
[Link]("Vehicle engine started");
}
}
7
01
01
01
class Main {
10
01
01
01
10
10
10
24
24
24
24
Vehicle myVehicle = new Car();
17
7
01
01
01
[Link]();
10
01
01
01
0
}
10
10
10
10
24
24
24
24
}
Answer
Car engine started
Status : Correct Marks : 1/1
Answer
7
17
17
01
01
10
0
01
01
01
The method must have the same name, same parameters, and must be in
00
10
10
10
different classes with an inheritance relationship
1
24
24
24
24
Status : Correct Marks : 1/1
class Vehicle {
void start() {
[Link]("Vehicle starts");
}
7
7
}
01
01
01
01
01
01
01
01
class Car extends Vehicle {
10
10
10
10
24
24
24
24
void start() {
[Link]("Car starts");
}
}
class ElectricCar extends Car {
void start() {
[Link]("Electric Car starts silently");
}
}
7
class Test {
01
01
01
1
10
01
01
0
10
10
10
10
24
24
24
24
Vehicle v = new ElectricCar();
17
7
01
01
01
[Link]();
10
01
01
01
0
}
10
10
10
10
24
24
24
24
}
Answer
Electric Car starts silently
Status : Correct Marks : 1/1
class Parent {
7
17
17
01
01
void show() {
10
0
01
01
01
00
[Link]("Parent class");
10
10
10
1
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();
7
7
01
01
01
01
[Link]();
01
01
01
01
}
10
10
10
10
24
24
24
24
}
Answer
Child class
Status : Correct Marks : 1/1
8. Which of the following is the correct way for class B to inherit from
class A?
7
7
01
01
01
Answer
10
01
01
01
0
10
10
10
10
class B extends A {}
24
24
24
24
Status : Correct Marks : 1/1
17
7
01
01
01
10
01
01
01
0
10
10
10
10
9. What will be the output of the following code?
24
24
24
24
class A {
int sum(int x) {
return x + 2;
}
}
class B extends A {
int sum(int x) {
7
17
17
01
01
return [Link](x) * 2;
10
0
01
01
01
}
00
10
10
10
1
}
24
24
24
24
class C extends B {
int sum(int x) {
return [Link](x) - 3;
}
}
class Test {
public static void main(String[] args) {
7
7
C obj = new C();
01
01
01
01
01
01
01
01
[Link]([Link](4));
10
10
10
} 10
24
24
24
24
}
Answer
9
Status : Correct Marks : 1/1
class Test {
01
01
01
1
10
01
01
01
10
10
10
24
24
24
24
[Link]("Method 1");
17
7
01
01
01
}
10
01
01
01
0
10
10
10
24
24
24
24
[Link]("Method 2");
}
public static void main(String[] args) {
Test obj = new Test();
[Link](10, 10.0);
}
}
Answer
Method 2
7
17
17
01
01
10
0
Status : Correct Marks : 1/1
01
01
01
00
10
10
10
1
24
24
24
24
11. What will be the output of the following code?
class A {
void display() {
[Link]("Display A");
}
}
class B extends A {
7
7
01
01
01
01
void display() {
01
01
01
01
[Link]("Display B");
10
10
10
10
24
24
24
24
}
}
class C extends B {
void display() {
[Link]();
}
}
class Test {
7
7
01
01
01
01
01
10
10
10
24
24
24
24
[Link]();
17
7
01
01
01
}
10
01
01
01
0
}
10
10
10
10
24
24
24
24
Answer
Display B
Status : Correct Marks : 1/1
12. Select the correct keyword for implementing inheritance through the
class.
Answer
7
17
17
01
01
10
0
01
01
01
extends
00
10
10
10
1
24
24
24
13. What will be the output of the following Java program?
class A {
void display() {
[Link]("Class A");
}
}
7
7
01
01
01
01
01
01
01
01
class B extends A {
10
10
10
void show() { 10
24
24
24
24
[Link]("Class B");
}
}
class C extends B {
void print() {
[Link]("Class C");
}
}
7
7
01
01
01
1
10
01
01
01
class Test {
0
10
10
10
10
24
24
24
24
public static void main(String[] args) {
17
7
01
01
01
C obj = new C();
10
01
01
01
0
[Link]();
10
10
10
10
24
24
24
24
[Link]();
[Link]();
}
}
Answer
Class AClass BClass C
Status : Correct Marks : 1/1
7
17
17
01
01
14. What will be the output of the following program?
10
0
01
01
01
00
10
10
10
1
24
24
24
24
class A {
public int i;
private int j;
}
class B extends A {
void display() {
super.j = super.i + 1;
[Link](super.i + " " + super.j);
}
}
7
7
01
01
01
01
class inheritance {
01
01
01
01
public static void main(String args[]) {
10
10
10
10
24
24
24
24
B obj = new B();
obj.i=1;
obj.j=2;
[Link]();
}
}
Answer
Compile Time Error
Status : Correct Marks : 1/1
7
7
01
01
01
1
10
01
01
01
0
10
10
10
10
24
24
24
24
15. What will be the output of the following program?
17
7
01
01
01
10
01
01
01
0
class Vehicle {
10
10
10
10
24
24
24
24
String type = "Vehicle";
}
class Test {
public static void main(String[] args) {
Car c = new Car();
7
17
17
01
01
[Link]([Link]);
10
0
01
01
01
00
}
10
10
10
1
24
24
24
24
}
Answer
Car
Status : Correct Marks : 1/1
7
7
01
01
01
01
01
01
01
01
10
10
10
10
24
24
24
24
7
7
01
01
01
1
10
01
01
01
0
10
10
10
10
24
24
24
24