Fan.cs
using System;
namespace Fans {
class Fan {
private int speed;
private double radius;
private string color;
//default constructor
public Fan() {
this.speed = 1;
this.radius = 1.53;
this.color = "green";
}
//convenience constructor
public Fan(double newRadius) {
this.radius = newRadius;
}
public override string ToString() {
return "A " + radius + " inch " + color " fan at a speed of " + speed;
}
public int speed {
get { return speed; }
set { speed = newSpeed; }
}
public double radius {
get { return radius; }
set { radius = newRadius; }
}
public string color {
get { return color ; }
set { color = newColor; }
}
}
}
Program.cs
using System;
namespace Fans {
class Program {
static void Main(string[] args) {
Fan fan1 = new Fan();
fan1.speed = 3;
fan1.radius = 10.26;
fan1.color = "yellow";
Console.WriteLine(fan1);
}
}
}
When I attempt to compile Program.cs, I get two errors:
Program.cs(7,9): error CS0246: The type or namespace name 'Fan' could not be found (are you missing a using directive or an assembly reference?)
Program.cs(7,24): error CS0246: The type or namespace name 'Fan' could not be found (are you missing a using directive or an assembly reference?)
Both files are in the same directory. Not sure what else is wrong.
There are a few minor things to fix here.
You are missing a
+inToStringYou need to use value in your set instead of newRadius, newColor and newSpeed
You are using the same member name as your variable. In the old days we would use underscore like I have in the working example below. Consider using the new format though
Full code: