-
Notifications
You must be signed in to change notification settings - Fork 103
Expand file tree
/
Copy pathProgram.cs
More file actions
147 lines (129 loc) · 3.23 KB
/
Program.cs
File metadata and controls
147 lines (129 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
using System;
public class Program
{
public static void Main()
{
Station rebelSpaceStation = new Station("RebelSpaceStation", 2, "Rebel");
Person leia = new Person("Leia", "Organa", "Rebel");
Person luke = new Person("Luke", "Skywalker", "Rebel");
Ship falcon = new Ship("Rebel", "Smuggling", 2);
Ship tie = new Ship("Tie", "Fighter", 1);
Station smallStation = new Station("Rebel", 2, "Rebel");
smallStation.ParkShip(tie, 0);
tie.addPerson(leia, 0);
Console.WriteLine(smallStation.Roster);
}
}
class Person
{
private string firstName;
private string lastName;
private string alliance;
public Person(string firstName, string lastName, string alliance)
{
this.firstName = firstName;
this.lastName = lastName;
this.alliance = alliance;
}
public string FullName
{
get
{
return this.firstName + " " + this.lastName;
}
set
{
string[] names = value.Split(' ');
this.firstName = names[0];
this.lastName = names[1];
}
}
}
class Ship
{
private Person[] passengers;
public Ship(string initialName)
{
Name = initialName;
}
public string Name { get; private set; }
public Ship(string alliance, string type, int size)
{
this.Type = type;
this.Alliance = alliance;
this.passengers = new Person[size];
}
public string Type
{
get;
set;
}
public string Alliance
{
get;
set;
}
public string Passengers
{
get
{
foreach (var person in passengers)
{
if (person != null)
{
Console.WriteLine(String.Format("{0}", person.FullName));
}
}
return "That's Everybody!";
}
}
public void addPerson(Person passengers, int spot)
{
this.passengers[spot] = passengers;
}
public void EnterShip(Person person, int seat)
{
this.passengers[seat] = person;
}
public void ExitShip(int seat)
{
this.passengers[seat] = null;
}
}
class Station
{
private Ship[] ships;
public string Name { get; private set; }
public int Size { get; private set; }
public string Alliance { get; private set; }
public Station(string initialName, int initialSize, string alliance)
{
this.Name = initialName;
this.ships = new Ship[initialSize];
this.Size = initialSize;
this.Alliance = alliance;
}
public void ParkShip(Ship ship, int spot)
{
ships[spot] = ship;
}
public void ExitStation(int spot)
{
this.ships[spot] = null;
}
public string Roster
{
get
{
for (int i = 0; i < ships.Length; i++)
{
if (ships[i] != null)
{
Console.WriteLine(String.Format("The {0} ship is in spot {1} and the people on that ship are:", ships[i].Type, i));
Console.WriteLine(ships[i].Passengers);
}
}
return "That's all!";
}
}
}