From ed7d0800bb08b98f91a9e3e76a93ac5c210d1e7b Mon Sep 17 00:00:00 2001 From: Michael Rich Date: Sun, 11 Nov 2018 03:49:48 -0600 Subject: [PATCH 1/2] Created Garage assignment --- Garage/Garage.csproj | 8 ++++++++ Garage/Program.cs | 12 ++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 Garage/Garage.csproj create mode 100644 Garage/Program.cs diff --git a/Garage/Garage.csproj b/Garage/Garage.csproj new file mode 100644 index 00000000..23df6047 --- /dev/null +++ b/Garage/Garage.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp2.1 + + + diff --git a/Garage/Program.cs b/Garage/Program.cs new file mode 100644 index 00000000..11ad11c0 --- /dev/null +++ b/Garage/Program.cs @@ -0,0 +1,12 @@ +using System; + +namespace Garage +{ + class Program + { + static void Main(string[] args) + { + Console.WriteLine("Hello World!"); + } + } +} From 431ca43b4502671f2d700d5d5d15d1a6a4bfd6f5 Mon Sep 17 00:00:00 2001 From: Michael Rich Date: Mon, 12 Nov 2018 23:57:31 -0600 Subject: [PATCH 2/2] I had accidently pushed the garage to my week4-2 branch --- Garage/Program.cs | 105 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 99 insertions(+), 6 deletions(-) diff --git a/Garage/Program.cs b/Garage/Program.cs index 11ad11c0..777e7a83 100644 --- a/Garage/Program.cs +++ b/Garage/Program.cs @@ -1,12 +1,105 @@ using System; -namespace Garage + +public class Program { - class Program + + public static void Main() + { + // instantiating a new instance of person, and passing names to the constructor; + Person Jill = new Person("Jill"); + Person Chris = new Person("Chris"); + Person Rebecca = new Person("Rebecca"); + Person Barry = new Person("Barry"); + + // instantiating a new instance of car, and passing colors to the constructor; + Car blueCar = new Car("blue"); + Car redCar = new Car("red"); + Car greenCar = new Car("green"); + Car whiteCar = new Car("white"); + + //Assigning Persons names to cars + blueCar.Name = Jill.Name; + redCar.Name = Barry.Name; + greenCar.Name = Chris.Name; + whiteCar.Name = Rebecca.Name; + + // instantiating a new instance of Garage class, and passing in a size of 4 to the constructor; + Garage smallGarage = new Garage(4); + + // calling a method Parkcar of the smallGarage instance, with inputs of car color and parking space + smallGarage.ParkCar(blueCar, 0); + smallGarage.ParkCar(redCar, 1); + smallGarage.ParkCar(greenCar, 2); + smallGarage.ParkCar(whiteCar, 3); + + // printint out the cars attribute of the small garage + Console.WriteLine(smallGarage.Cars); + } +} + +class Car +{ + // once the color is set i cant change it, outisde of this class + public string Color {get; private set;} + + // Name can be set outside of class + public string Name{get; set;} + + // Car constructor + public Car(String color) { - static void Main(string[] args) - { - Console.WriteLine("Hello World!"); - } + this.Color = color; } } + +class Person +{ + //attribute for persons name + public string Name { get; private set;} + + //Person constructor + public Person(string name){ + this.Name = name; + } +} + +class Garage +{ + // creates array of cars so they can be parked in the for loop down below + public Car[] cars; + + // constructor , int of initial size + public Garage(int initialSize) + { + // setting the size of this garage + Size = initialSize; + // instantiating an array of Cars, of size initialsize + this.cars = new Car[initialSize]; + } + + //attribute , private for number of slots in the garage. + public int Size { get; private set; } + + // a method that adds a car to the spot in the cars array + public void ParkCar (Car car, int spot) + { + // what if there is a car already in the spot? + // what if the spot passed in is outside the array? + cars[spot] = car; + } + public string Cars { + get { + String carsString = ""; + //parks cars in spot + for (int i = 0; i < cars.Length; i++) + { + if (cars[i] != null) { + carsString += String.Format("{2}'s {0} car is in spot {1}.", cars[i].Color, i, cars[i].Name); + carsString += "\n"; + } + } + return carsString; + } + } +} \ No newline at end of file