-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
227 lines (215 loc) · 5.77 KB
/
script.js
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
//Day 6 Tasks
/*
// Task 1
/* 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.
*/
console.log("TASK - 1");
console.log("----------------X--------------X---------------");
console.log("Task 1 a)- creating a constructor for the class Movie");
class Movie {
constructor(title, studio, rating) {
this.title = title;
this.studio = studio;
this.rating = rating;
}
}
const a = new Movie("Vikram", "RKFS", "8.5");
console.log(a.title, a.studio, a.rating);
console.log("----------------X--------------X---------------");
//Task 1
/* b) The constructor for the class Movie will set
the class property rating to "PG"
as default when no rating is provided.
*/
console.log("Task 1 b)- class property rating to 'PG' as default");
class Movie1 {
constructor(title, studio, rating = "PG") {
this.title = title;
this.studio = studio;
this.rating = rating;
}
}
const b = new Movie1(
"Harry Potter and the Sorcerer's Stone (2001)",
"Warner Bros."
);
console.log(b.title, b.studio, b.rating);
console.log("----------------X--------------X---------------");
//task 1
/* 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.
*/
console.log("Task 1 c)- method getPG with a rating of 'PG' ");
class Movie2 {
constructor(title, studio, rating = "PG") {
this.title = title;
this.studio = studio;
this.rating = rating;
}
static getPG(movies) {
return movies.filter((movie) => movie.rating === "PG");
}
}
// Create an array of Movie instances
const movies = [
new Movie2("Movie1", "Studio1", "PG"),
new Movie2("Movie2", "Studio2", "PG-13"),
new Movie2("Movie3", "Studio3", "PG"),
new Movie2("Movie4", "Studio4", "R"),
new Movie2("Movie5", "Studio5", "PG"),
];
Movie2.getPG(movies).forEach((movie) => console.log(movie.title));
console.log("----------------X--------------X---------------");
/*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”
*/
console.log(
"Task 1 d)- class Movie with the title “Casino Royale”, the studio “Eon Productions”, and the rating PG13"
);
class Movie3 {
constructor(title, studio, rating) {
this.title = title;
this.studio = studio;
this.rating = rating;
}
}
const c = new Movie3("Casino Royale", "Eon Productions", "PG13");
console.log(c.title, c.studio, c.rating);
console.log("----------------X--------------X---------------");
//Task 2
console.log("TASK - 2 -->Circle - Class");
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;
}
}
const circle = new Circle(1.2, "red");
console.log(circle.radius, circle.color);
console.log(circle.color);
console.log(circle.toString);
console.log(`Circle Radius - ${circle.area}`);
console.log(`Circle Circumfernce - ${circle.circumference}`);
circle.Radius = "5";
console.log(circle.radius);
circle.Color = "White";
console.log(circle.color);
console.log(circle.toString);
console.log("----------------X--------------X---------------");
//Task 3-->Write a “person” class to hold all the detail
console.log("Task - 3-->Person deatils in a class");
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 obj = new Person(
"Praveen",
22,
"Male",
"No",
1234567890,
);
console.log(
` Name - ${obj.name},
Age - ${obj.age},
Gender - ${obj.gender},
Marital Status - ${obj.maritalstatus},
Contact - ${obj.contact},
E-Mail - ${obj.email}
`
);
console.log("----------------X--------------X---------------");
// Task -4 --> write a class to calculate the Uber price.
console.log("Task - 4 --> write a class to calculate the Uber price.");
class Uber {
constructor(Price, Kms) {
this.Price = Price;
this.distance = Kms;
}
set price(p) {
this.Price = p;
}
get price() {
return this.Price;
}
set calculate(distance) {
this.distance = distance;
}
get calculate() {
return this.distance * this.Price;
}
}
const uber = new Uber();
uber.calculate = 20;
uber.price = 7;
console.log(
` Price = ${uber.price} Rupees , Kilometer = ${uber.distance} kms `
);
console.log(`Total Price = ${uber.calculate}`);
// //Session Task
// class car {
// constructor(companyname, model, milage, color, price, safety, type, section) {
// this.companyname = companyname;
// this.model = model;
// this.milage = milage;
// this.color = color;
// this.price = price;
// this.safety = safety;
// this.type = type;
// this.section = section;
// }
// }
// const obj1 = new car(
// "BMW",
// "x5",
// "10 KM/lit",
// "Black",
// "80Lakhs",
// "4.5 Star",
// "Hybird-(Electric/Petrol)",
// "Sedan"
// );
// console.log(
// obj1.companyname,
// obj1.model,
// obj1.milage,
// obj1.color,
// obj1.price,
// obj1.safety,
// obj1.type,
// obj1.section
// );