Skip to content

aaradhanas/design-exercise

Repository files navigation

Problem 1

A very prestigious chain of hotels is facing a problem of huge consumption of electricity bills for its electronic equipments. The common equipments, like lights, ACs, etc are currently controlled manually, by the hotel staff, using manual switches. Hotel Management wants to optimise the usage of electricity consumption and also ensure that there is no inconvenience caused to the guests and staff. So, it has installed Motion Sensors at appropriate places and have approached you to program a Controller which takes inputs from these sensors and controls various equipments.

The way the hotel equipments are organised and the requirements for the Controller are listed below:

A Hotel can have multiple floors

  • Each floor can have multiple main corridors and sub corridors
  • Both main corridor and sub corridor have one light each
  • Both main and sub corridor lights consume 5 units of power when ON
  • Both main and sub corridor have independently controllable ACs
  • Both main and sub corridor ACs consume 10 units of power when ON
  • All the lights in all the main corridors need to be switched ON between 6PM to 6AM, which is the Night Time slot
  • By default, all ACs are switched ON, all the time
  • When a motion is detected in one of the sub corridors the corresponding lights need to be switched ON between 6PM to 6AM (Night Time slot)
  • The total power consumption of all the ACs and lights combined should not exceed (Number of Main corridors * 15) + (Number of sub corridors * 10) units of per floor. Sub corridor AC could be switched OFF to ensure that the power consumption is not more than the specified maximum value
  • When there is no motion for more than a minute the sub corridor lights should be switched OFF and AC needs to be switched ON

Motion in sub-corridors is input to the controller, which needs to keep track and optimise the power consumption. Write a program that takes input values for Floors, Main corridors, Sub corridors and takes different external inputs for motion in sub corridors. For each input, the program prints out the state of all the lights and ACs in the hotel. For simplicity, assume that the controller is operating at the Night Time.

Problem 2

A simple calculator application written using Test Driven Development (TDD) approach. This application supports the following 4 operations:

  • Addition
  • Subtraction
  • Multiplication
  • Division

Developing an application using TDD helped me to think of all the positive, negative and edge cases while writing tests. I followed the basic principles of TDD as follows:

  1. Write a unit test.
  2. Make it fail (Either compilation error or functional error).
  3. Write code to make the test pass.
  4. Repeat steps 1 to 3. Refactor your code during this process.

JaCoCo has been used for code coverage.

JavaScript Concepts

'javascript-concepts' folder contains code samples for basic JS concepts

About

Exercises of design problems

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published