patternjavaMinor
Computing the electricity consumption of a client
Viewed 0 times
theelectricityclientconsumptioncomputing
Problem
I have a year or so of experience in developing in Java. I submitted the solution for this task, but never got the feedback that was promised. Since I still would like to get a feedback on my solution, I figured that here I will find skilled developers who wish to help me and others who may have similar questions.
Compute electricity day- and night- consumption of a client. Given
client's per-hour electricity consumption for some month. Goal is to
compute total day- and night- consumption. Hours are enumerated from 1
starting from beginning of month. Day hours are 7-23 at working days
(8-24 at daylight saving time or summer). All other hours are night
hours. Example for January 2012:
In this case, night consumption is 8 = 2+3+3 and day consumption is 6.
` /**
* Used for calculating day and night tariff energy consumption for one month. Takes into account the start and end time changes of
* the day and night tariff because of the day light saving time period.
* This constructor uses Estonian time zone and 7-23 as day hours and 8-24 as day hours at daylight saving time.
*
* @param consumptionData One month's consumption data for each hour. Each hour - consumption pair has to be on a separate line.
* Syntax: First the hour value, second, the separator: ' - ' and then the amount.
* Hours have to be integers, and start from 1. Lines with non-integer hour values are disregarded.
* Amount has to be a number value. Non-numbers are considered as zero value.
* For example, if one line of data is '1 - 2.5kW', then th
Compute electricity day- and night- consumption of a client. Given
client's per-hour electricity consumption for some month. Goal is to
compute total day- and night- consumption. Hours are enumerated from 1
starting from beginning of month. Day hours are 7-23 at working days
(8-24 at daylight saving time or summer). All other hours are night
hours. Example for January 2012:
1 - 2kW (hour #1 is January 1, Sunday, 00:00 - 01:00 - NIGHT)
2 - 3kW (hour #2 is January 1, Sunday, 01:00 - 02:00 - NIGHT)
26 - 3kW (hour #26 is January 2, Monday, 01:00 - 02:00 - NIGHT)
32 - 6kW (hour #32 is January 2, Monday, 07:00 - 08:00 - DAY)
...
744 - 0kW (hour #744 is January 31, 23:00 - 24:00)
In this case, night consumption is 8 = 2+3+3 and day consumption is 6.
` /**
* Used for calculating day and night tariff energy consumption for one month. Takes into account the start and end time changes of
* the day and night tariff because of the day light saving time period.
* This constructor uses Estonian time zone and 7-23 as day hours and 8-24 as day hours at daylight saving time.
*
* @param consumptionData One month's consumption data for each hour. Each hour - consumption pair has to be on a separate line.
* Syntax: First the hour value, second, the separator: ' - ' and then the amount.
* Hours have to be integers, and start from 1. Lines with non-integer hour values are disregarded.
* Amount has to be a number value. Non-numbers are considered as zero value.
* For example, if one line of data is '1 - 2.5kW', then th
Solution
the first thing that I noticed is that your functions do not describe an action, they are missing a verb. So when a reader comes to the function "MonthConsumption()" he has to read your comment to find out if the function calculates a mont consumption or .. or .. or consumes a month :-)
I like that you name your methos quite explicit, for my taste they are a bit too long. Good thing: in case of the @Test you exactly know the conditions for this test. But i would suggest giving shorter names.
Regarding to your comments: in "Clean Code" (by Robert C Martin) it is said that comments should not be neccessary to understand a code. However, I think comments are often neccesary to describe something in the real world.
The second function has a lot of parameters. I would suggest going for a object-based concept to avoid too much function parameters.
It is obvious that you worked and thought a lot on this example. Keep on, stay interested, a good progammer always learns :-)
I like that you name your methos quite explicit, for my taste they are a bit too long. Good thing: in case of the @Test you exactly know the conditions for this test. But i would suggest giving shorter names.
Regarding to your comments: in "Clean Code" (by Robert C Martin) it is said that comments should not be neccessary to understand a code. However, I think comments are often neccesary to describe something in the real world.
The second function has a lot of parameters. I would suggest going for a object-based concept to avoid too much function parameters.
It is obvious that you worked and thought a lot on this example. Keep on, stay interested, a good progammer always learns :-)
Context
StackExchange Code Review Q#38762, answer score: 4
Revisions (0)
No revisions yet.