class Person {
constructor(name, email, phone) {
this.name = name;
this.email = email;
this.phone = phone;
}
greet(otherPerson) {
console.log("Hello " + otherPerson.name + ", I am " + this.name + "!");
}
}Write code to
- Instantiate an instance object of
Personwith name of 'Sonny', email of 'sonny@hotmail.com', and phone of '483-485-4948', store it in the variablesonny - Instantiate another person with the name of 'Jordan', email of 'jordan@aol.com', and phone of '495-586-3456', store it in the variable
jordan - Add a method
printContactInformation()which prints person contact information - Have
sonnygreetjordanusing thegreetmethod and print contact information afterwards - Have
jordangreetsonnyusing thegreetmethod and print contact information afterwards
Create a class Product that represents a product sold in a shop.
A product has a price, amount and name.
The class should have:
- A constructor public Product(name, priceAtStart, amountAtStart)
- A method
printProduct()that prints a product in the following form:
Banana, price 1.1, amount 13
Test your code by running your code and adding three products:
- "Logitech mouse", 70.00 EUR, 14 units
- "iPhone 5s", 999.99 EUR, 3 units
- "Epson EB-U05", 440.46 EUR, 1 units
Print out information about them.
Add new behaviour to the Product class:
- possibility to change quantity
- possibility to change price
Reflect your changes in a working application.
Create a class called DateTime, class constructors accepts UNIX timestamp in seconds.
Class must have:
getYear,getMonth,getDate,getHours,getMinutes,getSecondsmethodsprettyPrintmethod which prints time in format of2020-01-30 11:59:59
Create an object that represents a cat. It should have properties for tiredness, hunger, lonliness and happiness
Next, write methods that increase and decrease those properties. Call them something that actually represents what would increase or decrease these things, like "feed", "sleep", or "pet".
Last, write a method that prints out the cat's status in each area. (Be creative e.g. Paws is really hungry, Paws is VERY happy.)
Bonus: Make the functions take arguments that increase or decrease arbitrary amounts
Bonus: Make the functions as arbitrary as cats are - sometimes make it so the cat doesn't want to be petted.
The class Movie is stated below. An instance of class Movie represents a film.
This class has the following three class variables:
title, which is a string representing the title of the moviestudio, which is a string representing the studio that made the movierating, which is a string representing the rating of the movie (i.e. PG13, R, etc)
- Write a constructor for the class
Movie, which takes the title of the movie, studio, and rating as its arguments, and sets the respective class variables to these values. - Write a method
getPG(), which takes an array of base type Movie as its argument, and returns a new array of only those movies in the input array with a rating of "PG". You may assume the input array is full of Movie instances. The returned array may be empty. - Write a piece of code that creates an instance of the class
Movie:- with the title “Casino Royale”, the studio “Eon Productions” and the rating “PG13”;
- with the title “Glass”, the studio “Buena Vista International” and the rating “PG13”;
- with the title “Spider-Man: Into the Spider-Verse”, the studio “Columbia Pictures” and the rating “PG”.