Skip to content

Commit 4aadb20

Browse files
ClémentClément
authored andcommitted
Tidied code.
1 parent 671ec94 commit 4aadb20

8 files changed

Lines changed: 77 additions & 46 deletions

File tree

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
1-
class Computer{
2-
private string brand;
3-
public void SetBrand(string brandP){ brand = brandP; }
4-
public Computer(string bP){ SetBrand(bP); }
5-
public override string ToString(){ return $"Brand: {brand}"; }
1+
class Computer
2+
{
3+
private string brand;
4+
5+
public void SetBrand(string brandP)
6+
{
7+
brand = brandP;
8+
}
9+
10+
public Computer(string bP)
11+
{
12+
SetBrand(bP);
13+
}
14+
15+
public override string ToString()
16+
{
17+
return $"Brand: {brand}";
18+
}
619
}
Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
1-
class Laptop : Computer{
2-
public int ScreenSize{get; set;}
3-
public Laptop(int ssP, string bP):base(bP){ScreenSize = ssP;}
4-
public override string ToString(){ return base.ToString() + $"\nScreen size: {ScreenSize}\""; }
1+
class Laptop : Computer
2+
{
3+
public int ScreenSize { get; set; }
4+
5+
public Laptop(int ssP, string bP)
6+
: base(bP)
7+
{
8+
ScreenSize = ssP;
9+
}
10+
11+
public override string ToString()
12+
{
13+
return base.ToString()
14+
+ $"\nScreen size: {ScreenSize}\"";
15+
}
516
}
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
using System;
22

3-
public class Program{
4-
public static void Main(){
5-
Computer test1 = new Computer("Framework");
6-
Console.WriteLine(test1);
7-
Laptop test2 = new Laptop(12, "ThinkPenguin");
8-
Console.WriteLine(test2);
9-
10-
}
11-
3+
public class Program
4+
{
5+
public static void Main()
6+
{
7+
Computer test1 = new Computer("Framework");
8+
Console.WriteLine(test1);
9+
Laptop test2 = new Laptop(12, "ThinkPenguin");
10+
Console.WriteLine(test2);
11+
}
1212
}
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
class Class2 : Class1
22
{
3-
public string Property2 { get; set; }
4-
5-
public Class2(string p1P, string p2P, string a1P){
6-
base.SetAttribute1(a1P);
7-
// The following would not work.
8-
// attribute1 = a1P;
9-
base.Property1 = p1P;
10-
Property2 = p2P;
11-
}
3+
public string Property2 { get; set; }
4+
5+
public Class2(string p1P, string p2P, string a1P)
6+
{
7+
base.SetAttribute1(a1P);
8+
// The following would not work.
9+
// attribute1 = a1P;
10+
base.Property1 = p1P;
11+
Property2 = p2P;
12+
}
1213
}

source/code/projects/Polymorphism1/Polymorphism1/Program.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ static void Main()
66
object1.SetAttribute1("Test");
77
object1.Property1 = "Test";
88

9-
Class2 object2 = new Class2("property1", "property2", "attribute1");
9+
Class2 object2 = new Class2(
10+
"property1",
11+
"property2",
12+
"attribute1"
13+
);
1014
object2.SetAttribute1("Attribute1");
1115
object2.Property1 = "Property1";
1216
object2.Property2 = "Property2";

source/code/projects/ReferenceMethods/ReferenceMethods/Program.cs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,37 @@ class Program
55
static void Main(string[] args)
66
{
77
// Example for AddR
8-
static void AddR(ref int a, ref int b){
8+
static void AddR(ref int a, ref int b)
9+
{
910
int tmp = a;
1011
a = a + b;
1112
b = tmp - b;
1213
}
13-
14-
int x = 4, y = 3;
14+
15+
int x = 4,
16+
y = 3;
1517
Console.WriteLine($"x is {x}, y is {y}.");
1618
AddR(ref x, ref y);
1719
Console.WriteLine($"x is {x}, y is {y}.");
1820
// End of AddR example
19-
21+
2022
/*
2123
// This Test1 method would not compile
2224
static void Test1(int a, out int b){
2325
if (a > 0) { b = 12; }
2426
}
2527
// Uncomment Test1 to see for yourself.
2628
*/
27-
29+
2830
/*
2931
// This Test2 method would not compile
3032
static void Test2(int a, out int b){
3133
if (b < 0) { b = a; }
3234
else { b = 10;}
3335
}
3436
// Uncomment Test2 to see for yourself.
35-
*/
36-
37+
*/
38+
3739
// Example for NameChange
3840
static void NameChange(
3941
ref string nameP,
@@ -45,8 +47,8 @@ out string oldnameP
4547
nameP = newnameP;
4648
}
4749
// End of NameChange example
48-
49-
string name = "Smith";
50+
51+
string name = "Smith";
5052
// This previous string is assumed given.
5153
string oldname;
5254
Console.WriteLine("Enter new name.");
@@ -55,25 +57,25 @@ out string oldnameP
5557
$"New name: {name}\nOld name: {oldname}"
5658
);
5759
// End of NameChange usage example
58-
60+
5961
// Example for AddLog
6062
string log;
6163
int x1 = 4,
62-
y1 = 3;
64+
y1 = 3;
6365
int result = AddLog(x1, y1, out log);
6466
Console.WriteLine(log + "\n" + result);
65-
67+
6668
// Solution for AddLog
6769
int AddLog(int xP1, int yP1, out string logP)
6870
{
6971
logP = xP1 + " + " + yP1 + " = " + (xP1 + yP1) + ".";
7072
return xP1 + yP1;
7173
}
72-
74+
7375
// AddReset example
7476
int x2 = 2,
75-
y2 = 3,
76-
z2;
77+
y2 = 3,
78+
z2;
7779
AddReset(ref x2, ref y2, out z2);
7880
Console.WriteLine($"x2 = {x2}, y2 = {y2}, z2 = {z2}.");
7981
// Solution for AddReset
@@ -85,5 +87,4 @@ void AddReset(ref int xP2, ref int yP2, out int zP2)
8587
}
8688
// Done with AddReset
8789
}
88-
8990
}

source/code/projects/Vehicle/Vehicle/Bike.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ public class Bike : Vehicle
55
public Bike()
66
{
77
ForkLength = -1;
8-
SetNOW(2);
9-
// or
8+
SetNOW(2);
9+
// or
1010
// base.SetNOW(2);
1111
}
1212

source/code/projects/Vehicle/Vehicle/Vehicle.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
23
public class Vehicle
34
{
45
public string Color { get; set; }

0 commit comments

Comments
 (0)