There are two different types of numbers in C#:
-6
, 0
, 1
, 25
, 976
and 500000
.-2.4
, 0.1
, 3.14
, 16.984025
and 1024.0
.The two most common numeric types in C# are int
and double
. An int
is a 32-bit integer and a double
is a 64-bit floating-point number.
Arithmetic is done using the standard arithmetic operators. Numbers can be compared using the standard numeric comparison operators and the equality (==
) and inequality (!=
) operators.
C# has two types of numeric conversions:
As an int
has less precision than a double
, converting from an int
to a double
is safe and is thus an implicit conversion. However, converting from a double
to an int
could mean losing data, so that requires an explicit conversion.
In this exercise you must conditionally execute logic. The most common way to do this in C# is by using an if/else
statement:
int x = 6;
if (x == 5)
{
// Execute logic if x equals 5
}
else if (x > 7)
{
// Execute logic if x greater than 7
}
else
{
// Execute logic in all other cases
}
The condition of an if
statement must be of type bool
. C# has no concept of truthy values.
In this exercise you'll be writing code to analyze the production of an assembly line in a car factory. The assembly line's speed can range from 0
(off) to 10
(maximum).
At its lowest speed (1
), 221
cars are produced each hour. The production increases linearly with the speed. So with the speed set to 4
, it should produce 4 * 221 = 884
cars per hour. However, higher speeds increase the likelihood that faulty cars are produced, which then have to be discarded.
You have three tasks.
Implement the (static) AssemblyLine.SuccessRate()
method to calculate the ratio of an item being created without error for a given speed. The following table shows how speed influences the success rate:
0
: 0% success rate.1
to 4
: 100% success rate.5
to 8
: 90% success rate.9
: 80% success rate.10
: 77% success rate.AssemblyLine.SuccessRate(10)
// => 0.77
Implement the (static) AssemblyLine.ProductionRatePerHour()
method to calculate the assembly line's production rate per hour, taking into account its success rate:
AssemblyLine.ProductionRatePerHour(6)
// => 1193.4
Note that the value returned is a double
.
Implement the (static) AssemblyLine.WorkingItemsPerMinute()
method to calculate how many working cars are produced per minute:
AssemblyLine.WorkingItemsPerMinute(6)
// => 19
Note that the value returned is an int
.
Sign up to Exercism to learn and master C# with 62 concepts, 164 exercises, and real human mentoring, all for free.