Question Bank - MTE
Question Bank - MTE
Task:
Create a base class Product with attributes: productId, productName, and price. Initialize
them using a constructor and include a method calculateBill() that returns the base price.
Create a subclass ElectronicProduct with an extra attribute warrantyCharge. Override
calculateBill() to return price + warrantyCharge.
Create another subclass ClothingProduct with an extra attribute discount. Override
calculateBill() to return price - discount.
In the main() method, simulate the billing system by creating one object each of
ElectronicProduct and ClothingProduct. Use dynamic method dispatch to display the total
bill for each product category.
33. You are tasked with building a smart calculator feature for a personal assistant app. The
calculator has to intelligently interpret the number of inputs and perform different
operations accordingly.
Task:
Define a class SmartCalculator with a method add() that behaves differently based on the
number of arguments passed:
If one argument is passed, treat it as a request to square the number and return the result.
If two arguments are passed, add the numbers and return the sum.
Demonstrate the usage of this feature by creating an object of SmartCalculator and calling
the add() method with both one and two arguments to simulate real-use scenarios.
34. Scenario:
You're creating a course enrollment system. The university offers online and offline
courses with varying fee structures.
Task:
Create an abstract class Course with attributes: courseId, courseName, and baseFee.
Include an abstract method calculateFee().
OnlineCourse has an additional attribute platformFee, which is added to the base fee.
OfflineCourse has a labFee, which is added to the base fee.
Implement the calculateFee() method in both subclasses.
In the main() method, simulate the fee calculation for both types of courses using
abstract class reference.
35. Scenario:
A fitness center offers memberships for general fitness and personal training.
Task: