Skip to content

Instantly share code, notes, and snippets.

@CasonBarnhill
Created October 25, 2015 20:20
Show Gist options
  • Save CasonBarnhill/54196a7b5b67d8598eab to your computer and use it in GitHub Desktop.
Save CasonBarnhill/54196a7b5b67d8598eab to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Week1Day4.cs
//build class
{
public class Delivery
{
public string Destination;
public string ItemShipped;
public int NumberOfCrates;
public int Profit;
public DateTime CreatedOn;
public string Pilot()
{
string Pilot = "";
if (this.Destination == "Earth")
{
Pilot = "Fry";
}
else if (this.Destination == "Mars")
{
Pilot = "Amy";
}
else if (this.Destination == "Uranus")
{
Pilot = "Bender";
}
else
{
Pilot = "Leela";
}
return Pilot;
}
}
public class Program
{
public static void Main()
{
//begin parse file
var planetExpressLogs = File.ReadAllLines(@"c:\projects\csv\planet_express_logs.csv");
var numOfLines = planetExpressLogs.Count();
//create an array of deliveries to load stuff into
Delivery[] deliveries = new Delivery[numOfLines - 1];
//loop through each file creating a delivery
for (int i = 0; i < numOfLines - 1; i++)
{
var row = planetExpressLogs[i + 1];
var columns = row.Split(new[] { ',' });
deliveries[i] = new Delivery();
deliveries[i].Destination = columns[0];
deliveries[i].ItemShipped = columns[1];
deliveries[i].NumberOfCrates = int.Parse(columns[2]);
deliveries[i].Profit = int.Parse(columns[3]);
deliveries[i].CreatedOn = DateTime.Parse(columns[4]);
}
foreach (var c in deliveries)
{
Console.WriteLine($"Destination:{c.Destination}. ItemShipped:{c.ItemShipped}. NumberOfCrates: {c.NumberOfCrates}. Profit:{c.Profit}. CreatedOn:{c.CreatedOn}.");
}
//how many trips did each employee make
int FryTrips = 0;
int AmyTrips = 0;
int BenderTrips = 0;
int LeelaTrips = 0;
foreach (Delivery c in deliveries)
{
switch (c.Pilot())
{
case "Fry":
FryTrips = FryTrips + 1;
break;
case "Amy":
AmyTrips = AmyTrips + 1;
break;
case "Bender":
BenderTrips = BenderTrips + 1;
break;
case "Leela":
LeelaTrips = LeelaTrips + 1;
break;
}
}
Console.WriteLine($"Fry traveled {FryTrips} times");
Console.WriteLine($"Amy traveled {AmyTrips} time");
Console.WriteLine($"Bender traveled {BenderTrips} times");
Console.WriteLine($"Leela traveled {LeelaTrips} times");
//how much money did planet express make this week
int totalProfit = 0;
foreach (Delivery c in deliveries)
{
totalProfit += c.Profit;
}
Console.WriteLine($"We made {totalProfit} this week");
//who piloted the planet express
foreach (Delivery c in deliveries)
{
string Pilot = c.Pilot();
Console.WriteLine($"Delivered by {Pilot} to {c.Destination}");
}
//bonus
double FrysBonus = 0;
double AmysBonus = 0;
double BendersBonus = 0;
foreach (var c in deliveries)
{
var Bonus = (c.Profit * .10);
switch (c.Pilot())
{
case "Fry":
FrysBonus += Bonus;
break;
case "Amy":
AmysBonus += Bonus;
break;
case "Bender":
BendersBonus += Bonus;
break;
}
}
Console.WriteLine($"Fry's bonus is:{FrysBonus}");
Console.WriteLine($"Amy's bonus is:{AmysBonus}");
Console.WriteLine($"Bender's bonus is: {BendersBonus}");
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment