Concept explainers
Javascript Question:
Part 1
Design a Pet object. A Pet is created with a language argument string and a stomach represented by an array. The Pet should support functions: eat() and speak(). Use the prototype property to define your object's interface.
eat(food) will store the passed argument into its stomach and return what it has eaten thus far.
speak(sentence) will simply return the passed in phrase.
function Pet(language) {// create stomach
// set language
}
// takes a food_item STRING and returns everything eaten so far ARRAY
Pet.prototype.eat = function(food_item) {
// ... complete
}
// takes in a sentence STRING and returns the passed in sentence STRING with no change
Pet.prototype.speak = function(sentence) {
// ... complete
}
You may also use the newer class notation.
Part 2
Create an object, Dog, that implements the Pet interface and takes the same argument language.
- Dogs eat the same way all pets do.
- Dogs speak differently. Dogs replace each word in a sentence with its only known language, "woof". For example, if the sentence is "I like bones", the speak() method will turn it into "woof woof woof".
Part 3
Implement at least two test cases to make sure your Dog object is correctly implementing the Pet interface with its own override functions (if applicable). You may use the assert() method. The test code can live in the same file and should create an instance of a Dog object in order to test.
// your code from part 1 and 2var dog = new Dog(...);
// tests here
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps
- do part 4 import java.util.*; // Car classclass Car{ private String name; // Variable to hold car name private String model; // Variable to hold car model // Default constructor Car(){ this.name = null; this.model = null; } // Parametrised constructor Car(String name, String model){ this.name = name; this.model = model; } // Function to get car name public String getName(){ return this.name; }} // Dealer classclass Dealer{ private Car[] arr; // Array holding car objects for a dealer private int count; // Variable to hold number of cars under a dealer // Default constructor Dealer(){ arr = new Car[50]; count=0; } // Function to add a car under a dealer public void addCar(Car obj){ this.arr[this.count] = obj; this.count++; } // Function to check if a car exists under a dealer or not public boolean contains(String name){…arrow_forward/* Interface File: Movie.h Declaration of Movie Class (Variables - "Data Members" or "Attributes" AND Functions - "Member Functions" or "Methods") */ #ifndef MOVIE_H // Include Guard or Header Guard -If already defined ignore rest of code #define MOVIE_H // Otherwise, define MOVIE_H #include<string> // Note: Not "using namespace std;" or even "using std::string" class Movie { private: std::string title = ""; // Explict scope used --> std::string int year = 0; public: Movie(std::string title = "", int year = 1888); // Declaring a Default Constructor ~Movie(); // A Destructor used for freeing up resources void set_title(std::string title_param); std::string get_title() const; // "const" safeguards class variable changes within function std::string get_title_upper() const; void set_year(int year_param); int get_year() const; }; //…arrow_forwardJAVA Programming Problem 3 - Book A Book has such properties as title, author, and numberOfPages. A Volume will have properties such as volumeName, numberOfBooks, and an array of book objects (Book [ ]). You are required to develop the Book and Volume classes, then write an application (DemoVolume) to test your classes. The directions below will give assistance. Create a class called Book with the following properties using appropriate data types: Title, Author, numberOfPages, Create a second class called Volume with the following properties using appropriate data types: volumeName, numberOfBooks and Book [ ]. The Book [ ] contains an array of book objects. Directions Create a class called Book with the following properties using appropriate data types: Title, Author, numberOfPages, The only methods necessary in the Book class, for this exercise, are the constructor and a toString(). Create a second class called Volume with the following properties using appropriate data types:…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