QuestionSet6
QuestionSet6
1. (Abstract)
Create an abstract class called Appliance with an attribute brand and an abstract method
calculateElectricityUsage(). Then create two classes, WashingMachine and Refrigerator, that
extend Appliance with the attribute of powerUsagePerHour. Implement the
calculateElectricityUsage() method in each class. calculateElectricityUsage() function of
washing machine should be multipled of powerUsagePerHour by 2, which means 2 hours of
usage, on the other hand assume that refrigerator will be used 24 hours. The main is given and
output should look like below.
2. (Abstract)
Create a class called SmartAppliance that extends the Appliance class. This class should
include an additional attribute, a List<String> called smartFeatures, which will hold the
names of the smart features. The SmartAppliance class should provide a method called
addSmartFeature that takes a String feature and a double additionalUsage as parameters. This
method should add the new feature to the smartFeatures list and also increase the
powerUsagePerHour by the additionalUsage amount corresponding to the smart feature.
Finally, update the calculateElectricityUsage method to return the total electricity usage
considering the current power usage for 2 hours of operation. The main is given and output
should look like below.
3. (Abstract)
Create a class called ApplianceManager that is responsible for managing multiple appliances
derived from the Appliance class. This class should contain a List<Appliance> to store the
appliances being managed. You will need to implement the method addAppliance(Appliance
appliance), which takes an Appliance object as a parameter and adds it to the list of
appliances. Additionally, implement the method calculateTotalElectricityUsage(), which
should iterate through the list of appliances and sum their electricity usage by invoking their
respective calculateElectricityUsage() methods. Finally, this method should return the total
electricity usage of all the appliances managed by the ApplianceManager. The main is given
and output should look like below.
4. (Final keyword)
Create a class named Configuration that contains a final attribute MAX_USERS. This
attribute will hold the maximum number of users allowed in the system, and it should be
declared as a public static final integer. The final keyword indicates that this value cannot be
changed once it is initialized. Next, create a class called UserManagementSystem. This class
should maintain the current number of users and provide a method to add new users. The
addUser method should first check if the current number of users is less than the
MAX_USERS value from the Configuration class. If it is, the method should increase the
count of current users by one and print a message indicating that a user has been added, along
with the new total number of users. If adding a user would exceed the MAX_USERS limit,
the method should print a message stating that the maximum limit has been reached. The
main is given and output should look like below.
5. (Final keyword)
Create a class named LibraryConfig that includes a final attribute MAX_BOOKS set to 4,
representing the maximum number of books that can be added to the library. This attribute
should be declared as public static final int. Create a class called BookManagementSystem
that manages a collection of book titles using a List<String>. This class should have a method
addBook(String title) that checks whether the current number of books is less than
MAX_BOOKS. If the current size of the book list is below the limit, the method should add
the book title to the list and print a message indicating that the book has been successfully
added (e.g., "The Great Gatsby has been added to the library."). However, if the maximum
limit has been reached (4 books), the method should print a message stating that no more
books can be added (e.g., "Cannot add more books, the maximum limit has been reached.").
The main is given and output should look like below.
6. (Superclasses)
Create a superclass named Device that has a String attribute called model to represent the
device's model name. This class should also include a method turnOn() that prints a generic
message indicating that the device is turning on. Next, extend this class with two subclasses:
Smartphone and Laptop. In each subclass, override the turnOn() method to provide a specific
message for each type of device. The main is given and output should look like below.
7. (Superclasses)
Create a superclass named Product that has attributes for productName, price, and quantity.
Include a method called displayProductInfo() that prints the product’s details. Next, create
two subclasses: Electronics and Clothing. The Electronics class should have an additional
attribute for warrantyPeriod, while the Clothing class should have an attribute for size.
Override the displayProductInfo() method in both subclasses to include specific details related
to each type of product. The main is given and output should look like below.
8. (Interface)
Create an interface named Storable with a method storeItem(). Then create two classes:
Warehouse and Store, both of which implement the Storable interface. The Warehouse class
should have an attribute for capacity and implement the storeItem() method to indicate how
many items can be stored. The Store class should have an attribute for location and implement
the storeItem() method to indicate that an item is being displayed. The main is given and
output should look like below.
9. (Interface)
Create an interface called Payable that declares a method processPayment(). Then create two
classes: CreditCard and PayPal, both of which implement the Payable interface. The
CreditCard class should have attributes for cardNumber and cardHolder, while the PayPal
class should have an attribute for email. Implement the processPayment() method in each
class to display a message indicating the payment method being used. The main is given and
output should look like below.
10. (Interface)
Create an interface called Notifiable that declares a method sendNotification(). Then create
two classes: EmailNotification and SMSNotification, both of which implement the Notifiable
interface. The EmailNotification class should have an attribute for emailAddress, while the
SMSNotification class should have an attribute for phoneNumber. Implement the
sendNotification() method in each class to display a message indicating the type of
notification being sent along with the relevant details. The main is given and output should
look like below.
11. (Adapter)
Create a LegacyPrinter class that has an attribute for the printer's name and a method
printDocument() for printing documents. The new printing system requires a method called
print(), defined by a NewPrinter interface. Your task is to implement an adapter class called
PrinterAdapter that will make the LegacyPrinter compatible with the new system by
implementing the NewPrinter interface. The main is given and output should look like below.
12. (Adapter)
Create a class named LegacyAudioPlayer that includes an attribute for the audio file name
and a method called playAudio() to play the audio file. In addition to this method, the
LegacyAudioPlayer should have extra methods such as stopAudio() and pauseAudio(), which
will not be utilized in the context of the new system. Next, create an interface named
ModernAudioPlayer that defines three methods: play(), stop(), and pause(). Your task is to
implement an adapter class called AudioPlayerAdapter that adapts the LegacyAudioPlayer to
the new system by implementing the ModernAudioPlayer interface. In the adapter class,
implement the play() method to call the playAudio() method of LegacyAudioPlayer, but leave
the stop() and pause() methods empty to illustrate that they are not needed for this specific
functionality.The main is given and output should look like below.
13. (Adapter)
Create a class named LegacyPaymentProcessor that includes an attribute for the payment
amount and a method called processPayment() to handle the payment processing.
Additionally, the LegacyPaymentProcessor should have extra methods such as
refundPayment() and cancelPayment(), which will not be utilized in the context of the new
system. Next, create an interface named PaymentGateway that defines three methods:
makePayment(), refund(), and cancel(). Your task is to implement an adapter class called
PaymentAdapter that adapts the LegacyPaymentProcessor to the new system by
implementing the PaymentGateway interface. In the adapter class, implement the
makePayment() method to call the processPayment() method of LegacyPaymentProcessor,
but leave the refund() and cancel() methods empty to illustrate that they are not needed for
this specific functionality. The main is given and output should look like below.
20. (Class)
Create a task management system by implementing a Task class and a TaskManager class.
The Task class should include attributes for title, description, and a boolean isCompleted to
track the task's status. It should have methods to mark the task as completed completeTask()
and to display the task's details displayTask(), which shows the title, description, and whether
it is completed. The TaskManager class will maintain a list of Task objects and should
include methods to add a new task (addTask(Task task)), display all tasks displayAllTasks(),
and display only incomplete tasks displayIncompleteTasks(). The main is given and output
should look like below.