From 9ab4322ef16756b80bd83502566bea673d50d7ea Mon Sep 17 00:00:00 2001 From: d3marco31 Date: Sat, 24 Nov 2018 20:44:56 -0600 Subject: [PATCH 1/6] inheritance program --- Inheritance/Inheritance.csproj | 8 +++ Inheritance/Program.cs | 81 +++++++++++++++++++++++++ WebServer/WebServer.cs | 108 --------------------------------- WebServer/WebServer.csproj | 13 ---- WebServer/database.db | Bin 49152 -> 0 bytes 5 files changed, 89 insertions(+), 121 deletions(-) create mode 100644 Inheritance/Inheritance.csproj create mode 100644 Inheritance/Program.cs delete mode 100644 WebServer/WebServer.cs delete mode 100644 WebServer/WebServer.csproj delete mode 100644 WebServer/database.db diff --git a/Inheritance/Inheritance.csproj b/Inheritance/Inheritance.csproj new file mode 100644 index 00000000..23df6047 --- /dev/null +++ b/Inheritance/Inheritance.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp2.1 + + + diff --git a/Inheritance/Program.cs b/Inheritance/Program.cs new file mode 100644 index 00000000..5815af61 --- /dev/null +++ b/Inheritance/Program.cs @@ -0,0 +1,81 @@ +using System; + namespace week6_1 +{ + class Manufacture + { + public static void Main(string[] args) + { + Car bmw = new Car(2,"BMW"); + Car audi = new Car(2,"Audi"); + + Truck ford = new Truck(4,"Ford"); + Truck crysler = new Truck(4,"Crysler"); + Console.WriteLine(string.Format("The manufacture is {1} and the car has {0} spots available for passengers.",bmw.spots, bmw.Type)); + Console.WriteLine(string.Format("The manufacture is {1} and the car has {0} spots available for passengers.",audi.spots, audi.Type)); + Console.WriteLine(string.Format("The manufacture is {1} and the truck has {0} spots available for passengers.",ford.Spots, ford.Type)); + Console.WriteLine(string.Format("The manufacture is {1} and the truck has {0} spots available for passengers.",crysler.Spots,crysler.Type)); + + } + } + public interface IcheckCar + { + int getAvaiableSeat(); + string getVehicle(); + } + class Car : IcheckCar + { + public int Spots; + public string Type; + public Car(int spots,string type) + { + this.spots = spots; + this.Type = type; + } + public int spots + { + get; + set; + } + public string type + { + get; + set; + } + int IcheckCar.getAvaiableSeat() + { + return spots; + } + string IcheckCar.getVehicle() + { + return type; + } + } + class Truck : IcheckCar + { + public int Spots; + public string Type; + public Truck(int spots, string type) + { + this.Spots = spots; + this.Type = type; + } + public int spots + { + get; + set; + } + public string type + { + get; + set; + } + int IcheckCar.getAvaiableSeat() + { + return spots; + } + string IcheckCar.getVehicle() + { + return type; + } + } +} \ No newline at end of file diff --git a/WebServer/WebServer.cs b/WebServer/WebServer.cs deleted file mode 100644 index 0ee8ec66..00000000 --- a/WebServer/WebServer.cs +++ /dev/null @@ -1,108 +0,0 @@ -using System; -using System.Threading; -using SimpleHttp; -using System.IO; -using System.Linq; -using Microsoft.Data.Sqlite; -using System.Collections.Generic; - -namespace WebServer -{ - class Program - { - static SqliteConnectionStringBuilder connectionStringBuilder = new SqliteConnectionStringBuilder(); - - static void Main() - { - connectionStringBuilder.DataSource = "./database.db"; - - Route.Add("/items", (request, response, args) => { - response.AsText(getItems()); - }); - - Route.Add("/items", (request, response, args) => { - RunQuery($@" - INSERT into items (name, price, container_id) - VALUES ('milk', '2.99', 1); - "); - response.AsText(getItems()); - }, "POST"); - - //run the server - int port = 8000; - Console.WriteLine($"Running Server On http://127.0.0.1:{port}"); - HttpServer.ListenAsync(port, CancellationToken.None, Route.OnHttpRequestAsync).Wait(); - } - - static string getItems() - { - List> results = RunQuery(@" - SELECT * - FROM items; - "); - string stringResults = PrintResults(results); - stringResults += @" -

-
- - - - -
- "; - return stringResults; - } - - static List> RunQuery(string query) - { - using (var connection = new SqliteConnection(connectionStringBuilder.ConnectionString)) - { - connection.Open(); - var selectCmd = connection.CreateCommand(); - selectCmd.CommandText = query; - SqliteDataReader reader = selectCmd.ExecuteReader(); - List> results = getResults(reader); - reader.Close(); - connection.Close(); - return results; - } - } - - static List> getResults(SqliteDataReader reader) - { - List> results = new List>(); - int row = 0; - while (reader.Read()){ - results.Add(new Dictionary()); - for (var column = 0; column < reader.FieldCount; column++) - { - results[row].Add(reader.GetName(column), reader.GetString(column)); - } - row++; - } - return results; - } - - static string PrintResults(List> results) - { - string resultsString = ""; - foreach (var result in results) - { - System.Collections.Generic.IEnumerable lines = result.Select(kvp => kvp.Key + ": " + kvp.Value); - resultsString += String.Join(Environment.NewLine, lines); - } - return resultsString; - } - } -} diff --git a/WebServer/WebServer.csproj b/WebServer/WebServer.csproj deleted file mode 100644 index 4365eb1b..00000000 --- a/WebServer/WebServer.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - - Exe - netcoreapp2.0 - - - - - - - - diff --git a/WebServer/database.db b/WebServer/database.db deleted file mode 100644 index 2d22309bddfcb69c82aaac413e1aa0feb2cd3cdf..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 49152 zcmeI)?QhdY90%|_JBe|gj+KJNvQoEbg9tj56=_4$w1g5^wUW}3s+2d0Nex6z?GmTz z`eHBIYWo-VFYFcKHr-`Q=3H z8>Yuj^5jbFWa6e6N%qFSO#BvGO{^pzB!AsvZ7hNS1Rwwb2tWV=ueQK)>P^j5;ryrVTHr z-hDZ{(l_ktzspcIk4E)!b-Jt%7mE3F`Ej!_S~Lq2BO~U8@!|8i@hS7;{FIrSD2@&n zX#3~$g`zo87#^F*AEyOf`0&uWMHSa+SXGBqpSIIz zdMSEPGkSaZQpGo}xU+MXQ?(-sT5xdT4GQM7Mnk7Ye@RNi1C5JS=E`gKM7iO$(nDt{(Q+l9i@!_6V1FH zG4j2eWo_59Ql=f%l7ojL#<{-D*J<&|m0IyovdH$xS~K{@Rx7s&yi%qU-;?~2oyes& z-=l0Ui>+f^)GmY~#<633YRv_!goZKu+_$hBv~>rQdgs+ISsZ0W~oE=>o%;8&Iu zwPVu#baKtXTsjpojvV1P{M}iO+qg~*edEj%7sYiMg9>%FYS*SS?W+=97c!}!jt=;n z>xgt>%DMvdcNRQngKJi+r&dMT@@j6yYE)h4i3=fJKFBI0?lAFC{4Rc?2qp+X00Izz z00bZa0SG_<0uX=z1h%n2G!$a`!82B^W_dA{;;E15zf%p@5em&5zGyjS&Y{_=8|5-* zjuuv(p#OiHiwELo@x8dcjSGlFg8&2|009U<00Izz00bZa0SLTW0$tSAKfi^$j;+FVB+!0@k&v$SU zap(|$00bZa0SG_<0uX=z1Rwx`Z7q;Kpic5<8qg)NNA2b9(H#{1fNF4mY>0R=uJ+NA z_7D!@A&dHpw4_c;IztV}G5q3sbHo7o{J$dpX5t?TFhKwU5P$##AOHafKmY;|fB*y_ zu;T?(MP-QuS6SaU4R1FT|3V z5%0*)jxRC_009U<00Izz00bZa0SG_<0ucD$0<@R%y0tJnsPUoew(Z$j`4&D+YInp>Jy*BpY%kjtq$>NvVb-JRXWVP%S=XJ;9{%&H zoVr87ChWRx)w277%rxwOn58%$ty|7D+f&qT#m|+So2%L0hmV_^?B{hL009U<00Izz00bZa0SG`~mk2!T{r`UfJ$< Date: Sun, 25 Nov 2018 17:47:31 -0600 Subject: [PATCH 2/6] TowersofHanoi 1st draft --- TowersOfHanoi/TowersOfHanoi.cs | 73 +++++++++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 2 deletions(-) diff --git a/TowersOfHanoi/TowersOfHanoi.cs b/TowersOfHanoi/TowersOfHanoi.cs index 10475b4a..728b98b0 100644 --- a/TowersOfHanoi/TowersOfHanoi.cs +++ b/TowersOfHanoi/TowersOfHanoi.cs @@ -1,12 +1,81 @@ using System; +using System.Collections; +using System.Collections.Generic; namespace TowersOfHanoi { class Program { - static void Main(string[] args) + Game game = new Game(); + } + class Block + { + int Weight {public get; private set; } + } + class Tower + { + Stack blocks = new Stack(); + + } + class Game + { + Dictionary towers = new Dictionary(); + + public Game() { - Console.WriteLine("Hello World!"); + towers.Add("A", new Tower()); + towers.Add("B", new Tower()); + towers.Add("C", new Tower()); + + Block block1 = new Block(); + Block block2 = new Block(); + Block block3 = new Block(); + block1.Weight = 1; + block2.Weight = 10; + block3.Weight = 100; + + towers["A"].blocks.Push(block3); + towers["A"].blocks.Push(block2); + towers["A"].blocks.Push(block1); + + } + public print() + { + foreach( var towerKey in towers.Keys) + { + foreach(Block block in towers[towerKey].blocks) + { + Console.WriteLine(" Tower :" + towerKey + " Weight: " + block.weight ); + } + } + } + public MovePiece(string popOff, string pushOn) + { + Block block = towers[popOff].blocks.Pop(); + towers[pushOn].blocks.Push(block); + print(); + + } + public bool isLegal(string popOff, string pushOn) + { + if (towers[popOff].blocks.Count == 0) + { + return false; + } + if (towers[pushOn].blocks.Count == 0) + { + return true; + } + Block popOffBlock = towers[popOff].blocks.Peek(); + Block pushOnBlock = towers[pushOn].blocks.Peek(); + + if (popOffBlock.Weight > pushOnBlock.Weight) + { + return false; + + }else{ + return true; + } } } } From 9e354d7a5546d34870a6fa6bae9e5bf7f0ac3b44 Mon Sep 17 00:00:00 2001 From: d3marco31 Date: Mon, 26 Nov 2018 18:41:41 -0600 Subject: [PATCH 3/6] 2nd draft Hanoi --- TowersOfHanoi/TowersOfHanoi.cs | 83 ++++++++++++++++++++++------------ 1 file changed, 53 insertions(+), 30 deletions(-) diff --git a/TowersOfHanoi/TowersOfHanoi.cs b/TowersOfHanoi/TowersOfHanoi.cs index 728b98b0..1cbaeac0 100644 --- a/TowersOfHanoi/TowersOfHanoi.cs +++ b/TowersOfHanoi/TowersOfHanoi.cs @@ -6,55 +6,61 @@ namespace TowersOfHanoi { class Program { - Game game = new Game(); + public void Main() + { + Game game = new Game(); + CheckForWin(); + } + } class Block { - int Weight {public get; private set; } + int weight { public get; private set; } } class Tower { Stack blocks = new Stack(); - + } class Game { - Dictionary towers = new Dictionary(); + // Console.WriteLine("Which one?"); + Dictionary towers = new Dictionary(); public Game() { - towers.Add("A", new Tower()); - towers.Add("B", new Tower()); - towers.Add("C", new Tower()); - - Block block1 = new Block(); - Block block2 = new Block(); - Block block3 = new Block(); - block1.Weight = 1; - block2.Weight = 10; - block3.Weight = 100; + towers.Add("A", new Tower()); + towers.Add("B", new Tower()); + towers.Add("C", new Tower()); - towers["A"].blocks.Push(block3); - towers["A"].blocks.Push(block2); - towers["A"].blocks.Push(block1); + Block block1 = new Block(); + Block block2 = new Block(); + Block block3 = new Block(); + block1.weight = 1; + block2.weight = 10; + block3.weight = 100; + + towers["A"].blocks.Push(block3); + towers["A"].blocks.Push(block2); + towers["A"].blocks.Push(block1); } - public print() + public string print() { - foreach( var towerKey in towers.Keys) - { - foreach(Block block in towers[towerKey].blocks) - { - Console.WriteLine(" Tower :" + towerKey + " Weight: " + block.weight ); - } - } + foreach (var towerKey in towers.Keys) + { + foreach (Block block in towers[towerKey].blocks) + { + Console.WriteLine(" Tower :" + towerKey + " Weight: " + block.weight); + } + } } - public MovePiece(string popOff, string pushOn) + public string MovePiece(string popOff, string pushOn) { Block block = towers[popOff].blocks.Pop(); towers[pushOn].blocks.Push(block); print(); - + } public bool isLegal(string popOff, string pushOn) { @@ -62,20 +68,37 @@ public bool isLegal(string popOff, string pushOn) { return false; } - if (towers[pushOn].blocks.Count == 0) + if (towers[pushOn].blocks.Count == 0) { return true; } Block popOffBlock = towers[popOff].blocks.Peek(); Block pushOnBlock = towers[pushOn].blocks.Peek(); - if (popOffBlock.Weight > pushOnBlock.Weight) + if (popOffBlock.weight > pushOnBlock.weight) { return false; - }else{ + } + else + { return true; } } + public bool CheckForWin() + { + if (towers["B"].Count() || towers["C"].Count() == 4) + { + Console.WriteLine("You Won!"); + return true; + + } + else + { + return false; + } + } + } + } From d9c130d1d724d16e42a46b235f474194024d6741 Mon Sep 17 00:00:00 2001 From: d3marco31 Date: Mon, 26 Nov 2018 21:20:16 -0600 Subject: [PATCH 4/6] draft towers --- TowersOfHanoi/TowersOfHanoi.cs | 42 ++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/TowersOfHanoi/TowersOfHanoi.cs b/TowersOfHanoi/TowersOfHanoi.cs index 1cbaeac0..00e9137c 100644 --- a/TowersOfHanoi/TowersOfHanoi.cs +++ b/TowersOfHanoi/TowersOfHanoi.cs @@ -6,26 +6,26 @@ namespace TowersOfHanoi { class Program { - public void Main() + public static void Main(string[] args) { Game game = new Game(); - CheckForWin(); + game.CheckForWin(); } } - class Block + public class Block { - int weight { public get; private set; } + public int weight {get; private set;} } - class Tower + public class Tower { - Stack blocks = new Stack(); + public Stack blocks = new Stack(); } - class Game + public class Game { // Console.WriteLine("Which one?"); - Dictionary towers = new Dictionary(); + public Dictionary towers = new Dictionary(); public Game() { @@ -33,18 +33,30 @@ public Game() towers.Add("B", new Tower()); towers.Add("C", new Tower()); - Block block1 = new Block(); - Block block2 = new Block(); - Block block3 = new Block(); - block1.weight = 1; - block2.weight = 10; - block3.weight = 100; + Block block1 = new Block(10); + Block block2 = new Block(20); + Block block3 = new Block(30); + + towers["A"].blocks.Push(block3); towers["A"].blocks.Push(block2); towers["A"].blocks.Push(block1); + Console.WriteLine("How many blocks would you like?"); + Console.ReadLine(); + int NumbOfblocks = Console.ReadLine(); + Console.WriteLine("What tower do you pick?"); + Console.ReadLine(); + + + foreach(int block in NumbOfblocks) + { + count++; + + } } + public string print() { foreach (var towerKey in towers.Keys) @@ -87,7 +99,7 @@ public bool isLegal(string popOff, string pushOn) } public bool CheckForWin() { - if (towers["B"].Count() || towers["C"].Count() == 4) + if (towers["B"].blocks.Count || towers["C"].blocks.Count == 4) { Console.WriteLine("You Won!"); return true; From 3da864280ec884c4a9b64e4a4487330be1e2c4b3 Mon Sep 17 00:00:00 2001 From: d3marco31 Date: Sat, 1 Dec 2018 11:12:35 -0600 Subject: [PATCH 5/6] 2nd draft --- Linq/Linq.cs | 13 ++++++++++- TowersOfHanoi/TowersOfHanoi.cs | 40 ++++++++++++++++++---------------- 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/Linq/Linq.cs b/Linq/Linq.cs index 6cabb44e..5cb21bb0 100644 --- a/Linq/Linq.cs +++ b/Linq/Linq.cs @@ -6,7 +6,18 @@ class Program { static void Main(string[] args) { - Console.WriteLine("Hello World!"); + int[] numbers = new int[20]; + + for (int i = 0; i < numbers; i++; ) + } + { + numbers[i] = randomGenerator.Next(0, 1000); + } + foreach (int n in numbers) + { + Console.WriteLine(n); + } + } } } diff --git a/TowersOfHanoi/TowersOfHanoi.cs b/TowersOfHanoi/TowersOfHanoi.cs index 00e9137c..1212ac91 100644 --- a/TowersOfHanoi/TowersOfHanoi.cs +++ b/TowersOfHanoi/TowersOfHanoi.cs @@ -15,7 +15,13 @@ public static void Main(string[] args) } public class Block { - public int weight {get; private set;} + public int Weight {get; private set;} + + public Block(int initalWeight) + { + this.Weight = initalWeight; + + } } public class Tower { @@ -33,45 +39,41 @@ public Game() towers.Add("B", new Tower()); towers.Add("C", new Tower()); + Block block1 = new Block(10); Block block2 = new Block(20); Block block3 = new Block(30); - - towers["A"].blocks.Push(block3); towers["A"].blocks.Push(block2); towers["A"].blocks.Push(block1); Console.WriteLine("How many blocks would you like?"); - Console.ReadLine(); - int NumbOfblocks = Console.ReadLine(); - Console.WriteLine("What tower do you pick?"); - Console.ReadLine(); + var NumOfBLocks = Console.ReadLine(); + // Console.WriteLine("What tower do you pick?"); + // Console.ReadLine(); - foreach(int block in NumbOfblocks) - { - count++; - - } } - - public string print() + + public void printBoard() { foreach (var towerKey in towers.Keys) { foreach (Block block in towers[towerKey].blocks) { - Console.WriteLine(" Tower :" + towerKey + " Weight: " + block.weight); + + Console.WriteLine(" Tower :" + towerKey + " Weight: " + block.Weight); + + } } } - public string MovePiece(string popOff, string pushOn) + public void MovePiece(string popOff, string pushOn) { Block block = towers[popOff].blocks.Pop(); towers[pushOn].blocks.Push(block); - print(); + printBoard(); } public bool isLegal(string popOff, string pushOn) @@ -87,7 +89,7 @@ public bool isLegal(string popOff, string pushOn) Block popOffBlock = towers[popOff].blocks.Peek(); Block pushOnBlock = towers[pushOn].blocks.Peek(); - if (popOffBlock.weight > pushOnBlock.weight) + if (popOffBlock.Weight > pushOnBlock.Weight) { return false; @@ -99,7 +101,7 @@ public bool isLegal(string popOff, string pushOn) } public bool CheckForWin() { - if (towers["B"].blocks.Count || towers["C"].blocks.Count == 4) + if (towers["B"].blocks.Count == 4 || towers["C"].blocks.Count == 4) { Console.WriteLine("You Won!"); return true; From b0425d12cde7bb90300a3f207c05752a2dee42e7 Mon Sep 17 00:00:00 2001 From: d3marco31 Date: Thu, 6 Dec 2018 21:44:42 -0600 Subject: [PATCH 6/6] 2nd update --- TowersOfHanoi/TowersOfHanoi.cs | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/TowersOfHanoi/TowersOfHanoi.cs b/TowersOfHanoi/TowersOfHanoi.cs index 1212ac91..bfe532c0 100644 --- a/TowersOfHanoi/TowersOfHanoi.cs +++ b/TowersOfHanoi/TowersOfHanoi.cs @@ -27,6 +27,7 @@ public class Tower { public Stack blocks = new Stack(); + } public class Game { @@ -48,26 +49,36 @@ public Game() towers["A"].blocks.Push(block2); towers["A"].blocks.Push(block1); - Console.WriteLine("How many blocks would you like?"); - var NumOfBLocks = Console.ReadLine(); + while (CheckForWin()) + { + + Console.WriteLine(printBoard()); + + } + + // Console.WriteLine("How many blocks would you like?"); + // var NumOfBLocks = Console.ReadLine(); // Console.WriteLine("What tower do you pick?"); // Console.ReadLine(); } - public void printBoard() + public string printBoard() { + string board = ""; foreach (var towerKey in towers.Keys) { foreach (Block block in towers[towerKey].blocks) { - Console.WriteLine(" Tower :" + towerKey + " Weight: " + block.Weight); - + board += " Tower :" + towerKey + " Weight: " + block.Weight; + + } } + return board; } public void MovePiece(string popOff, string pushOn) {