Challenge exercise In the current design of ClockDisplay, a ClockDisplay object is responsible for detecting when a NumberDisplay object has rolled over to zero and then telling another NumberDisplay object to increment. In other words, there is no direct link between NumberDisplay objects. Would it be possible to have one NumberDisplay object tell another that it has rolled over, and that the other NumberDisplay object should then increment? For instance, have the minutes object tell the hour object that another hour has passed, or have the seconds object tell the minutes object that another sixty seconds have elapsed. Which of these objects would the timeTick method interact with? What fields would a NumberDisplay object have? What should the hour object do when a whole day has elapsed? Discuss the issues involved in this alternative design and, if you really feel like a challenge, try implementing it! Note that you might need to find out about the Java null keyword, which we don't cover until late in Chapter 4.
Want to see the full answer?
Check out a sample textbook solutionChapter 3 Solutions
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
Additional Engineering Textbook Solutions
Experiencing MIS
Starting Out with C++ from Control Structures to Objects (9th Edition)
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Starting Out With Visual Basic (8th Edition)
Computer Systems: A Programmer's Perspective (3rd Edition)
- : Design and implement a text-based Minesweeper game. Minesweeper is the classicsingle-player computer game where an NxN grid has B mines (or bombs) hidden across the grid. Theremaining cells are either blank or have a number behind them. The numbers reflect the number ofbombs in the surrounding eight cells. The user then uncovers a cell. If it is a bomb, the player loses.If it is a number, the number is exposed. If it is a blank cell, this cell and all adjacent blank cells (up toand including the surrounding numeric cells) are exposed. The player wins when all non-bomb cellsare exposed. The player can also flag certain places as potential bombs. This doesn't affect gameplay, other than to block the user from accidentally clicking a cell that is thought to have a bomb.(Tip for the reader: if you're not familiar with this game, please play a few rounds on line first.)arrow_forwardThe Contact class implements the Comparable interface and thereforeprovides a definition of the compareTo method. In this case, the contacts aresorted by last name; if two contacts have the same last name, their first namesare used.arrow_forwardHELP WITH EXAMPLES OF THE METHODS, IN THE TODO package integerarraylist; import static org.junit.jupiter.api.Assertions.*; import java.util.ArrayList; import org.junit.jupiter.api.Test; class CustomIntegerArrayListTest { @Test void testGetArrayList() { //create a new empty CustomIntegerArrayList CustomIntegerArrayList arr1 = new CustomIntegerArrayList(); arr1.add(2); arr1.add(0, 5); arr1.add(1, 5); ArrayList<Integer> lst1 = new ArrayList<Integer>(); lst1.add(2); lst1.add(0, 5); lst1.add(1, 5); assertEquals(lst1, arr1.getArrayList()); ArrayList<Integer> arr4Elements = new ArrayList<Integer>(); arr4Elements.add(100); arr4Elements.add(200); arr4Elements.add(500); //create a new CustomIntegerArrayList with the elements in the given ArrayList CustomIntegerArrayList arr4 = new CustomIntegerArrayList(arr4Elements); ArrayList<Integer> lst4 = new ArrayList<Integer>(); lst4.add(100); lst4.add(200); lst4.add(500); assertEquals(lst4,…arrow_forward
- Implement an ADT that can used as a Tic-Tac-Toe game board. Your ADT will implement the interfacegiven below. In the main method also include a simple usage example.Here are the rules of N x N Tic-Tac-Toe game:• Players take turns placing characters into empty squares (" ").• The first player A always places "X" characters, while the second player B always places "O" characters.• "X" and "O" characters are always placed into empty squares, never on filled ones.• The game ends when there are N of the same (non-empty) character filling any row, column, or diagonal.• The game also ends if all squares are non-empty.• No more moves can be played if the game is over Must be outputted in the console not with gui.arrow_forwardDiscuss the limitations of the Comparable interface when it comes to sorting custom objects. When might you need to resort to using the Comparator interface instead?arrow_forwardImplement the "paint fill"feature seen in several picture editing products.To put it another way, if you have a screen (represented by a two-dimensional array of colours), a point, and a new colour, Fill in the surrounding area until the colour shifts away from the original.arrow_forward
- . For the TimeSpan class described below, add a compareTo method that takes another TimeSpan object as a parameter & returns: -1 if this TimeSpan is SMALLER than to the TimeSpan object passed in as a parameter 0 if both TimeSpans are the same 1 if this TimeSpan is GREATER than the TimeSpan object passed in as a parameter Add code, as needed, to allow the Collections class to sort the ArrayList of TimeSpan objects import java.util.*; public class TimeSpan implements { private int hours; private int minutes; public TimeSpan(int hours1, int minutes1) { hours = 0; minutes = 0; add(hours1, minutes1); } public void add(int hours1, int minutes1) { hours += hours1; minutes += minutes1; while (minutes > 60) { minutes -= 60; // convert 60 min --> 1 hour hours++; } } public void add(TimeSpan time) { add(time.hours, time.minutes); }…arrow_forwardIn programming, we use the mask concept to indicate information that can be shown to the user and information that must be “masked”, that is, hidden. In an implementation of a hangman game, we use a mask to indicate which secret word positions the player has already guessed right (whose the contents must therefore be shown to the player), and which positions must remain hidden. Each time that the player hits a letter of the hidden word, the mask is updated so that it has little dashes in the places of letters that the player has not hit yet and show it, in their proper place, the letters that he already hit it. For example, if the word is "cards", the current mask is: - a - - s and the player guesses the letter "d", the mask should be updated to: - a - ds.Write a function called update_mask that takes as input a string containing the word secret (in the example above, this word would be “cards”), a list whose elements are the characters of the current mask (in the example above…arrow_forwardDevelop a class VisualCounter that allows both increment and decrementoperations. Take two arguments N and max in the constructor, where N specifies themaximum number of operations and max specifies the maximum absolute value forthe counter. As a side effect, create a plot showing the value of the counter each time its tally changes.arrow_forward
- You are to write an Ant class to simulate Langton's Ant. In this simulation, a virtual "ant" moves about a two-dimensional square matrix, whose spaces can be designated white or black, according to the rules below: If the ant is on a white space, it will turn right 90 degrees relative to the directions it is facing, move forward one step, and change the space it left to black. If the ant is on a black space, it will turn left 90 degrees relative to the directions it is facing, move forward one step, and change the space it left to white. When the ant hits the edge of the board and is going to go out of the bounds, wrap the board around so the ant will appear on the other side. The matrix is initially composed of all white spaces. The user will specify the size of the square matrix. The user will also specify the number of steps that the ant will move and the starting location and direction of the ant. After the simulation, the final board with the ant position will be displayed to…arrow_forwardImplement a class named Parade using an ArrayList, which will manage instances of class Clown. Each Clown only needs to be identified by a String for their name. Always join a new Clown to the end of the Parade. Only the Clown at the head of the Parade (i.e., the first one) can leave the Parade. In addition, also write a method called isFront that takes a Clown as parameter and returns true if the passed clown is at the front of the parade otherwise returns false. Create a test application to demonstrate building a parade of three or four clowns and include your own name. Then, remove one or two, and add another one or two. Also, test the isFront method by passing different clowns to the method.arrow_forwardI need help with this Java program over a Cell class program shown below detailed in the given image: This is the Java code (Cell class)that need fixed with help of both the given image and the interface guide - package classPackage; import java.util.ArrayList; import interfaces.CellInterface; import interfaces.RatInterface; /** * @author Owner * */ public class Cell implements CellInterface { privatefinalint [] location; private ArrayList <RatInterface> ratHouse = new ArrayList <RatInterface>(); public Cell(int[] pLocation) { location = pLocation.clone(); } @Override publicchar getCellType() { // TODO Auto-generated method stub return 0; } @Override publicint[] receiveRat(RatInterface pRat) { pRat.wearDown(); if (Math.random()<.2) pRat.refresh(); ratHouse.add(pRat); returnlocation.clone(); } @Override public RatInterface retrieveRat() { /** * The storeTheDead(Rat pRat) method stores the argument Rat in a list of dead rats. * precondition: pRat must…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education