Question: Program in java Concept for Our Part of the Game Code When a goat's score changes, it triggers two changes: 1. The Point Display for

Program in java

Program in java Concept for Our Part of the Game Code When

Concept for Our Part of the Game Code When a goat's score changes, it triggers two changes: 1. The Point Display for the goat is changed. 2. A Winner Display to declare the winner when a goat gets to 1000 points. The Observer pattern is well-suited for this problem. Each player is a Source and both Displays are Observers. Program Design Have a Goat Class that extends Observable (or Submission Publisher). In Goat, have a name field (String) and a score field (int). Write a getter and setter for both. The constructor should set the score to 0 and assign your goat a name. Goat needs a method named addPoints(int) that adds points to the Goat's score.addPoints(int) calls setchanged() and notifyObservers() to signal that the score has changed (in addition to changing the score for a Goat). In add points, do nothing if the parameter is less than or equal to 0. Each play has a goat. Create two classes that implement Observer (or Subscriber), named PointDisplay and Winner Display. Both displays will observe both goats. o update in PointDisplay will output " ate something and now has points." o Winner Display's update method will only produce output when the first Goat breaks 1000 points. When a Goat breaks 1000 points, Winner Display will output, " wins." The GoatSimulator class contains main. It declares, instantiates Observers and Subjects, and registers the Observers. Then make a series of .addPoints () calls until one of the Goats wins the game. (Have at least 10 calls to addPoints before one of the goats acquires 1000 points.) Concept for Our Part of the Game Code When a goat's score changes, it triggers two changes: 1. The Point Display for the goat is changed. 2. A Winner Display to declare the winner when a goat gets to 1000 points. The Observer pattern is well-suited for this problem. Each player is a Source and both Displays are Observers. Program Design Have a Goat Class that extends Observable (or Submission Publisher). In Goat, have a name field (String) and a score field (int). Write a getter and setter for both. The constructor should set the score to 0 and assign your goat a name. Goat needs a method named addPoints(int) that adds points to the Goat's score.addPoints(int) calls setchanged() and notifyObservers() to signal that the score has changed (in addition to changing the score for a Goat). In add points, do nothing if the parameter is less than or equal to 0. Each play has a goat. Create two classes that implement Observer (or Subscriber), named PointDisplay and Winner Display. Both displays will observe both goats. o update in PointDisplay will output " ate something and now has points." o Winner Display's update method will only produce output when the first Goat breaks 1000 points. When a Goat breaks 1000 points, Winner Display will output, " wins." The GoatSimulator class contains main. It declares, instantiates Observers and Subjects, and registers the Observers. Then make a series of .addPoints () calls until one of the Goats wins the game. (Have at least 10 calls to addPoints before one of the goats acquires 1000 points.)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!