Question
JAVA code .Please true code.. An IntegerCounter object has an integer attribute called state and an array of 3 observers, mainly objects of Printer abstract
JAVA code .Please true code..
An IntegerCounter object has an integer attribute called state and an array of 3 observers, mainly objects of Printer abstract class. Create a method to attach observers(add into array) into the IntegerCounter objects. Every time its state attribute is modified this class should alert all of its observers (call their update method.) Printer Abstract class should be defined like below:
public abstract class Printer{
public abstract void update() }
Your program should have 3 Timer Classes that extends Printer:
1. 1Second Timer prints time every second using update method.
2.10 Second Timer prints time every 10 seconds. (After objects state updated 10 times) using update method.
3. 20 Second Timer prints time every 20 seconds. (After object state updated 20 times) using update method.
Your program needs to print out the exact times objects state value is changed. Each one of them should be notified when there is a change in Integer Counters state value and prints out time independently of each other. Your programs output should look like this. You can use color codes with System.out.println to color your output provided below. (Not Mandatory) static
Color Codes (System.out.println(COLOR_ATTRIBUTE+TEXT)): 1) public static final String ANSI_GREEN = "\u001B[32m";
2) public static final String ANSI_RED = "\u001B[31m";
3) public static final String ANSI_YELLOW = "\u001B[33m";
1 Second Tiner Notified at :20.22.00 10 Seoond Timer Notified at :20.22.00 20 Seoond Timer Notified at:20.22.00 1 Second Timer Notified at :20.22.01 1 Second Timer Notified at :20.22.02 1 Second Timer Notified at :20.22.03 1 Second Timer Notified at :20.22.04 1 Second Timer Notified at :20.22.05 1 Second Tiner Notified at :20.22.06 1 second Time Notified at :20.22.07 1 Second Tiner Notified at :20.22.08 1 Seoond Timer Notified at :20.22.09 1 Seoond Timer Notified at :20.22.10 10 s oond Timer Notified at :20.22.10 1 Second Timer Notified at :20.22.11 1 Second Timer Notified at :20.22-12 1 Second Timer Notified at :20.22-13 1 Second Timer Notified at :20.22.14 1 second Timer Not 1 fled at :20-22.15 1 second Timer Not 1 fled at 120.22.16 1 second Tiner Notified at :20.22.1 1 Seoond Tiner Notified at :20.22.18 1 Seoond Timer Notified at :20.22.19 1 Second Timer Notified at :20.22.20 10 Seoond Timer Notified at 20.22.20 20 Second Timer Notified at :20.22.20 1 Second Timer Notified at :20.22.21 1 Second Timer Notified at :20.22.22 1 second Tiler Not 1 fled at :20-22.23 1 second Tiler Not 1 fled at :20 . 22.24 1 second Timer Notified at :20.22.25 25 Second Passed Since Program Executed! BUILD SUCCESSPOL (total time: 26 seconds)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started