-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
141 lines (123 loc) · 4.03 KB
/
script.js
File metadata and controls
141 lines (123 loc) · 4.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
//TASK 1:
//The class Movie is stated below. An instance of class Movie represents a film.
// This class has the following three properties:
//title, which is a String representing the title of the movie
//studio, which is a String representing the studio that made the movie
//rating, which is a String representing the rating of the movie (i.e. PG13, R, etc)
//a) Write a constructor for the class Movie, which takes a String representing the title of the movie,
//a String representing the studio, and a String representing the rating as its arguments, and sets the
//respective class properties to these values.
class Movies{
constructor(title,studio,rating){
this.title=title;
this.studio=studio;
this.rating=rating;
}
}
const property=new Movies("Jailer","Sun pictures","7.1");
console.log(property.title,property.studio,property.rating);
//b) The constructor for the class Movie will set the class property rating
//to "PG" as default when no rating is provided.
class Movie1{
constructor(title,studio,rating="PG"){
this.title=title;
this.studio=studio;
this.rating=rating;
}
}
const property1=new Movie1("Jailer","Sun pictures",);
console.log(property1.title,property1.studio,property1.rating);
//c) 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 need not be full.
class Movies1{
constructor(title,studio,rating="PG"){
this.title=title;
this.studio=studio;
this.rating=rating;
}
}
const property2=[new Movies1("Jailer","Sun pictures","7.1"),new Movies1("vikram","raj kamal"),
new Movies1("leo","seven screen","7.2"),new Movies1("jeo","vision cinema house")]
const result=property2.filter((ele)=>ele!==this.rating)
console.log(result)
//d) 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”
class Movie{
constructor(title,studio,rating){
this.title=title;
this.studio=studio;
this.rating=rating;
}
}
const Production=new Movie("Casino Royale","Eon Productions","PG13");
console.log(Production.title,Production.studio,Production.rating);
//TASK 2:-
//Convert the UML diagram to Typescript class. - use number for double
class Circle {
constructor(radius, color) {
this.radius = radius;
this.color = color;
}
get Radius() {
return this.radius;
}
set Radius(n) {
this.radius = n;
}
get Color() {
return this.color;
}
set Color(c) {
this.color = c;
}
get toString() {
return `"Circle[radius=${this.radius},color=${this.color}]"`;
}
get Area() {
return Math.PI * Math.pow(this.radius, 2);
}
get Circumference() {
return 2 * Math.PI * this.radius;
}
}
let Circle1 = new Circle(1.0, "red");
console.log(Circle1.radius);
console.log(Circle1.color,Circle1.radius);
console.log(Circle1.Radius);
console.log(Circle1.Color);
console.log(Circle1.toString);
console.log(Circle1.Area);
console.log(Circle1.Circumference);
//TASK 3:-
//Write a “person” class to hold all the details.
class Person{
constructor(name,age,gender,maritalstatus,contact,email){
this.name=name;
this.age=age;
this.gender=gender;
this.maritalstatus=maritalstatus;
this.contact=contact;
this.email=email;
}
}
const data=new Person("Mathi","22","Female","single",9876543210,"mathikk06@gmail.com");
console.log(data.name,data.age,data.gender,data.maritalstatus,data.contact,data.email);
//TASK 4:-
//write a class to calculate the Uber price.
class Uberprice{
constructor(kilometer,price){
this.kilometer=kilometer
this.price=price
}
set Price(n){
this.price=n
}
get Price(){
return this.price*this.kilometer
}
}
let Uber=new Uberprice(1,50)
console.log(Uber.kilometer,Uber.price);
Uber.kilometer=20
console.log(Uber.Price);