Code Monkey home page Code Monkey logo

geektrust-challenge-water-management's Introduction

Water Management - [GeekTrust] - LLD

  • Machine Coding Problem Statement: https://www.geektrust.com/coding/detailed/water-management .

  • This problem was solved on September 10, 2022.

  • The low-level design code reads data input from a file. After reading the input commands, processes them & prints output on the command line interface.

  • This code has earned all the required badges: Object Modelling, Readability, Tests, Correctness, Build.

enter image description here

Statement

You work at WaterBill, a startup developing smart solutions for water management.

GeekHeights community has approached you to use your software to manage their water bills efficiently.

Each GeekHeights apartment is allotted with corporation and borewell water in a specific ratio at the start of the month. There are 2 bedroom and 3 bedroom apartments in the community and it is assumed that they will hold 3 and 5 people respectively.

Each person is allotted 10L of water per day. So a 2 BHK apartment will be allotted 900 L (3*10*30) of water per month and a 3 BHK apartment will be allotted 1500L (5*10*30) of water per month. The total water consumption is then split between corporation and borewell based on a ratio.

If there are additional guests in the apartment, the total allotted water will not suffice and the apartment has to ask for tanker water.

Costs

  1. Corporation Water - Flat rate of Rs. 1 per litre
  2. Borewell Water - Flat rate of Rs. 1.5 per litre
  3. Tanker Water - Slab rate:
    • 0 to 500L - Rs. 2 per litre
    • 501L to 1500L - Rs. 3 per litre
    • 1501 to 3000L - Rs. 5 per litre
    • 3001L+ - Rs. 8 per litre

Input Commands

  1. ALLOT_WATER <apartment-type> <ratio>
    Allots the water from corporation and borewell based on the apartment type and ratio passed. Here the ratio is always of the format Corporation Water : Borewell Water. This command will be executed only once a month per house and also at the start of the input command set.
    Example- ALLOT_WATER 3 1:5
  2. ADD_GUESTS <no_of_guests>
    Adds the number of guests to a house. ADD_GUESTS command can be given multiple times in a month and total guests is the sum of all ADD_GUESTS numbers for that month.
    Example - ADD_GUESTS 10
  3. BILL
    Prints the total water consumed in litres and the total cost, after cumulatively adding up all the guests cost to the bill. This command will be executed only once and at the end of the input set.
    It should print the total water consumption and the cost in the format
    <TOTAL_WATER_CONSUMED_IN_LITERS> <TOTAL_COST>
    Example - BILL
    4500 13625

Assumptions

  1. All the calculations are done for a single apartment in a month. Number of days in the month is assumed to be 30.
  2. The water consumption is measured in litres.
  3. All calculations should be rounded off to the nearest integer. No decimal values are used.
  4. Allotment based on ratio is done only once at the start of the month.
  5. Guests can be added a multiple number of times.
  6. The command BILL can be executed only once, which is at the end of the month. It should be a part of the input set.

Pre-requisites

  • Java 1.8/1.11/1.15
  • Gradle 6

How to run the code

We have provided scripts to execute the code.

Use run.sh if you are Linux/Unix/macOS Operating systems and run.bat if you are on Windows.

Internally both the scripts run the following commands

  • gradle clean build -x test --no-daemon - This will create a jar file geektrust.jar in the build/libs folder.
  • java -jar build/libs/geektrust.jar sample_input/input1.txt - This will execute the jar file passing in the sample input file as the command line argument

Use the build.gradle file provided along with this project. Please change the main class entry under the jar task

manifest {
       attributes 'Main-Class' : 'com.geektrust.backend.App' //Change this to the main class of your program which will be executed
   }

in the build.gradle if your main class has changed.

How to execute the unit tests

gradle clean test --no-daemon will execute the unit test cases.

Help

You can refer our help documents here You can read build instructions here

geektrust-challenge-water-management's People

Contributors

axitchandora avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.