Consider the following class: public class Assignment2 { public Assignment2() { System.out.print(Instancecreatedat: + System.currentTimeMillis()); We would like
Question:
public class Assignment2 {
public Assignment2() {
System.out.print("Instancecreatedat:" + System.currentTimeMillis());
We would like to implement the Assignment2 class as a modified version of Singleton design pattern. Let us call the new class SingletonAssignment2. However, instead of allowing one single instance to be created, we would like to enable a maximum of three instances to be created.
Here is a description of the client code, called SingletonTest, that would create instances of SingletonAssignment2 class:
The user is asked whether he/she would like to create an instance of the SingletonAssignment2.
1. If the answer is "Yes": create a new instance only if the number of instances that have been created so far is less than three. Otherwise, display the message You cannot create more than three instances and the instance created last is returned.
2. If the answer is No, display the message "No instance is requested.
You need to provide:
1. The UML class diagram for the SingletonAssignment2 class.
2. Implement the SingletonTest client and SingletonAssignment2 class based on your UML class diagram. Implement a scenario in your SingletonTest in which the users inputs are "No, Yes, Yes, Yes, Yes".