Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java8 programming, interfaces,polymorphism,inheritance, convert uml to Java8 code,and output as expected. please explain in detail Interfaces declare methods that will describe a behaviour an object

Java8 programming, interfaces,polymorphism,inheritance, convert uml to Java8 code,and output as expected. please explain in detail

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Interfaces declare methods that will describe a behaviour an object may have. When a class implements the interface it will need to define the methods that have been declared to satisfy the relationship. public interface Talkable { //outputting what the object is saying public void talk(); //What the object should say, if it can understand words public void script (String[] words); } Wait... aren't they the same thing? These two concepts are oftenly confused of being the same thing when really they are used in different scenarios. Class heirarchy infers to a clear generalisation of a type while interfaces infers to an shared behaviour between types. Example 1: a Dog and Cat both exhibit some way of talking but the noise they emit is different and it doesn't make sense for Cat and Dog to be in the same heirarchy. Example 2: Person can interact with other Person objects but also Furniture, Singage and Animal objects. It is clear are not suitable to be in the same class heirarchy but can facilitate a method of Interaction. Unlike class inheritance where a class can only inherit from only a single class, a class can implement as many interfaces it wants. The following is where a Person class has specified it will implement a number of interfaces. public class Person implements Swim, Talk, Jump, Run Similar to abstract classes, when a class states it will implement an interface it will need to implement all methods declared. Question 4: Interacting with objects Given the following UML diagram, implement the following interface and classes. Your classes must be able to interact with any object that implements the Interactable interface. When an object invokes talkTo, it will use Strings from the initiation script, for every elements in the initiation script the target object will respond with Strings in the response script. > Interactable +talkTo(thing:Interactable): void +responseScript(): List +contactScript(): List Alien Person Billboard - content: String +talkTo(thing:Interactable): void +responseScript(): List +contactScript(): List -isHostile: boolean |-contact: List - responses: List -name: String |-contact: List - responses: List +talkTo(thing:Interactable): void +responseScript(): List +contactScript(): List +getName (): String +talkTo(thing:Interactable): void +responseScript(): List +contactScript (): List Figure 4: Interaction UML Diagram There are a few conditions of interaction between these objects. Consider how the dialogue for all 3 classes could be inputted. This could be as simple as creating a constructor that allows for input or extending the interface. All objects have variable length scripts, if a script contains no Strings, then the dialogue may be cut short to someone just specifying the first string as part of their script. Person object will use their name at the beginning of their script. You may utilise the isHostile attribute in the Alien class however you see fit. Billboard usually has short messages to state that it is trying to sell to you immediately. It does not have a clever method of communication and will instead just responds to you with a whole string. Output of a Person interact with another Person selling tickets. Hi ow are you? Get tickets for 'Splendour in the Grass'! Oh okay

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

Database Horse Betting The Road To Absolute Horse Racing 2

Authors: NAKAGAWA,YUKIO

1st Edition

B0CFZN219G, 979-8856410593

More Books

Students also viewed these Databases questions