Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi, when I was typing my code. I got into a trouble. When I tried to add implements observer, it said I couldn't override my

Hi, when I was typing my code. I got into a trouble. When I tried to add "implements observer", it said I couldn't override my update method, but I must update it for printing those sentences. Also, I was uncertain what I should do for the Observable class, could someone please explain some ideas behind to me? image text in transcribed
The designpatterns is not allowed to modify image text in transcribed
image text in transcribed
image text in transcribed
In order for this to work, you'll have to do the following: 1. CustomList will have to implement the Iterable interface, which means it will have to return an Iterator. The Iterator should be implemented such that it skips values over 9000. In other words, as far as your Iterator is concerned, values over 9000 should be ignored for the purposes of getting the next value in the list, or determining whether there are more values in the list. (Your Iterator doesn't need to do anything for the remove() method.) 2. You can create a new source file that defines a class for your custom iterator, or you can create the iterator as an anonymous class which CustomList returns on a call to iterator(). It's up to you. 3. The Scouter wants to know when a value over 9000 is added to the CustomList. To do this, it should implement Java's Observer interface. Then, when the Scouter's update() method is called. It should print the text "It's over 9000!!!" 4. CustomList should extend Java's Observable class. Whenever a value is added to CustomList. It should check if that value is over 9000, and if it is, it should notify all observers of that event. It would be possible to get the program to print the desired output without Implementing all of the required design patterns, but if you do so, you will lose a lot of points. import java.util. public class Customlist extends Observable implements Iterator List atterns nment.ml public void addobserver(Scouter sco) { braries and Console: 12 // TODO: Add your code inside this class. private ArrayList list = new ArrayListo(); public void add(Integer i) { System.out.println("Adding " + i +" list.add(i); BRONEER abstract class Observable{ int Value; Scouter sco=new Scouter(); 215 CustomList External file changes sync may be slow: Project files cannot be watched (are they under ne... (today 7:19 PM) Ona Observer (Java Platform SE 7) - Mo... source import java.util. import java.util.Observable; public class Scouter implements Observer erns hent.iml COA aries nd Console: 12 @Override public void update(Observable o, Object arg) { if(arg>9000) { System.out.println("It's over 9000!!!"); }// TODO: Add your code inside this class. Scouter update any cannot be applied to Java.lang. Object, in gnment source 1 // Do not modify any of this code. public class DesignPatterns { public static void main(String[] args) { tomList signPatterns Assignment.iml puter nal Libraries tches and Console: CustomList list = new CustomList(); Scouter scouter = new Scouter(); list.addobserver(scouter); list.add(1024); list.add(2048); list.add(16384); list.add(4096); list.add(8192); list.add(32768); System.out.println(); System.out.println("Printing power levels"); System.out.println(" for (Integer i : list) System.out.println(i); System.out.println(" Dones "); System.out.println(); ON main Design Patterns foreach not applicable to type "Customist Observer (lava Platform SE7) Mo In order for this to work, you'll have to do the following: 1. CustomList will have to implement the Iterable interface, which means it will have to return an Iterator. The Iterator should be implemented such that it skips values over 9000. In other words, as far as your Iterator is concerned, values over 9000 should be ignored for the purposes of getting the next value in the list, or determining whether there are more values in the list. (Your Iterator doesn't need to do anything for the remove() method.) 2. You can create a new source file that defines a class for your custom iterator, or you can create the iterator as an anonymous class which CustomList returns on a call to iterator(). It's up to you. 3. The Scouter wants to know when a value over 9000 is added to the CustomList. To do this, it should implement Java's Observer interface. Then, when the Scouter's update() method is called. It should print the text "It's over 9000!!!" 4. CustomList should extend Java's Observable class. Whenever a value is added to CustomList. It should check if that value is over 9000, and if it is, it should notify all observers of that event. It would be possible to get the program to print the desired output without Implementing all of the required design patterns, but if you do so, you will lose a lot of points. import java.util. public class Customlist extends Observable implements Iterator List atterns nment.ml public void addobserver(Scouter sco) { braries and Console: 12 // TODO: Add your code inside this class. private ArrayList list = new ArrayListo(); public void add(Integer i) { System.out.println("Adding " + i +" list.add(i); BRONEER abstract class Observable{ int Value; Scouter sco=new Scouter(); 215 CustomList External file changes sync may be slow: Project files cannot be watched (are they under ne... (today 7:19 PM) Ona Observer (Java Platform SE 7) - Mo... source import java.util. import java.util.Observable; public class Scouter implements Observer erns hent.iml COA aries nd Console: 12 @Override public void update(Observable o, Object arg) { if(arg>9000) { System.out.println("It's over 9000!!!"); }// TODO: Add your code inside this class. Scouter update any cannot be applied to Java.lang. Object, in gnment source 1 // Do not modify any of this code. public class DesignPatterns { public static void main(String[] args) { tomList signPatterns Assignment.iml puter nal Libraries tches and Console: CustomList list = new CustomList(); Scouter scouter = new Scouter(); list.addobserver(scouter); list.add(1024); list.add(2048); list.add(16384); list.add(4096); list.add(8192); list.add(32768); System.out.println(); System.out.println("Printing power levels"); System.out.println(" for (Integer i : list) System.out.println(i); System.out.println(" Dones "); System.out.println(); ON main Design Patterns foreach not applicable to type "Customist Observer (lava Platform SE7) Mo

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Illuminated

Authors: Catherine Ricardo

2nd Edition

1449606008, 978-1449606008

More Books

Students also viewed these Databases questions