diff --git a/Cars/Cars.csproj b/Cars/Cars.csproj new file mode 100644 index 00000000..21dff5ca --- /dev/null +++ b/Cars/Cars.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp2.2 + + + diff --git a/Cars/Program.cs b/Cars/Program.cs new file mode 100644 index 00000000..839e417e --- /dev/null +++ b/Cars/Program.cs @@ -0,0 +1,132 @@ +using System; +using System.Collections.Generic; + +namespace Cars +{ + + public class Program + { + public static void Main(String[] args) + { + // Instantiates instances of CarLot, each is an empty List (instance name: inventory) based on Class Vehicle + CarLot edsSouth = new CarLot("South Lot"); + CarLot edsNorth = new CarLot("North Lot"); + + // Instantiates instances of Car (using base Class Vehicle). Passes the parameters cooresponding to the Class parameters + Car Escort = new Car("Ford", "Escort", "Tx-123", 8000, "Hatchback", 4); + Car Mustang = new Car("Ford", "Mustang", "Tx-654", 15000, "Coupe", 4); + + // Instantiates instances of Truck (using base Class Vehicle). Passes the parameters cooresponding to the Class parameters + Truck SuperDuty = new Truck("Ford", "SuperDuty", "Tx-987", 20000, "LongBed"); + Truck Ram = new Truck("Dodge", "Ram", "Tx-456", 10000, "LongBed"); + + // Method Call chained to CarLot Class list variable - passes through a Class Vehicle parameter + // Calls Class Object (which is either a Car:Vehicle or Truck:Vehicle) and ads it to the CarLot list + // The "return" of either Class is the object added to the CarLot list + edsSouth.addCar(Escort); + edsSouth.addCar(Ram); + + edsNorth.addCar(Mustang); + edsNorth.addCar(SuperDuty); + + // Method Call chained to CarLot Class list variable - method is void, no parameter + edsSouth.PrintInventory(); + edsNorth.PrintInventory(); + + Console.ReadLine(); + } + } + + public class CarLot + { + // Field defines a List called inventory (variable) with a (Class: Vehicle) value + List inventory; + String name; + + // Paremeterized Constructor - when called it creates a blank instance of a List + // It takes in a string passed in from the instance call (ex: "South Lot") + public CarLot(string Lname) + { + //Constructor - when called it creates an empty instance of CarLot List called "this.inventory" + this.inventory = new List(); + //Constructor parameter - takes parameter and sets it to this.name instance variable (ex: "South Lot") + this.name = Lname; + } + + // Method addCar - takes in a Class: Vehicle type and sets it to the object variable "vehicle" + public void addCar(Vehicle vehicle) + { + // Method - when called it adds a vehicle according to the vehicle class and parameters passed in + this.inventory.Add(vehicle); + } + + // Method PrintInventory - Void - takes in no parameters + public void PrintInventory() + { + // Prints the current instance Car Lot "this.name" and the count of objects in the list (cars) + Console.WriteLine("Eds Cars Lot: {0} Car Count: {1}", this.name, this.inventory.Count); + + // loops through each object in the current instance of CarLot list and prints the contents, each vehicle + for(int i = 0; i < this.inventory.Count; i++) + { + Console.WriteLine("Vehicle Inventory: {0}", this.inventory[i]); + } + Console.WriteLine(); + } + } + + public abstract class Vehicle + { + public string make; + public string model; + public string license; + public int price; + public Vehicle(string Tmake, string Tmodel, string Tlicense, int Tprice) + { + make = Tmake; + model = Tmodel; + license = Tlicense; + price = Tprice; + } + + } + + // Class Car : Vehicle - takes in parameters accorting to its Constructor - instance generator must match + // Car : Vehicle - returns the string value in the ToString (override) Method + public class Car : Vehicle + { + public string Ctype; + public int Cdoors; + public Car(string Tmake, string Tmodel, string Tlicense, int Tprice, string type, int doors) : base (Tmake, Tmodel, Tlicense, Tprice) + { + Ctype = type; + Cdoors = doors; + } + + override public String ToString() + { + String s = ""; + s = (" Car Make: " +make +" Model: " +model +" License: " +license +" Type: " +Ctype +" Doors: " +Cdoors +" Price: " +price); + return s; + } + } + + // Class Truck : Vehicle - takes in parameters accorting to its Constructor - instance generator must match + // Truck : Vehicle - returns the string value in the ToString (override) Method + public class Truck : Vehicle + { + public string Tbed; + + public Truck(string Tmake, string Tmodel, string Tlicense, int Tprice, string bed) : base (Tmake, Tmodel, Tlicense, Tprice) + { + Tbed = bed; + } + + override public String ToString() + { + String s = ""; + s = (" Truck Make: " +make +" Model: " +model +" Bed Size: " +Tbed +" License: " +license +" Price: " +price); + return s; + } + } +} \ No newline at end of file diff --git a/Files/Files.cs b/Files/Files.cs index da1ebc78..6b6c4e4f 100644 --- a/Files/Files.cs +++ b/Files/Files.cs @@ -1,4 +1,5 @@ using System; +using System.IO; namespace Files { @@ -6,7 +7,26 @@ class Program { static void Main(string[] args) { - Console.WriteLine("Hello World!"); + string[] lines = System.IO.File.ReadAllLines("/Users/afogarasi/Desktop/words_alpha.txt"); + + System.IO.File.WriteAllLines("/Users/afogarasi/Desktop/words.2_alpha.txt", lines); + + StreamReader stream = File.OpenText("/Users/afogarasi/Desktop/words_alpha.txt"); + + FileStream outStream = File.OpenWrite("/Users/afogarasi/Desktop/words3_alpha.txt"); + + StreamWriter s = new StreamWriter (outStream); + + + string line = stream.ReadLine(); + while (line != null) + { + Console.WriteLine(line); + line = stream.ReadLine(); + } + + s.Close(); + stream.Close(); } } } diff --git a/OOPDay1/OOPDay1.csproj b/OOPDay1/OOPDay1.csproj new file mode 100644 index 00000000..21dff5ca --- /dev/null +++ b/OOPDay1/OOPDay1.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp2.2 + + + diff --git a/OOPDay1/Program.cs b/OOPDay1/Program.cs new file mode 100644 index 00000000..b3290243 --- /dev/null +++ b/OOPDay1/Program.cs @@ -0,0 +1,102 @@ +using System; +using System.Collections.Generic; + + +namespace OOPDay1 +{ + class Program + { + static void Main(string[] args) + { + Person Passenger = new Person("Tom"); + Car NextCar = new Car("Blue", 4); + Garage smallGarage = new Garage(2); + + NextCar.SeatPerson(Passenger, 0); + Console.WriteLine(NextCar.People); + + smallGarage.ParkCar(NextCar, 0); + Console.WriteLine(smallGarage.Cars); + } + } + + public class Person + { + // Constructor creates an instance of a Person + public Person(string initialGender) + { + gender = initialGender; + } + + public string gender { get; private set; } + } + + class Car + { + private Person[] persons; + + // Constructor creates an instance of a Car with attributes of Size (seats) and Color + public Car(String initialColor, int initialSize) + { + Color = initialColor; + Size = initialSize; + this.persons = new Person[initialSize]; + } + + public String Color; + public int Size { get; private set; } + + + // Method to get an instance of a person and place that person in a seat (index) of the "persons" array + public void SeatPerson (Person person, int seat) + { + persons[seat] = person; + } + + // Method prints out where each instance of People is sitting in a car (seat) and the color of the car + public string People { + get { + for (int i = 0; i < persons.Length; i++) + { + if (persons[i] != null) { + Console.WriteLine(String.Format("Passenger {0} is in seat {1} of the {2} car", persons[i].gender, i+1, Color)); + } + } + return "Where is it parked?"; + } + } + } + class Garage + { + private Car[] cars; + + // Constructor creates an instance a garage with attributes of number of parking spaces (Space) + public Garage(int initialSpace) + { + Space = initialSpace; + this.cars = new Car[initialSpace]; + } + + public int Space { get; private set; } + + // Method to get an instance of a Car and place that car in a parking spot (index) of the "cars" array + public void ParkCar (Car car, int spot) + { + cars[spot] = car; + } + + // Method prints out where each instance of Car is parked in a Garage (spot) in the Small Garage + 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} of the Small Garage.", cars[i].Color, i+1)); + } + } + return "That's all!"; + } + } + } +} \ No newline at end of file diff --git a/OOPGarage/OOPGarage.csproj b/OOPGarage/OOPGarage.csproj new file mode 100644 index 00000000..21dff5ca --- /dev/null +++ b/OOPGarage/OOPGarage.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp2.2 + + + diff --git a/OOPGarage/Program.cs b/OOPGarage/Program.cs new file mode 100644 index 00000000..d9e326bc --- /dev/null +++ b/OOPGarage/Program.cs @@ -0,0 +1,102 @@ +using System; +using System.Collections.Generic; + + +namespace OOPDay1 +{ + class Program + { + static void Main(string[] args) + { + Person Passenger = new Person("Tom"); + Car NextCar = new Car("Blue", 4); + Garage smallGarage = new Garage(2); + + NextCar.SeatPerson(Passenger, 0); + Console.WriteLine(NextCar.People); + + smallGarage.ParkCar(NextCar, 0); + Console.WriteLine(smallGarage.Cars); + } + } + + public class Person + { + // Constructor creates an instance of a Person + public Person(string initialGender) + { + gender = initialGender; + } + + public string gender { get; private set; } + } + + class Car + { + private Person[] persons; + + // Constructor creates an instance of a Car with attributes of Size (seats) and Color + public Car(String initialColor, int initialSize) + { + Color = initialColor; + Size = initialSize; + this.persons = new Person[initialSize]; + } + + public String Color; + public int Size { get; private set; } + + + // Method to get an instance of a person and place that person in a seat (index) of the "persons" array + public void SeatPerson (Person person, int seat) + { + persons[seat] = person; + } + + // Method prints out where each instance of People is sitting in a car (seat) and the color of the car + public string People { + get { + for (int i = 0; i < persons.Length; i++) + { + if (persons[i] != null) { + Console.WriteLine(String.Format("Passenger {0} is in seat {1} of the {2} car", persons[i].gender, i+1, Color)); + } + } + return "Where is it parked?"; + } + } +    } + class Garage + { + private Car[] cars; + + // Constructor creates an instance a garage with attributes of number of parking spaces (Space) + public Garage(int initialSpace) + { + Space = initialSpace; + this.cars = new Car[initialSpace]; + } + + public int Space { get; private set; } + + // Method to get an instance of a Car and place that car in a parking spot (index) of the "cars" array + public void ParkCar (Car car, int spot) + { + cars[spot] = car; + } + + // Method prints out where each instance of Car is parked in a Garage (spot) in the Small Garage + 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} of the Small Garage.", cars[i].Color, i+1)); + } + } + return "That's all!"; + } + } +    } +} diff --git a/TowersOfHanoi/TowersOfHanoi.cs b/TowersOfHanoi/TowersOfHanoi.cs index 10475b4a..9c6135ae 100644 --- a/TowersOfHanoi/TowersOfHanoi.cs +++ b/TowersOfHanoi/TowersOfHanoi.cs @@ -1,12 +1,183 @@ using System; +using System.Collections; +using System.Collections.Generic; namespace TowersOfHanoi { class Program { static void Main(string[] args) + { + Game game = new Game(); + game.Run(); + + } + } +// Game class + public class Game + { + // Field defines a Dictionary called towers (variable) with a string (key) and a (tower) value + public Dictionary tDictionary; + + //Constructor - when called it creates an instance of a Dictionary called "towers" + public Game() + { + // Method call - creates an empty dictionary called "this.towers" with a string (key) and a Tower object (value) + this.tDictionary = new Dictionary(); + + // creates 4 Block objects using the "Block" class and populates them with unique weights + Block red = new Block(4); + Block white = new Block(3); + Block blue = new Block(2); + Block green = new Block(1); + + // creates 3 unique Tower objects (A, B, C) defined by the "Tower" class each with an empty Stack of empty Block objects + Tower A = new Tower(); + Tower B = new Tower(); + Tower C = new Tower(); + + // populates TowerA.blocks (blocks = Stack containing a Block object) using Push, one at a time with named "Block"s + A.blocks.Push(red); + A.blocks.Push(white); + A.blocks.Push(blue); + A.blocks.Push(green); + + // Method call - uses the "this.towers" instance variable (Dictionary) and adds (Add) a Key (string) and value (TowerA and B and C) one at a time + this.tDictionary.Add("A",A); + this.tDictionary.Add("B",B); + this.tDictionary.Add("C",C); + } + + public void Run() + { + Console.WriteLine("Play Towers of Hanoi"); + // User Input Method + // Ask user to input "From" Tower and "To" Tower + // Write to screen the player's choice + string playGame = "Y"; + while (playGame == "Y") + { + printBoard(); + + // Error handling using try if something other than string values "A", "B" or "C" are entered + try + { + Console.WriteLine("Choose the SOURCE Tower (A, B or C): "); + string from = (Console.ReadLine().ToUpper()); + Console.WriteLine("SOURCE Tower is Tower: " + from); + Tower From = this.tDictionary[from]; + + Console.WriteLine("Choose the To Tower: "); + string to = (Console.ReadLine().ToUpper()); + Console.WriteLine("DESTINATION Tower is Tower: " + to); + Tower To = this.tDictionary[to]; + + if (IsLegal(From, To)) + { + Move(From, To); + } + } + + // catch point in case of a bad user entry + catch (Exception e) + { + Console.WriteLine(e.Message); + } + + printBoard(); + int ctB = this.tDictionary["B"].blocks.Count; + int ctC = this.tDictionary["C"].blocks.Count; + if (ctB == 4 || ctC ==4) + { + Console.WriteLine("You Win!"); + playGame = "end"; + } + else + {Console.WriteLine("Try Another? \"Y\" = yes, any other choice to exit: "); + playGame = Console.ReadLine().ToUpper(); + } + } + Console.ReadLine(); + } + public void printBoard() + { + // iterates through each key in the this.towers Dictionary + foreach (string key in this.tDictionary.Keys) + { + // writes each key + Console.Write(key+":"); + // creates the variable "blockStack" according to Tower Class - a Stack of a Block + // this.towers[key] is the Tower (Stack of Block) paired to the instance key + Tower blockStack = this.tDictionary[key]; + string blockstring = ""; + + // iterates through each Block in blockStack + // PREpends each weight integer to the string variable x with a space between + foreach (Block i in blockStack.blocks) + { + blockstring = i.weight + " " + blockstring; + } + // writes out the string variable x + Console.WriteLine(blockstring); + } + } + public bool IsLegal(Tower From, Tower To) + { + if (From.blocks.Count == 0) + { + Console.WriteLine("No move. Nothing in Start Tower "); + return false; + } + + else if (To.blocks.Count == 0) + { + return true; + } + + else if (To.blocks.Count > 0) + { + int E = To.blocks.Peek().weight; + int S = From.blocks.Peek().weight; + if (S > E) + { + Console.WriteLine("Move Not Accepted. Big block over small block is not allowed"); + return false; + } + } + return true; + } + public void Move(Tower start, Tower end) + { + // this method should move the top block from the source tower to the destination tower + Block j = start.blocks.Pop(); + end.blocks.Push(j); + } + } + + // Tower class creates a Stack containing an empty "Block" object + public class Tower + { + // Field defines a Stack called blocks (variable) with an empty Block + public Stack blocks; + + //Constructor - when called it creates an instance of a Stack with a Block + public Tower() + { + this.blocks = new Stack(); + } + } + + // Block class creates a "Block" object made up of a string (color) and an integer (weight) + public class Block + { + //Instance Variable: creates an integer of weight that is unique to each instance + + public int weight {get; private set;} + + // Constructor - when called it creates an instance of a Block + public Block(int initialWeight) { - Console.WriteLine("Hello World!"); + this.weight = initialWeight; } } -} +} \ No newline at end of file