Skip to content

Commit a3707dd

Browse files
committed
Studio done
1 parent 5e57861 commit a3707dd

File tree

1 file changed

+72
-32
lines changed

1 file changed

+72
-32
lines changed

classes/studio/ClassStudio.js

Lines changed: 72 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,80 @@
1-
//Declare a class called CrewCandidate with a constructor that takes three parameters—name, mass, and scores. Note that scores will be an array of test results.
2-
31
class CrewCandidate {
42
constructor(name, mass, scores) {
5-
this.name = name;
6-
this.mass = mass;
7-
this.scores = scores;
3+
this.name = name;
4+
this.mass = mass;
5+
this.scores = scores;
86
}
9-
}
10-
11-
const bear = new CrewCandidate("Bubba Bear", 135, [88, 85, 90]);
12-
const maltese = new CrewCandidate("Merry Maltese", 1.5, [93, 88, 97]);
13-
const gator = new CrewCandidate("Glad Gator", 225, [75, 78, 62]);
14-
15-
console.log(bear);
16-
console.log(maltese);
17-
console.log(gator);
18-
197

8+
addScore(newScore) {
9+
this.scores.push(newScore);
10+
}
2011

21-
//Add methods for adding scores, averaging scores and determining candidate status as described in the studio activity.
12+
calculateAverageScore() {
13+
if (this.scores.length === 0) {
14+
return 0;
15+
}
16+
const total = this.scores.reduce((sum, score) => sum + score, 0);
17+
return total / this.scores.length;
18+
}
2219

23-
class CrewCandidate {
24-
constructor(name, mass, scores) {
25-
this.name = name;
26-
this.mass = mass;
27-
this.scores = scores;
20+
shouldAdmit() {
21+
const averageScore = this.calculateAverageScore();
22+
return averageScore >= 90;
2823
}
29-
30-
addScore(newScore) {
31-
this.scores.push(newScore);
24+
25+
status() {
26+
const averageScore = this.calculateAverageScore();
27+
28+
if (averageScore >= 90) {
29+
return "Accepted";
30+
} else if (averageScore >= 80) {
31+
return "Reserve";
32+
} else if (averageScore >= 70) {
33+
return "Probationary";
34+
} else {
35+
return "Rejected";
36+
}
3237
}
33-
}
34-
35-
bear.addScore(83);
36-
37-
console.log("Bubba's Scores:", bear.scores);
38-
39-
40-
//Part 4 - Use the methods to boost Glad Gator’s status to Reserve or higher. How many tests will it take to reach Reserve status? How many to reach Accepted? Remember, scores cannot exceed 100%.
38+
}
39+
40+
// Create objects for the candidates
41+
const bubbaBear = new CrewCandidate("Bubba Bear", 135, [88, 85, 90]);
42+
const merryMaltese = new CrewCandidate("Merry Maltese", 1.5, [93, 88, 97]);
43+
const gladGator = new CrewCandidate("Glad Gator", 225, [75, 78, 62]);
44+
45+
// Add scores to candidates' records
46+
bubbaBear.addScore(83);
47+
merryMaltese.addScore(95);
48+
gladGator.addScore(80);
49+
50+
// Get the status for each candidate
51+
const bubbaBearStatus = bubbaBear.status();
52+
const merryMalteseStatus = merryMaltese.status();
53+
const gladGatorStatus = gladGator.status();
54+
55+
console.log(`${bubbaBear.name} earned an average test score of ${bubbaBear.calculateAverageScore()}% and has a status of ${bubbaBearStatus}.`);
56+
console.log(`${merryMaltese.name} earned an average test score of ${merryMaltese.calculateAverageScore()}% and has a status of ${merryMalteseStatus}.`);
57+
console.log(`${gladGator.name} earned an average test score of ${gladGator.calculateAverageScore()}% and has a status of ${gladGatorStatus}.`);
58+
59+
// Reset Glad Gator's scores for the test
60+
gladGator.scores = [75, 78, 62];
61+
62+
// Define the target status
63+
const targetStatus = "Accepted";
64+
65+
let testsTaken = 0;
66+
67+
while (gladGator.status() !== targetStatus) {
68+
// Increment the test score by 5 (or any other increment you prefer)
69+
const newScore = gladGator.scores[testsTaken % 3] + 5;
70+
71+
// Ensure the score doesn't exceed 100
72+
if (newScore <= 100) {
73+
gladGator.scores[testsTaken % 3] = newScore;
74+
testsTaken++;
75+
} else {
76+
break; // Break the loop if the score cannot be increased further
77+
}
78+
}
79+
80+
console.log(`Glad Gator reached ${targetStatus} status after taking ${testsTaken} tests.`);

0 commit comments

Comments
 (0)