subject

Create and work with interfaces In this exercise, you'll create the DepartmentConstants interface presented in this chapter. In addition, you'll implement an interface named Displayable that similar to the Printable interface presented in this chapter. Create the interfaces 1. Open the project named ch09_exl_Displayable Test in the ex starts folder. Then, review the code.
2. Note that this code includes an interface named Displayable that contains a single method named getDisplay Text() that returns a String.
3. Open the Displayable TestApp class. Then, note that it includes a method named display that accepts a Displayable object as an argument.
4 Add an interface named Department Constants that contains these three constants: ADMIN, EDITORIAL, and MARKETING. Implement the interfaces
5. Open the Product class. Then, edit it so it implements the Displayable interface. To do that, add a getDisplay Text() method that returns a description of the product.
6. Open the Employee class. Then, edit it so it implements the DepartmentConstants and Displayable interfaces. To do that, add a getDisplay Text() method that uses the constants in the Department Constants interface to include the department name and the employee's name in the string that it returns. Use the classes that implement the interfaces
7. Open the Displayable TestApp class. Then, modify the variable that stores the Employee object so it is of the Displayable type.
8. Add code that passes the Displayable object to the static display method that's coded at the end of this class.
9. Run the application to make sure that it displays the employee information.
10. Repeat the previous three steps for a Product object. When you're done, the console should look like this: Welcome to the Displayable Test application John Smith (Editorial) Murach's Java Programming Use a default method
11. In the Employee and Product classes, rename the getDisplay Text() methods to toString() methods so they override the toString method of the Object class. This should prevent the classes from compiling and display an error message that indicates that the classes don't implement the getDisplay Text() method. Section 2 Object-oriented programming
12. In the Displayable interface, modify the getDisplay Text() method so it's a default method. The code for this method should return the String object that's returned by the toString() method. This should allow the Employeee and Product classes to compile since they can now use the default method
13. Run the application to make sure it works as before.

ansver
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 17:40, lazerlemon500
Write a modular program (no classes yet, just from what you learned last year), that allows two players to play a game of tic-tac-toe. use a two-dimensional char array with 3 rows and 3 columns as the game board. each element of the array should be initialized with an asterisk (*). the program should display the initial board configuration and then start a loop that does the following: allow player 1 to select a location on the board for an x by entering a row and column number. then redisplay the board with an x replacing the * in the chosen location. if there is no winner yet and the board is not yet full, allow player 2 to select a location on the board for an o by entering a row and column number. then redisplay the board with an o replacing the * in the chosen location. the loop should continue until a player has won or a tie has occurred, then display a message indicating who won, or reporting that a tie occurred. player 1 wins when there are three xs in a row, a column, or a diagonal on the game board. player 2 wins when there are three ox in a row, a column, or a diagonal on the game board. a tie occurs when all of the locations on the board are full, but there is no winner. input validation: only allow legal moves to be entered. the row must be 1, 2, or 3. the column must be 1, 2 3. the (row, column) position entered must currently be empty (i. e., still have an asterisk in it).
Answers: 1
image
Computers and Technology, 22.06.2019 18:00, abbygriffin2009
Martha is a healer, a healthcare provider, and an experienced nurse. she wants to share her daily experiences, as well as her 12 years of work knowledge, with people who may be interested in health and healing. which mode of internet communication can martha use?
Answers: 3
image
Computers and Technology, 23.06.2019 06:30, eddsworldfrantic
You have a small company and want to keep your costs low, but it is important your employees share data. which network would provide you with the most economical solution?
Answers: 1
image
Computers and Technology, 23.06.2019 12:30, Prettygirlyaya
How is the brightness of oled of the diaplay is controled
Answers: 1
You know the right answer?
Create and work with interfaces In this exercise, you'll create the DepartmentConstants interface pr...

Questions in other subjects:

Konu
Business, 11.03.2021 01:00
Konu
Mathematics, 11.03.2021 01:00
Konu
Biology, 11.03.2021 01:00