HiveBrain v1.2.0
Get Started
← Back to all entries
patterncsharpMinor

Calculates the number of hours and days left, where the total number of hours is 486

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
totalleftnumberthehours486whereanddayscalculates

Problem

I'm new here and this is my first simple console application that calculates the number of hours left. There's a lot to improve and if you have any suggestions on what things to add or refactor that would be awesome! It's 486 because it's the usual number of hours an internship has.

The user presses 1 to enter the number of days, and 2 gets the current date. The output shows the accumulated number of hours, the remaining hours and days left before the 486 hours are up.

```
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Reuseable
{
//calculates the accumulated hours, remaining hours, and remaining days, where total hours = 486.
public static class ReuseableClass
{
static int AccumulatedHours(int dayhours, int input)
{
int result = dayhours * input;
Console.WriteLine("Accumulated hours: " + result);
return result;
}

static int RemainingHours(int totalhours, int accumulatedhours)
{
int result = totalhours - accumulatedhours;
Console.Write("Remaining hours: " + result);
return result;
}

static int RemainingDays(int remaininghours, int dayhours)
{
int result = remaininghours / dayhours;
Console.Write("\nRemaining days: " + result);
return result;
}

/// Number of business days during the 'span'
public static double GetBusinessDays(DateTime startD, DateTime endD)
{

double calcBusinessDays =
1 + ((endD - startD).TotalDays * 5 -
(startD.DayOfWeek - endD.DayOfWeek) * 2) / 7;

if (endD.DayOfWeek == DayOfWeek.Saturday) calcBusinessDays--;
if (startD.DayOfWeek == DayOfWeek.Sunday) calcBusinessDays--;

return calcBusinessDays;
}

public static void NumberOne()
{

Solution

ReuseableClass

Each class is (ok, might be) reusable so naming it like this does not have much value. It calculates something... name it simply IntershipCalculator.

And... it's not really reusable either because you write to the console there. You should write to the console somewhere else and let the methods just calculate the results.

NumberOne

This looks to me like a class but it's a method. You should name it appropriatly ie ReadNumberOne.

//gets input from user
        int accumHours = AccumulatedHours(dayHours, input);
        int remainingHours = RemainingHours(totalHours, accumHours);
        RemainingDays(remainingHours, dayHours);


The comment is misleading. You are not getting here anything from the user but writing results.

Console.WriteLine("1. Enter No. of Days \n2. Use current day");


Why not like so?

Console.WriteLine("1. Enter No. of Days");
Console.WriteLine("2. Use current day");

Code Snippets

//gets input from user
        int accumHours = AccumulatedHours(dayHours, input);
        int remainingHours = RemainingHours(totalHours, accumHours);
        RemainingDays(remainingHours, dayHours);
Console.WriteLine("1. Enter No. of Days \n2. Use current day");
Console.WriteLine("1. Enter No. of Days");
Console.WriteLine("2. Use current day");

Context

StackExchange Code Review Q#139669, answer score: 2

Revisions (0)

No revisions yet.