Tracks
/
C#
C#
/
Exercises
/
Land Grab in Space
Land Grab in Space

Land Grab in Space

Learning Exercise

Introduction

Structs

C# structs are closely related classs. They have state and behavior. They have constructors that take arguments, instances can be assigned, tested for equality and stored in collections.

enum Unit
{
    Kg,
    Lb
}
struct Weight
{
    private double count;
    private Unit unit;

    public Weight(double count, Unit unit)
    {
        this.count = count;
        this.unit = unit;
    }

    public override string ToString()
    {
        return count.ToString() + unit.ToString();
    }
}

new Weight(77.5, Unit.Kg).ToString();
// => "77.6Kg"

Instructions

You have been tasked by the claims department of Isaacs Asteroid Exploration Co. to improve the performance of their land claim system.

Every time a new asteroid is ready for exploitation speculators are invited to stake their claim to a plot of land. The asteroid's land is divided into 4 sided plots. Speculators claim the land by specifying its dimensions.

Your goal is to develop a performant system to handle the land rush that has in the past caused the website to crash.

The unit of measure is 100 meters but can be ignored in these tasks.

1. Define a Plot

Complete the implementation of the Plot struct which comprises 4 coord structs (which it accepts in its constructor).

2. Speculators can stake their claim by specifying a plot identified by its dimensions

Implement the ClaimsHandler.StakeClaim() method to allow a claim to be registered.

Implement the ClaimsHandler.IsClaimStaked() method to determine whether a claim has been staked.

var ch = new ClaimsHandler();
ch.StakeClaim(new Plot(new Coord(1,1), new Coord(2,1), new Coord(1,2), new Coord(2,2)));
ch.IsClaimStaked(new Plot(new Coord(1,1), new Coord(2,1), new Coord(1,2), new Coord(2,2)));
// => true

3. Check whether the current claim is the same as the last one.

Implement the ClaimsHandler.IsLastClaim() method to compare the current claim with the previous one.

var ch = new ClaimsHandler();
ch.StakeClaim(new Plot(new Coord(1,1), new Coord(2,1), new Coord(1,2), new Coord(2,2)));
ch.IsLastClaim(new Plot(new Coord(1,1), new Coord(2,1), new Coord(1,2), new Coord(2,2)));
// => true

4. Find the plot claimed that has the longest side for research purposes

Implement the ClaimsHandler.GetClaimWithLongestSide() method to examine all registered claims and return the plot with the longest side.

var ch = new ClaimsHandler();
ch.StakeClaim(new Plot(new Coord(1,1), new Coord(2,1), new Coord(1,2), new Coord(2,2)));
ch.StakeClaim(new Plot(new Coord(1,1), new Coord(20,1), new Coord(1,2), new Coord(2,2)));
ch.GetClaimWithLongestSide();
// => new Plot(new Coord(1,1), new Coord(20,1), new Coord(1,2), new Coord(2,2))
Edit via GitHub The link opens in a new window or tab
C# Exercism

Ready to start Land Grab in Space?

Sign up to Exercism to learn and master C# with 62 concepts, 164 exercises, and real human mentoring, all for free.