United International University
Dept. of Computer Science & Engineering
Course Code: CSE 1116
Course Title: Object Oriented Programming Laboratory
Section: L Marks: 20
Time: 30 minutes
Create a class named Smartphone with the following:
Instance Variables:
• brand (String): the brand of the smartphone.
• model (String): the model name or number.
• price (double): the price of the smartphone.
• stockQuantity (int): the number of units in stock.
Methods:
1. Constructors:
o A parameterized constructor to initialize all attributes.
o A default constructor that sets:
▪ brand = "Generic"
▪ model = "Unknown Model"
▪ price = 0.0
▪ stockQuantity = 0
2. checkStockStatus():
o Returns "In Stock" if stockQuantity > 0, otherwise "Out of Stock".
3. updateStock(int newStock):
o A setter method to update the stockQuantity attribute.
4. Overloaded Methods:
o applyDiscount(double discountPercentage): Reduces the price of the
smartphone by the given percentage.
o applyDiscount(double flatAmount, String discountType): Reduces the price
by a flat amount only if discountType equals "FLAT".
5. isAffordable(double budget):
o Checks whether the smartphone's price is within the given budget. Returns
true if the price is less than or equal to the budget, otherwise false.
Main Class with Tasks
Write a Main class with a main method that performs the following:
1. Create a Smartphone object using the parameterized constructor, with user-
provided values for the attributes.
2. Check the stock status using checkStockStatus() and print the result.
3. Apply a 15% discount using the applyDiscount(double discountPercentage)
method and print the updated price.
4. Apply a flat discount of 200 units using the overloaded applyDiscount method with
the appropriate discount type, and print the updated price.
5. Update the stock quantity to a new value (input from the user) using the
updateStock() method and check the stock status again.
6. Check if the smartphone is affordable within a budget provided by the user using
isAffordable() and print the result.