Table of Contents:
- Assessment Overview
- Section 1: Short Response
- Section 2: Class Implementation
- Section 3: System Design
Welcome to your Object-Oriented Programming assessment! This assessment tests your understanding of classes, encapsulation, inheritance, polymorphism, and system design.
The assessment has 3 sections:
- Short Response - Answer questions about JavaScript concepts
- Class Implementation - Implement JavaScript classes that satisfy the given requirements.
- System Design - Design a system and create a UML diagram that reflects it
Your repository contains the following relevant files:
swe-assessment-2-oop/
├── README.md # This file - your instructions
├── rubric.md # The grading rubric for this assessment
└── src/
├── short-response.md # Section 1: Answer questions here
├── phone.js # Section 2: Problem 3 - Implement Phone and IPhone
├── bank.js # Section 2: Problem 1 - Debug Bank and BankAccount
├── pokemon.js # Section 2: Problem 2 - Implement Pokemon
└── system-design.md # Section 3: Include a link to your design and your Loom recording
Clone the Repository
git clone <repository-url>
cd swe-assessment-2-oopSwitch to a draft branch
git checkout -B draftInstall Dependencies
npm installPrior to submitting your work, run the "linter" which will inform you of any code style issues in your code.
Check for linting errors:
npm run lintBefore submitting your assessment, go through this checklist to ensure you haven't missed any critical details!
Submission Checklist:
- All questions in
src/short-response.mdare answered - All classes in
src/bank.js,src/pokemon.js, andsrc/phone.jsare implemented - All links in
src/system-design.mdare provided - Short responses have been proofread and cleared of any typos or grammar mistakes.
- Run
npm run lint- fix any errors - Remove any
console.logstatements used for debugging - Remove any commented-out code
How to Submit:
-
Run the linter:
npm run lint
And fix any issues.
-
Commit your changes:
git add -A git commit -m "Completed assessment" -
Push to GitHub:
git push
-
Create a pull request to merge
draftintomainand tag your instructor for review. -
Submit on Canvas:
- Double-check that your latest code is visible on the
draftbranch in GitHub - Submit the link to your pull request on Canvas
- Double-check that your latest code is visible on the
Allowed Resources:
- ✅ MDN Documentation
- ✅ Your notes from class
- ✅ Previous assignments and labs
- ✅ Running code in Node to test ideas
NOT Allowed:
- ❌ AI tools (ChatGPT, Claude, Copilot, etc.)
- ❌ Asking classmates for help
- ❌ Searching for solutions online
- ❌ Posting questions on Stack Overflow, Reddit, etc.
If You're Stuck:
- Read the error messages carefully
- Use
console.log()to debug your code - Take a break and come back with fresh eyes
- Remember: struggling is part of learning!
Q: Can I use AI tools to check my code?
A: No, you may not. You are allowed to use official documentation (e.g. MDN), your notes, and our course GitBook for this exam. You may also use StackOverflow. However, you may not use LLMs, such as ChatGPT or Claude to support you on this exam.
Q: Can I use AI tools to check my writing?
A: You may use Grammarly to proofread your writing to ensure that it is grammar-error and typo-free.
Q: What if I don't finish in 6 hours? A: You can request a 1-day extension. Speak with an instructor.
Q: Is there partial credit? A: Yes! Partial credit is awarded based on the rubric. Do your best!
Q: Can I use Google? A: You can use MDN and official documentation, but don't search for solutions to the specific problems. Feel free to use the Marcy GitBook, your own notes, and past assignments.
Q: What if my video is over the time? A: A few seconds over is fine. Just avoid excessive rambling.
Q: Can I resubmit if I'm not happy with my score? A: Talk to your instructor about retake options.
Remember:
- Read all instructions carefully before starting
- Don't spend too much time on one question - move on and come back
- Save your work frequently (
git commitregularly) - Test your code as you write it
If you have questions about the instructions (not the content), ask an instructor.
In your own words, explain what does encapsulation refer to? Why is this concept beneficial when programming?
Provide a code snippet to illustrate encapsulation.
Explain what the this keyword is. Why is the this keyword useful?
In the code snippet below, what does this refer to?
class Counter {
constructor() {
this.count = 0;
}
increment() {
this.count++;
}
}
const counterA = new Counter();
const counterB = new Counter();
counterA.increment();
counterA.increment();
counterA.increment();
counterB.increment();
console.log(counterA.count);
console.log(counterB.count);In your own words, explain what polymorphism means in OOP. Provide an example in code that demonstrates polymorphism.
You're building a game where players can raise different digital pets: Cats, Dogs, and Birds. All pets have have a name, energy level, and happiness level and can all sleep. Cats have the ability to hunt, dogs have the ability to chase, and birds have the ability to fly.
Part A: Describe in words how you would use inheritance to organize these classes.
Part B: Explain one advantage of using inheritance here instead of creating three completely separate classes.
For these problems, there will not be any provided tests. You must implement your code to the best of your ability. We've provided example usage that you can use to manually test your code.
Instructions: The UML Diagram below was handed off to an AI Coding Agent to implement:
Remember the rules for UML Diagrams:
+indicates a public property/method-indicates a private property/method- Underline indicates a
staticproperty/method
As a result, the AI Coding Agent produced the file src/bank.js. It is your task to:
- Analyze the code and verify that it works as expected.
- Comment out any broken code.
- Implement fixes.
Here is some sample test code with comments indicating expected output. You can use this directly in the src/bank.js file
const account1 = new BankAccount("001", "Alice");
const account2 = new BankAccount("002", "Bob");
console.log(account1); // BankAccount { accountNumber: "001", ownerName: "Alice" }
console.log(account2); // BankAccount { accountNumber: "002", ownerName: "Bob" }
console.log(account1.getBalance()); // 0
account1.deposit(100); // Prints "Deposited $100. New Balance: 100"
account1.withdraw(50); // Prints "Withdrew $50. New Balance: 50"
account1.withdraw(1000); // Prints "Withdrawal failed. Insufficient funds."
console.log(account1.getBalance()); // 50
new BankAccount("003", "Charlie");
console.log("Total accounts:", BankAccount.getTotalAccounts()); // 3
const myBank = new Bank("First National");
console.log(myBank); // Bank { name: "First National" }
myBank.addAccount(account1);
myBank.addAccount(account2);
console.log(myBank.accounts);
/*
[
BankAccount { accountNumber: "001", ownerName: "Alice" },
BankAccount { accountNumber: "002", ownerName: "Bob" }
]
*/
account2.deposit(250); // Prints "Deposited $250. New Balance: 250"
console.log(myBank.getTotalBalance()); // 300
console.log(myBank.findAccount("001").ownerName); // "Alice"Run the file with
node src/bank.jsInstructions: In the src/pokemon.js file, create a Pokemon class with the following specifications:
- Instance Properties:
name(String, public, set by the constructor)type(String, public, set by the constructor)health(Number, private, starting value of100)level(Number, private, starting value of1)
- Instance Methods:
- "Getter" methods for the
healthandlevelprivate fields. Bonus points if you use thegetsyntax! (get MDN documentation) levelUp()- increaseslevelby1and increaseshealthby10. Then print"{name} leveled up to level {level}!".isFainted()- returnstrueifhealthis0or below,falseotherwise.attack(targetPokemon)- reduces the target Pokemon'shealthby an amount equal to10times the attacking Pokemon'slevel. Then print"{name} attacked {target.name}!".
- "Getter" methods for the
- Static Properties
allPokemon(array tracking all created Pokemon)
- Static Methods
getTotalPokemon()- returns count of all Pokemon createdfindByName(name)- searches theallPokemonarray and returns matching Pokemon
Test your code with following example usage:
const charizard = new Pokemon("Charizard", "Fire");
const squirtle = new Pokemon("Squirtle", "Water");
// 1. Checking instance properties
console.log(charizard); // Pokemon { name: "Charizard", type: "Fire" }
console.log(squirtle); // Pokemon { name: "Squirtle", type: "Water" }
// 2. Leveling up a Pokemon
squirtle.levelUp(); // Squirtle leveled up to level 2!
squirtle.levelUp(); // Squirtle leveled up to level 3!
squirtle.levelUp(); // Squirtle leveled up to level 4!
// 3. Checking the level
console.log(squirtle.getLevel()); // 4
// OR if you use the get syntax
console.log(squirtle.level); // 4
// 4. Checking on health
console.log(squirtle.getHealth()); // Should be 130 (100 + 10*3 from leveling up)
// OR if you use the get syntax
console.log(squirtle.health); // Should be 130 (100 + 10*3 from leveling up)
// 5. Attacking until one faints
while (!charizard.isFainted()) {
squirtle.attack(charizard); // Prints "Squirtle attacked Charizard!"
}
console.log("Charizard has fainted!");
console.log(charizard.isFainted()); // true
// 6. Finding a Pokemon instance
console.log(Pokemon.findByName("Charizard")); // Pokemon { name: "Charizard", type: "Fire" }
// 7. Viewing count of all Pokemon
console.log("Total Pokemon:", Pokemon.getTotalPokemon()); // 2Instructions: In the src/phone.js file, demonstrate inheritance by creating a Phone and IPhone class.
Create a Phone class with the following:
- Instance Properties:
brand(String, public, set by the constructor)model(String, public, set by the constructor)password(String, private, set by the constructor)batteryLevel(Number, public, starting value of100)
- Instance Methods:
makeCall(number)- decreases battery by5, returns"Calling {number}"charge()- sets battery back to100, returns"Phone fully charged"unlock(password)- returnstrueif the provided password matches the private password. Otherwise returnsfalse.
Test your code with following example usage:
const flipPhone = new Phone("Nokia", "Flip", "TimeToLearn882");
console.log(flipPhone); // Phone { brand: "Nokia", model: "Flip", batteryLevel: 100 }
// 1. Making a call and checking battery
console.log(flipPhone.makeCall("123-456-7890")); // Calling 123-456-7890
console.log(flipPhone.batteryLevel); // 95
// 2. Charging and checking battery
console.log(flipPhone.charge()); // Phone fully charged
console.log(flipPhone.batteryLevel); // 100
// 3. Unlocking the phone
console.log(flipPhone.unlock("TimeToLearn882")); // true
console.log(flipPhone.unlock("wrongpassword")); // falseCreate a IPhone class with the following:
- Is a subclass of the
Phoneclass - The
brandshould always be set to"Apple" - One additional property:
numberOfCameras(Number, public, set by the constructor) - Override
makeCall(number)to return"Calling {number} using FaceTime audio" - New method:
faceTime(name)- decreasesbatteryLevelby 10, returns"Facetiming {name}"
Test your code with following example usage:
const smartPhone = new IPhone("IPhone 14 Pro", "TimeToLearn882", 3);
console.log(smartPhone); // IPhone { brand: "Apple", model: "IPhone 14 Pro", numberOfCameras: 3, batteryLevel: 100}
// 1. Making a call
console.log(smartPhone.makeCall("555-1234")); // Calling 555-1234 using FaceTime audio
console.log(smartPhone.batteryLevel); // Should be 95
// 2. Using the faceTime method
console.log(smartPhone.faceTime("Alice")); // Facetiming Alice
console.log(smartPhone.batteryLevel); // Should be 85
// 3. Charge the phone
console.log(smartPhone.charge()); // Phone fully charged
console.log(smartPhone.batteryLevel); // Should be 100
// 4. Unlock the phone
console.log(smartPhone.unlock("0000")); // false
console.log(smartPhone.unlock("TimeToLearn882")); // trueThis section is meant to simulate an interview (and your upcoming assessment) so aim to spend approximately 2 hours on it total, and up to 3 hours if you must.
- 20-30 min: Understanding requirements and sketching initial design
- 30-40 min: Creating the UML diagram in LucidChart
- 20-30 min: Writing bullet points for explanation
- 15-20 min: Recording and reviewing the Loom
Your goal should be to hone your intuition around good system design and this time constraint will force you to make decisions.
Scenario: You are tasked with designing an online restaurant ordering system. Your system design should capture the essential entities (classes), the responsibilities of those entities (properties/methods), and the relationships between them.
We recommend that you take notes as you create your system in the system-design.md file and use pen and paper to draw an initial sketch of your design.
System Requirements:
- Your system should be able to handle the following functionality:
- A restaurant can manage the items in their menu
- A customer can place an order with items from the restaurant's menu
- An order can be marked as "pending", "in progress", "picked up", or "delivered"
- Your system must include at least three classes that are connected by relationships (associations), with at least one one-to-many relationship.
Constraints:
- Restaurants in this system are assumed to be pickup or delivery. No dining-in.
Explanation Topics: When you record your explanation, you will be asked to explain:
- How your system handles each of the system functionality requirements above:
- Why you chose the specific relationships and class responsibilities.
- At least one significant design decision you made and what alternatives or trade-offs you considered to arrive at your final design.
- Examples of significant decisions: where to store your data, how your system handles order status, which class is responsible for X, Y, or Z.
As you approach finalizing your design, transition to LucidChart to create your UML diagram.
When you are done, click Share in the top right corner, turn on the Shareable link and then paste the link in the src/system-design.md file.
UML Requirements: Your UML Diagram must have the following:
-
Model relationships using arrows and appropriate multiplicity notation:
- Exactly one:
1(e.g. an adoption application has exactly 1 Pet) - Zero or more (many):
0..*(e.g. a shelter has 0 or more pets)
- Exactly one:
-
Annotate relationships with association labels to describe each relationship
- Example: "Shelter --creates many--> Applications"
- Example: "Application --references one--> Adopter"
-
Include detailed class definitions with:
- Properties (attributes) and their data types (e.g.
name: String) - Methods (behaviors) and their named parameters (e.g.
findPetById(id))
- Properties (attributes) and their data types (e.g.
-
Use Loom to record your screen. For instructions on downloading Loom, refer to the Marcy GitBook.
-
In your video, you must explain the Explanation Topics listed in part 1.
-
Prior to recording, we highly recommend that you write out the key points of your explanation in bullets in the
src/system-design.mdfile. -
Be specific and use proper technical vocabulary:
✅ Good Example 🚫 Bad Example "instance property" or "instance method" "variable" or "function" "Pet status is updated by invoking setStatus()" "A Pet changes status" "A shelter houses many pets" "pets are in a shelter" "A donor submits an application by invoking shelter.createApplication()" "An application is created" -
Keep your video concise (roughly between 5-7 minutes)
-
Upload your video and add the link to the comment at the top of
src/system-design.md
