Zybooks SDEV 255 2.1.1 Objects
Define a method named orderOfAppearance() that takes the name of a role as an argument and returns that role's order of appearance. If the role is not found, the method returns 0. Ex: orderOfAppearance("Elizabeth Swann") returns 3. Hint: A method may access the object's properties using the keyword this. Ex: this.title accesses the object's title property.
// Code will be tested with different roles and movies
let movie = {
title: "Pirates of the Caribbean: At World's End",
director: "Gore Verbinski",
composer: "Hans Zimmer",
roles: [ // Roles are stored in order of appearance
"Jack Sparrow",
"Will Turner",
"Elizabeth Swann",
"Hector Barbossa"
],
orderOfAppearance: function(role) {
}
};
There is a Lord of the rings test that tests orderOfAppearance for "Saruman" but it is not shown.
Heres my current code i tried
if(role!==this.orderOfAppearance[role])
return "3";
else
return this.orderOfAppearance[role]
return "0";
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 2 images
- QUESTION 7 Final data/code constructs are only inheritable once. O True O False QUESTION 8 You can include code in an interface by using the keywordarrow_forwardTrue or False ___(13) A client code is a program that uses classes and objects. ___(14) The concept of allowing a class's private data to be changed only by a class's own methods is known as data masking. ___(15) The keyword super in the Java statement y = super.getX(); refer to the getX() method in the super class.arrow_forward1- A variable of class type (i.e., object) always require the same amount of memory to store its values? False True 2- A class that contains no methods (other than constructors) that change any of the data in its object is called as: Mutable class Immutable class Anonymous class Class invariantarrow_forward
- True or False 1) After a user defines his/her own constructor in a Java class, the default constructor is still available. ___(2) Java supports multiple inheritances directly. ___(3) Some methods in an interface can have method body.arrow_forwardPage < 32 of 41 You can override a private method defined in a subclass. (True/False)? ZOOM +arrow_forwardPortfolio Instructions: You are working for a financial advisor who creates portfolios of financial securities for his clients. A portfolio is a conglomeration of various financial assets, such as stocks and bonds, that together create a balanced collection of investments. When the financial advisor makes a purchase of securities on behalf of a client, a single transaction can include multiple shares of stock or multiple bonds. It is your job to create an object-oriented application that will allow the financial advisor to maintain the portfolios for his/her clients. You will need to create several classes to maintain this information: Security, Stock, Bond, Portfolio, and Date. The characteristics of stocks and bonds in a portfolio are shown below: Stocks: Bonds: Purchase date (Date) Purchase date (Date) Purchase price (double)…arrow_forward
- True or False ___(1) An abstract class can have fields. ___(2) You can create an object from an abstract class _ _(3) An abstract class can have both abstract methods and methods that have method bodyarrow_forwardA method that returns the value of an object's instance variable is calleda(n)a) mutator b) function c) constructor d) accessorarrow_forwardTrue or False ___(10) You only need to override methods you need in an interface while ignoring other methods that you don’t use. ___(11) In Java the expression instanceof returns a boolean value. ___(12) One of the most important benefit of using inheritance in Java is the reuse of codearrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY