0% found this document useful (0 votes)
12 views

Assignment 2

Oop assignment 2

Uploaded by

vikasbarker390
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Assignment 2

Oop assignment 2

Uploaded by

vikasbarker390
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Faculty of Engineering

School of Information Technology


B. TECH Information Technology
VII Semester
Assignment 2
IT 4148 Object Oriented Design & Patterns
Instruction:

• Submit your answers as handwritten and scanned pdf document through following link on or
before 30 Nov 2024.

https://forms.office.com/r/aTbaGpQtrJ

1. Write a method
public static Object minimum(ArrayList a)
that computes the smallest element in the array list. Assume that the elements of the array list
implement the Comparable interface type, and that the array is not empty. Document these
preconditions. (Here, we use the “raw” ArrayList and Comparable types without type
parameters. As a result, the compiler will issue warnings that you may ignore.)
2. Write a method
public static String maximum(ArrayList<String> a, Comparator<String> c)
that computes the largest string in the array list, using the ordering relationship that is defined
by the given comparator. Supply a test program that uses this method to find the longest string
in the list.
3. What is a design pattern in Java, and why is it important in software development? Use the
COMPOSITE pattern to define a class CompositeIcon that implements the Icon interface
type and contains a list of icons. Supply a method void addIcon(Icon icon, int x,
int y)
4. Implement a Factory Method pattern to create different types of shapes (e.g., Circle,
Rectangle, Triangle). Then create a Shape interface, implement concrete classes for each
shape, and design a factory method to instantiate these shapes dynamically based on user
input.
5. Design a Singleton class for a logger utility that ensures only one instance of the logger is
created, and it is thread-safe. Then implement the Singleton pattern and demonstrate logging
messages from multiple threads.
6. Design a Composite pattern to represent a file system where directories can contain files or
other directories. Then implement the Component, Leaf (File), and Composite (Directory)
classes, and demonstrate operations like adding, removing, and displaying elements.
7. Create a Decorator pattern for a text editor to add functionalities like spell checking and
grammar checking to plain text. Then implement base and decorator classes to apply these
functionalities dynamically.
8. Create a Proxy pattern to add access control to a database. Only authorized users should be
able to fetch or update data. Then implement the Proxy class to check permissions before
delegating calls to the actual database class.

You might also like