Repository navigation
Expand file tree
/
Copy pathScript.js
More file actions
181 lines (141 loc) · 4.49 KB
/
Copy pathScript.js
File metadata and controls
181 lines (141 loc) · 4.49 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
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
// 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)
//Day-6-Task-1a
//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 Movie {
constructor(title,studio,rating){
this.title=title;
this.studio=studio;
this.rating=rating;
}
}
const obj=new Movie ("mehandi-circus","studio-green","8");
console.log(obj.title,obj.studio,obj.rating);
// Day-6-Task-1b
//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 obj1=new Movie1 ("Leo","7-screen-studio");
console.log(obj1.title,obj1.studio,obj1.rating);
// Day-6-Task-1c
//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 film {
constructor(title,studio,rating="PG"){
this.title=title;
this.studio=studio;
this.rating=rating;
}
static getPG(films){
return films.filter((film)=>film.rating==="PG")
}
}
const films = [
new film ("jaiBhim","2DEntertainment"),
new film ("varanamAayiram","cloud-nine"),
new film ("leo","7 screen studio","8")
]
const PGfilms=film.getPG(films);
console.log (PGfilms);
// Day-6-Task-1d
//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 Movie3 {
constructor(title,studio,rating="PG13"){
this.title=title;
this.studio=studio;
this.rating=rating;
}
}
const obj3=new Movie3 ("Casino Royale","Eon Productions");
console.log(obj3.title,obj3.studio,obj3.rating);
//---------------------------------------------------------------------
//Day-6-Task-2
class Circle {
constructor(radius,color){
this.radius=radius;
this.color=color;
}
get Radius(){
return this.radius
}
set Radius(n){
this.raidus=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 obj4=new Circle("1.0","red");
console.log(obj4.radius);
console.log(obj4.color);
console.log(obj4.toString);
console.log(obj4.area);
console.log(obj4.circumference);
//---------------------------------------------------------------
// Day-6-Task-3
// Write a "person" class to hold all the details
class Person {
constructor(name,age,gender,martialStatus,contact,email,city){
this.name=name;
this.age=age;
this.gender=gender;
this.martialStatus=martialStatus;
this.contact=contact;
this.email=email;
this.city=city;
}
}
const obj5=new Person ("jayadurgha","28","female","married","9019081993","jayadurgha04@gmail.com","ariyalur");
console.log(obj5);
console.log(obj5.name);
console.log(obj5.age);
console.log(obj5.martialStatus);
console.log(obj5.gender);
console.log(obj5.contact);
console.log(obj5.email);
console.log(obj5.city);
//----------------------------------------------------------------------------------
// Day6-Task-4
// Write a class to calculate the Uber Price
class UberPrice {
constructor(distance,price){
this.distance=distance;
this.price=price;
}
get Distance(){
return this.distance
}
set Distance(d){
this.distance=d
}
set Price(n){
this.price=n
}
get Price(){
return this.price
}
get amount(){
return (this.distance*this.price)
}
}
const obj6=new UberPrice (15,50)
console.log(obj6);
console.log(obj6.amount);