forked from AustinCodingAcademy/csharp-workbook
-
Notifications
You must be signed in to change notification settings - Fork 0
Week5 1 #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
d3marco
wants to merge
11
commits into
master
Choose a base branch
from
week5-1
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Week5 1 #7
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
22ccbc6
finished week1 practice
d3marco d8271b9
textgame file added
d3marco e112627
file renamed
d3marco 2efd24f
1st attempt text game
d3marco ff1c62b
updated text game
d3marco 17a8883
finished text game
d3marco ce7dd0e
finail fizzbuzz
d3marco c4f83b1
CarGarage first commit
d3marco 714529a
Final Garage program
d3marco 6406231
first draft StarWars
d3marco a60252c
final starwars
d3marco File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>netcoreapp2.1</TargetFramework> | ||
| </PropertyGroup> | ||
|
|
||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
|
|
||
| public class Program | ||
| { | ||
| public static void Main() | ||
| { | ||
| Car blueCar = new Car("blue"); | ||
| Car redCar = new Car("red"); | ||
| Car greenCar = new Car("green"); | ||
| Car orangeCar = new Car("orange"); | ||
| Garage smallGarage = new Garage(4); | ||
|
|
||
| Person person1 = new Person("James", "Smith"); | ||
| Person person2 = new Person("Jane", "Ann"); | ||
| Person person3 = new Person("Robert", "Class"); | ||
| Person person4 = new Person("Lisa", "George"); | ||
|
|
||
| blueCar.addPerson(person1); | ||
| orangeCar.addPerson(person2); | ||
|
|
||
|
|
||
| smallGarage.ParkCar(blueCar, 0); | ||
| smallGarage.ParkCar(orangeCar,1); | ||
| smallGarage.ParkCar(redCar,2); | ||
| smallGarage.ParkCar(greenCar,3); | ||
|
|
||
|
|
||
| for ( int i =0; i < 1; i++){ | ||
| try | ||
| { | ||
| Car car = getCar(smallGarage); | ||
|
|
||
| Console.WriteLine("Enter your first name:"); | ||
| string firstname = Console.ReadLine(); | ||
| Console.WriteLine("Enter your last name:"); | ||
| string lastName = Console.ReadLine(); | ||
| Person person = new Person(firstname,lastName); | ||
| car.addPerson(person); | ||
|
|
||
| } | ||
| catch | ||
| { | ||
| Console.WriteLine("No car found"); | ||
| } | ||
| } | ||
|
|
||
| Console.WriteLine(smallGarage.Cars); | ||
| } | ||
| public static string getUserCar() | ||
| { | ||
| Console.WriteLine("What car would you like?"); | ||
| string carChoice = Console.ReadLine().ToLower(); | ||
| return carChoice; | ||
|
|
||
| } | ||
| public static Car getCar(Garage myCars) | ||
| { | ||
| string userCar = getUserCar(); | ||
| foreach (Car car in myCars.cars) | ||
| { | ||
| if (car.Color == userCar) | ||
| { | ||
| return car; | ||
| } | ||
| } | ||
| return null; | ||
|
|
||
| } | ||
|
|
||
| } | ||
| public class Car | ||
| { | ||
| List<Person> people; | ||
|
|
||
| public Car(string initialColor) | ||
| { | ||
| people = new List<Person>(); | ||
| Color = initialColor; | ||
|
|
||
|
|
||
| } | ||
| public void addPerson(Person person) | ||
| { | ||
| people.Add(person); | ||
|
|
||
| } | ||
| public void getPeople() | ||
| { | ||
| foreach (Person p in people) | ||
| { | ||
| Console.WriteLine("{0} " + "{1} ", p.firstName, p.lastName); | ||
| } | ||
| } | ||
|
|
||
| public string Color { get; private set; } | ||
| } | ||
|
|
||
| public class Garage | ||
| { | ||
| public Car[] cars { get; private set; } | ||
|
|
||
| public Garage(int initialSize) | ||
| { | ||
| Size = initialSize; | ||
| this.cars = new Car[initialSize]; | ||
| } | ||
|
|
||
| public int Size { get; private set; } | ||
|
|
||
| public void ParkCar(Car car, int spot) | ||
| { | ||
| cars[spot] = car; | ||
| } | ||
|
|
||
| public string Cars | ||
| { | ||
| get | ||
| { | ||
| for (int i = 0; i < cars.Length; i++) | ||
| { | ||
| if (cars[i] != null) | ||
| { | ||
| Console.WriteLine(String.Format("The {0} car is in spot {1}.", cars[i].Color, i)); | ||
| cars[i].getPeople(); | ||
| } | ||
| } | ||
| return "That's all!"; | ||
| } | ||
| } | ||
| } | ||
| public class Person | ||
| { | ||
|
|
||
| public string firstName { get; private set; } | ||
| public string lastName { get; private set; } | ||
| public Person(string firstName, string lastName) | ||
| { | ||
| this.firstName = firstName; | ||
| this.lastName = lastName; | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
|
|
||
| public class Program | ||
| { | ||
| public static void Main() | ||
| { | ||
| Person leia = new Person("Leia", "Organa", "Rebel"); | ||
| Person darth = new Person("Darth", "Vader", "Imperial"); | ||
| Person luke = new Person("Luke", "Skywalker", "Rebel"); | ||
| Person han = new Person("Han", "Solo", "Rebel"); | ||
| Person palp = new Person("Emporer", "Palpatine", "Imperial"); | ||
| Ship x = new Ship("xwing", "Rebel", "fighter", 2); | ||
| Ship falcon = new Ship("MilFal", "Rebel", "Smuggling", 2); | ||
| Ship tie = new Ship("TieFie", "Tie", "Fighter", 1); | ||
| Station station1 = new Station("Rebel Space Station", "Rebel", 3); | ||
| Station station2 = new Station("Death Star", "Imperial", 3); | ||
| x.EnterShip(luke, 0); | ||
| x.EnterShip(han, 1); | ||
| station1.DockShip(x, 1); | ||
| PrintRoster(station1); | ||
| } | ||
| private static void PrintRoster(Station station) | ||
| { | ||
|
|
||
| foreach (KeyValuePair<int, Ship> ships in station.Docked) | ||
| { | ||
| Console.WriteLine("Ship {0} contains:", ships.Value.Name); | ||
| Console.WriteLine("{0}", ships.Value.Passengers); | ||
| } | ||
| } | ||
| } | ||
| 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 name, string alliance, string type, int size) | ||
| { | ||
| this.Name = name; | ||
| this.Type = type; | ||
| this.Alliance = alliance; | ||
| this.passengers = new Person[size]; | ||
| } | ||
| public string Name | ||
| { | ||
| get; | ||
| set; | ||
| } | ||
| public string Type | ||
| { | ||
| get; | ||
| set; | ||
| } | ||
| public string Alliance | ||
| { | ||
| get; | ||
| set; | ||
| } | ||
| public string Passengers | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. did not expect a console statement in the passengers getter. |
||
| { | ||
| get | ||
| { | ||
| foreach (var person in passengers) | ||
| { | ||
| Console.WriteLine(String.Format("{0}", person.FullName)); | ||
| } | ||
| return "That's Everybody!"; | ||
| } | ||
| } | ||
| public void EnterShip(Person person, int seat) | ||
| { | ||
| this.passengers[seat] = person; | ||
| } | ||
| public void ExitShip(int seat) | ||
| { | ||
| this.passengers[seat] = null; | ||
| } | ||
| } | ||
| class Station | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. was expecting a station rooster method. |
||
| { | ||
| public string Name { get; set; } | ||
| public string Alliance { get; set; } | ||
| public int Size { get; set; } | ||
| public Dictionary<int,Ship> Docked = new Dictionary<int, Ship>(); | ||
| public Station(string name, string alliance, int size) | ||
| { | ||
| this.Name = name; | ||
| this.Alliance = alliance; | ||
| } | ||
| public void DockShip(Ship ship, int port) | ||
| { | ||
| Docked.Add(port, ship); | ||
| } | ||
| public void UnDockShip(Ship ship, int port) | ||
| { | ||
| Docked.Remove(port); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>netcoreapp2.1</TargetFramework> | ||
| </PropertyGroup> | ||
|
|
||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This getter should not console anything to the screen.