// Sample Solution
///////////////////////////////////////////////////
// Program.cs code
using System;
namespace StaticMembers
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(Forest.ForestsCreated);
Forest f = new Forest("Forest F");
Forest g = new Forest("Forest G");
Console.WriteLine(Forest.ForestsCreated);
}
}
}
Quotes help make search much faster. Example: "Practice Makes Perfect"
Showing posts with label Learn C#. Show all posts
Showing posts with label Learn C#. Show all posts
Wednesday, September 4, 2019
Codecademy Common Static Errors 6/8
// Sample Solution
///////////////////////////////////////////////////
// Forest.cs code
using System;
namespace StaticMembers
{
class Forest
{
// FIELDS
public int age;
private string biome;
private static int forestsCreated;
private static string treeFacts;
// CONSTRUCTORS
public Forest(string name, string biome)
{
this.Name = name;
this.Biome = biome;
Age = 0;
ForestsCreated++;
}
public Forest(string name) : this(name, "Unknown")
{ }
static Forest()
{
treeFacts = "Forests provide a diversity of ecosystem services including:\r\n aiding in regulating climate.\r\n purifying water.\r\n mitigating natural hazards such as floods.\n";
ForestsCreated = 0;
}
// PROPERTIES
public string Name
{ get; set; }
public int Trees
{ get; set; }
public string Biome
{
get { return biome; }
set
{
if (value == "Tropical" ||
value == "Temperate" ||
value == "Boreal")
{
biome = value;
}
else
{
biome = "Unknown";
}
}
}
public int Age
{
get { return age; }
private set { age = value; }
}
public static int ForestsCreated
{
get { return forestsCreated; }
private set { forestsCreated = value; }
}
public static string TreeFacts
{
get { return treeFacts; }
}
// METHODS
public int Grow()
{
Trees += 30;
Age += 1;
return Trees;
}
public int Burn()
{
Trees -= 20;
Age += 1;
return Trees;
}
public static void PrintTreeFacts()
{
Console.WriteLine(TreeFacts);
}
}
}
///////////////////////////////////////////////////
// Program.cs code
using System;
namespace StaticMembers
{
class Program
{
static void Main(string[] args)
{
Forest f = new Forest("Congo", "Tropical");
f.Grow();
Console.WriteLine(Forest.TreeFacts);
}
}
}
///////////////////////////////////////////////////
// Forest.cs code
using System;
namespace StaticMembers
{
class Forest
{
// FIELDS
public int age;
private string biome;
private static int forestsCreated;
private static string treeFacts;
// CONSTRUCTORS
public Forest(string name, string biome)
{
this.Name = name;
this.Biome = biome;
Age = 0;
ForestsCreated++;
}
public Forest(string name) : this(name, "Unknown")
{ }
static Forest()
{
treeFacts = "Forests provide a diversity of ecosystem services including:\r\n aiding in regulating climate.\r\n purifying water.\r\n mitigating natural hazards such as floods.\n";
ForestsCreated = 0;
}
// PROPERTIES
public string Name
{ get; set; }
public int Trees
{ get; set; }
public string Biome
{
get { return biome; }
set
{
if (value == "Tropical" ||
value == "Temperate" ||
value == "Boreal")
{
biome = value;
}
else
{
biome = "Unknown";
}
}
}
public int Age
{
get { return age; }
private set { age = value; }
}
public static int ForestsCreated
{
get { return forestsCreated; }
private set { forestsCreated = value; }
}
public static string TreeFacts
{
get { return treeFacts; }
}
// METHODS
public int Grow()
{
Trees += 30;
Age += 1;
return Trees;
}
public int Burn()
{
Trees -= 20;
Age += 1;
return Trees;
}
public static void PrintTreeFacts()
{
Console.WriteLine(TreeFacts);
}
}
}
///////////////////////////////////////////////////
// Program.cs code
using System;
namespace StaticMembers
{
class Program
{
static void Main(string[] args)
{
Forest f = new Forest("Congo", "Tropical");
f.Grow();
Console.WriteLine(Forest.TreeFacts);
}
}
}
Codecademy Static Classes 5/8
// Sample Solution
using System;
namespace StaticMembers
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(Math.PI);
Console.WriteLine(Math.Abs(-32));
}
}
}
using System;
namespace StaticMembers
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(Math.PI);
Console.WriteLine(Math.Abs(-32));
}
}
}
Codecademy Static Constructors 4/8
// Sample Solution
///////////////////////////////////////////////////
// Forest.cs code
using System;
namespace StaticMembers
{
class Forest
{
// FIELDS
public int age;
private string biome;
private static int forestsCreated;
private static string treeFacts;
// CONSTRUCTORS
static Forest()
{
treeFacts = "Forests provide a diversity of ecosystem services including:\r\n aiding in regulating climate.\r\n purifying water.\r\n mitigating natural hazards such as floods.\n";
ForestsCreated = 0;
}
public Forest(string name, string biome)
{
this.Name = name;
this.Biome = biome;
Age = 0;
ForestsCreated++;
}
public Forest(string name) : this(name, "Unknown")
{ }
// PROPERTIES
public string Name
{ get; set; }
public int Trees
{ get; set; }
public string Biome
{
get { return biome; }
set
{
if (value == "Tropical" ||
value == "Temperate" ||
value == "Boreal")
{
biome = value;
}
else
{
biome = "Unknown";
}
}
}
public int Age
{
get { return age; }
private set { age = value; }
}
public static int ForestsCreated
{
get { return forestsCreated; }
private set { forestsCreated = value; }
}
public static string TreeFacts
{
get { return treeFacts; }
}
// METHODS
public int Grow()
{
Trees += 30;
Age += 1;
return Trees;
}
public int Burn()
{
Trees -= 20;
Age += 1;
return Trees;
}
public static void PrintTreeFacts()
{
Console.WriteLine(TreeFacts);
}
}
}
///////////////////////////////////////////////////
// Program.cs code
using System;
namespace StaticMembers
{
class Program
{
static void Main(string[] args)
{
Forest.PrintTreeFacts();
}
}
}
///////////////////////////////////////////////////
// Forest.cs code
using System;
namespace StaticMembers
{
class Forest
{
// FIELDS
public int age;
private string biome;
private static int forestsCreated;
private static string treeFacts;
// CONSTRUCTORS
static Forest()
{
treeFacts = "Forests provide a diversity of ecosystem services including:\r\n aiding in regulating climate.\r\n purifying water.\r\n mitigating natural hazards such as floods.\n";
ForestsCreated = 0;
}
public Forest(string name, string biome)
{
this.Name = name;
this.Biome = biome;
Age = 0;
ForestsCreated++;
}
public Forest(string name) : this(name, "Unknown")
{ }
// PROPERTIES
public string Name
{ get; set; }
public int Trees
{ get; set; }
public string Biome
{
get { return biome; }
set
{
if (value == "Tropical" ||
value == "Temperate" ||
value == "Boreal")
{
biome = value;
}
else
{
biome = "Unknown";
}
}
}
public int Age
{
get { return age; }
private set { age = value; }
}
public static int ForestsCreated
{
get { return forestsCreated; }
private set { forestsCreated = value; }
}
public static string TreeFacts
{
get { return treeFacts; }
}
// METHODS
public int Grow()
{
Trees += 30;
Age += 1;
return Trees;
}
public int Burn()
{
Trees -= 20;
Age += 1;
return Trees;
}
public static void PrintTreeFacts()
{
Console.WriteLine(TreeFacts);
}
}
}
///////////////////////////////////////////////////
// Program.cs code
using System;
namespace StaticMembers
{
class Program
{
static void Main(string[] args)
{
Forest.PrintTreeFacts();
}
}
}
Codecademy Static Methods 3/8
// Sample Solution
///////////////////////////////////////////////////
// Forest.cs code
using System;
namespace StaticMembers
{
class Forest
{
// FIELDS
public int age;
private string biome;
private static int forestsCreated;
private static string treeFacts;
// CONSTRUCTORS
public Forest(string name, string biome)
{
this.Name = name;
this.Biome = biome;
Age = 0;
ForestsCreated++;
}
public Forest(string name) : this(name, "Unknown")
{ }
// PROPERTIES
public string Name
{ get; set; }
public int Trees
{ get; set; }
public string Biome
{
get { return biome; }
set
{
if (value == "Tropical" ||
value == "Temperate" ||
value == "Boreal")
{
biome = value;
}
else
{
biome = "Unknown";
}
}
}
public int Age
{
get { return age; }
private set { age = value; }
}
public static int ForestsCreated
{
get { return forestsCreated; }
private set { forestsCreated = value; }
}
public static string TreeFacts
{
get { return treeFacts; }
}
// METHODS
public int Grow()
{
Trees += 30;
Age += 1;
return Trees;
}
public int Burn()
{
Trees -= 20;
Age += 1;
return Trees;
}
public static void PrintTreeFacts()
{
Console.WriteLine(TreeFacts);
}
}
}
///////////////////////////////////////////////////
// Forest.cs code
using System;
namespace StaticMembers
{
class Forest
{
// FIELDS
public int age;
private string biome;
private static int forestsCreated;
private static string treeFacts;
// CONSTRUCTORS
public Forest(string name, string biome)
{
this.Name = name;
this.Biome = biome;
Age = 0;
ForestsCreated++;
}
public Forest(string name) : this(name, "Unknown")
{ }
// PROPERTIES
public string Name
{ get; set; }
public int Trees
{ get; set; }
public string Biome
{
get { return biome; }
set
{
if (value == "Tropical" ||
value == "Temperate" ||
value == "Boreal")
{
biome = value;
}
else
{
biome = "Unknown";
}
}
}
public int Age
{
get { return age; }
private set { age = value; }
}
public static int ForestsCreated
{
get { return forestsCreated; }
private set { forestsCreated = value; }
}
public static string TreeFacts
{
get { return treeFacts; }
}
// METHODS
public int Grow()
{
Trees += 30;
Age += 1;
return Trees;
}
public int Burn()
{
Trees -= 20;
Age += 1;
return Trees;
}
public static void PrintTreeFacts()
{
Console.WriteLine(TreeFacts);
}
}
}
Codecademy Static Fields and Properties 2/8
// Sample Solution
///////////////////////////////////////////////////
// Forest.cs code
using System;
namespace StaticMembers
{
class Forest
{
// FIELDS
public int age;
private string biome;
private static int forestsCreated;
public static int ForestsCreated
{
get { return forestsCreated; }
private set { forestsCreated = value; }
}
// CONSTRUCTORS
public Forest(string name, string biome)
{
this.Name = name;
this.Biome = biome;
Age = 0;
ForestsCreated++;
}
public Forest(string name) : this(name, "Unknown")
{ }
// PROPERTIES
public string Name
{ get; set; }
public int Trees
{ get; set; }
public string Biome
{
get { return biome; }
set
{
if (value == "Tropical" ||
value == "Temperate" ||
value == "Boreal")
{
biome = value;
}
else
{
biome = "Unknown";
}
}
}
public int Age
{
get { return age; }
private set { age = value; }
}
// METHODS
public int Grow()
{
Trees += 30;
Age += 1;
return Trees;
}
public int Burn()
{
Trees -= 20;
Age += 1;
return Trees;
}
}
}
///////////////////////////////////////////////////
// Forest.cs code
using System;
namespace StaticMembers
{
class Forest
{
// FIELDS
public int age;
private string biome;
private static int forestsCreated;
public static int ForestsCreated
{
get { return forestsCreated; }
private set { forestsCreated = value; }
}
// CONSTRUCTORS
public Forest(string name, string biome)
{
this.Name = name;
this.Biome = biome;
Age = 0;
ForestsCreated++;
}
public Forest(string name) : this(name, "Unknown")
{ }
// PROPERTIES
public string Name
{ get; set; }
public int Trees
{ get; set; }
public string Biome
{
get { return biome; }
set
{
if (value == "Tropical" ||
value == "Temperate" ||
value == "Boreal")
{
biome = value;
}
else
{
biome = "Unknown";
}
}
}
public int Age
{
get { return age; }
private set { age = value; }
}
// METHODS
public int Grow()
{
Trees += 30;
Age += 1;
return Trees;
}
public int Burn()
{
Trees -= 20;
Age += 1;
return Trees;
}
}
}
Codecademy Review 12/12
// Sample Solution
///////////////////////////////////////////////////
// Program.cs code
using System;
namespace BasicClasses
{
class Program
{
static void Main(string[] args)
{
Forest f = new Forest("Amazon");
Console.WriteLine(f.Trees);
f.Grow();
Console.WriteLine(f.Trees);
}
}
}
///////////////////////////////////////////////////
// Program.cs code
using System;
namespace BasicClasses
{
class Program
{
static void Main(string[] args)
{
Forest f = new Forest("Amazon");
Console.WriteLine(f.Trees);
f.Grow();
Console.WriteLine(f.Trees);
}
}
}
Codecademy Overloading Constructors 11/12
// Sample Solution
///////////////////////////////////////////////////
// Forest.cs code
using System;
namespace BasicClasses
{
class Forest
{
public int age;
private string biome;
public Forest(string name, string biome)
{
this.Name = name;
this.Biome = biome;
Age = 0;
}
//Second constructor
public Forest(string name) : this(name, "Unknown")
{
Console.WriteLine("Biome property not specified. Value defaulted to 'Unknown'.");
}
public string Name
{ get; set; }
public int Trees
{ get; set; }
public string Biome
{
get { return biome; }
set
{
if (value == "Tropical" ||
value == "Temperate" ||
value == "Boreal")
{
biome = value;
}
else
{
biome = "Unknown";
}
}
}
public int Age
{
get { return age; }
private set { age = value; }
}
public int Grow()
{
Trees += 30;
Age += 1;
return Trees;
}
public int Burn()
{
Trees -= 20;
Age += 1;
return Trees;
}
}
}
///////////////////////////////////////////////////
// Program.cs code
using System;
namespace BasicClasses
{
class Program
{
static void Main(string[] args)
{
Forest f = new Forest("Congo", "Tropical");
f.Trees = 0;
Console.WriteLine(f.Name);
Console.WriteLine(f.Biome);
Forest g = new Forest("Rendlesham");
Console.WriteLine(g.Biome);
}
}
}
///////////////////////////////////////////////////
// Forest.cs code
using System;
namespace BasicClasses
{
class Forest
{
public int age;
private string biome;
public Forest(string name, string biome)
{
this.Name = name;
this.Biome = biome;
Age = 0;
}
//Second constructor
public Forest(string name) : this(name, "Unknown")
{
Console.WriteLine("Biome property not specified. Value defaulted to 'Unknown'.");
}
public string Name
{ get; set; }
public int Trees
{ get; set; }
public string Biome
{
get { return biome; }
set
{
if (value == "Tropical" ||
value == "Temperate" ||
value == "Boreal")
{
biome = value;
}
else
{
biome = "Unknown";
}
}
}
public int Age
{
get { return age; }
private set { age = value; }
}
public int Grow()
{
Trees += 30;
Age += 1;
return Trees;
}
public int Burn()
{
Trees -= 20;
Age += 1;
return Trees;
}
}
}
///////////////////////////////////////////////////
// Program.cs code
using System;
namespace BasicClasses
{
class Program
{
static void Main(string[] args)
{
Forest f = new Forest("Congo", "Tropical");
f.Trees = 0;
Console.WriteLine(f.Name);
Console.WriteLine(f.Biome);
Forest g = new Forest("Rendlesham");
Console.WriteLine(g.Biome);
}
}
}
Codecademy Constructors 10/12
// Sample Solution
///////////////////////////////////////////////////
// Forest.cs code
using System;
namespace BasicClasses
{
class Forest
{
public int age;
private string biome;
public Forest(string name, string biome)
{
this.Name = name;
this.Biome = biome;
Age = 0;
}
public string Name
{ get; set; }
public int Trees
{ get; set; }
public string Biome
{
get { return biome; }
set
{
if (value == "Tropical" ||
value == "Temperate" ||
value == "Boreal")
{
biome = value;
}
else
{
biome = "Unknown";
}
}
}
public int Age
{
get { return age; }
private set { age = value; }
}
public int Grow()
{
Trees += 30;
Age += 1;
return Trees;
}
public int Burn()
{
Trees -= 20;
Age += 1;
return Trees;
}
}
}
///////////////////////////////////////////////////
// Forest.cs code
using System;
namespace BasicClasses
{
class Forest
{
public int age;
private string biome;
public Forest(string name, string biome)
{
this.Name = name;
this.Biome = biome;
Age = 0;
}
public string Name
{ get; set; }
public int Trees
{ get; set; }
public string Biome
{
get { return biome; }
set
{
if (value == "Tropical" ||
value == "Temperate" ||
value == "Boreal")
{
biome = value;
}
else
{
biome = "Unknown";
}
}
}
public int Age
{
get { return age; }
private set { age = value; }
}
public int Grow()
{
Trees += 30;
Age += 1;
return Trees;
}
public int Burn()
{
Trees -= 20;
Age += 1;
return Trees;
}
}
}
Codecademy Constructors 9/12
// Sample Solution
///////////////////////////////////////////////////
// Forest.cs code
using System;
namespace BasicClasses
{
class Forest
{
public int age;
private string biome;
public string Name
{ get; set; }
public int Trees
{ get; set; }
public string Biome
{
get { return biome; }
set
{
if (value == "Tropical" ||
value == "Temperate" ||
value == "Boreal")
{
biome = value;
}
else
{
biome = "Unknown";
}
}
}
public int Age
{
get { return age; }
private set { age = value; }
}
public int Grow()
{
Trees += 30;
Age += 1;
return Trees;
}
public int Burn()
{
Trees -= 20;
Age += 1;
return Trees;
}
public Forest(string name, string biome)
{
Name = name;
Biome = biome;
Age = 0;
}
}
}
///////////////////////////////////////////////////
// Program.cs code
using System;
namespace BasicClasses
{
class Program
{
static void Main(string[] args)
{
Forest f = new Forest("Congo", "Tropical");
f.Trees = 0;
Console.WriteLine(f.Name);
Console.WriteLine(f.Biome);
}
}
}
///////////////////////////////////////////////////
// Forest.cs code
using System;
namespace BasicClasses
{
class Forest
{
public int age;
private string biome;
public string Name
{ get; set; }
public int Trees
{ get; set; }
public string Biome
{
get { return biome; }
set
{
if (value == "Tropical" ||
value == "Temperate" ||
value == "Boreal")
{
biome = value;
}
else
{
biome = "Unknown";
}
}
}
public int Age
{
get { return age; }
private set { age = value; }
}
public int Grow()
{
Trees += 30;
Age += 1;
return Trees;
}
public int Burn()
{
Trees -= 20;
Age += 1;
return Trees;
}
public Forest(string name, string biome)
{
Name = name;
Biome = biome;
Age = 0;
}
}
}
///////////////////////////////////////////////////
// Program.cs code
using System;
namespace BasicClasses
{
class Program
{
static void Main(string[] args)
{
Forest f = new Forest("Congo", "Tropical");
f.Trees = 0;
Console.WriteLine(f.Name);
Console.WriteLine(f.Biome);
}
}
}
Codecademy Methods 8/12
// Sample Solution
///////////////////////////////////////////////////
// Forest.cs code
using System;
namespace BasicClasses
{
class Forest
{
public int age;
private string biome;
public string Name
{ get; set; }
public int Trees
{ get; set; }
public string Biome
{
get { return biome; }
set
{
if (value == "Tropical" ||
value == "Temperate" ||
value == "Boreal")
{
biome = value;
}
else
{
biome = "Unknown";
}
}
}
public int Age
{
get { return age; }
private set { age = value; }
}
public int Grow()
{
Trees = Trees + 30;
Age = Age + 1;
return Trees;
}
public int Burn()
{
Trees = Trees - 20;
Age = Age + 1;
return Trees;
}
}
}
///////////////////////////////////////////////////
// Forest.cs code
using System;
namespace BasicClasses
{
class Forest
{
public int age;
private string biome;
public string Name
{ get; set; }
public int Trees
{ get; set; }
public string Biome
{
get { return biome; }
set
{
if (value == "Tropical" ||
value == "Temperate" ||
value == "Boreal")
{
biome = value;
}
else
{
biome = "Unknown";
}
}
}
public int Age
{
get { return age; }
private set { age = value; }
}
public int Grow()
{
Trees = Trees + 30;
Age = Age + 1;
return Trees;
}
public int Burn()
{
Trees = Trees - 20;
Age = Age + 1;
return Trees;
}
}
}
Codecademy Public vs. Private 6/12
// Sample Solution
using System;
///////////////////////////////////////////////////
// Forest.cs code
namespace BasicClasses
{
class Forest
{
public int age;
public string Name
{ get; set; }
public int Trees
{ get; set; }
private string Biome
{
get { return biome; }
set
{
if (value == "Tropical" ||
value == "Temperate" ||
value == "Boreal")
{
biome = value;
}
else
{
biome = "Unknown";
}
}
}
}
}
///////////////////////////////////////////////////
// Program.cs code
using System;
namespace BasicClasses
{
class Program
{
static void Main(string[] args)
{
Forest f = new Forest();
f.Name = "Congo";
f.Trees = 0;
f.age = 0;
f.Biome = "Desert";
Console.WriteLine(f.Name);
Console.WriteLine(f.Biome);
}
}
}
using System;
///////////////////////////////////////////////////
// Forest.cs code
namespace BasicClasses
{
class Forest
{
public int age;
public string Name
{ get; set; }
public int Trees
{ get; set; }
private string Biome
{
get { return biome; }
set
{
if (value == "Tropical" ||
value == "Temperate" ||
value == "Boreal")
{
biome = value;
}
else
{
biome = "Unknown";
}
}
}
}
}
///////////////////////////////////////////////////
// Program.cs code
using System;
namespace BasicClasses
{
class Program
{
static void Main(string[] args)
{
Forest f = new Forest();
f.Name = "Congo";
f.Trees = 0;
f.age = 0;
f.Biome = "Desert";
Console.WriteLine(f.Name);
Console.WriteLine(f.Biome);
}
}
}
Codecademy Automatic Properties 5/12
// Sample Solution
///////////////////////////////////////////////////
// Forest.cs code
using System;
namespace BasicClasses
{
class Forest
{
public int age;
public string biome;
public string Name { get; set; }
public int Trees { get; set; }
public string Biome
{
get { return biome; }
set
{
if (value == "Tropical" ||
value == "Temperate" ||
value == "Boreal")
{
biome = value;
}
else
{
biome = "Unknown";
}
}
}
}
}
///////////////////////////////////////////////////
// Forest.cs code
using System;
namespace BasicClasses
{
class Forest
{
public int age;
public string biome;
public string Name { get; set; }
public int Trees { get; set; }
public string Biome
{
get { return biome; }
set
{
if (value == "Tropical" ||
value == "Temperate" ||
value == "Boreal")
{
biome = value;
}
else
{
biome = "Unknown";
}
}
}
}
}
Codecademy Properties 4/12
// Sample Solution
///////////////////////////////////////////////////
// Forest.cs code
using System;
namespace BasicClasses
{
class Forest
{
public string name;
public string Name
{
get { return name; }
set { name = value; }
}
public int trees;
public int Trees
{
get { return trees; }
set { trees = value; }
}
public int age;
public string biome;
public string Biome
{
get { return biome; }
set {
if(value == "Tropical" || value == "Temperate" || value == "Boreal")
{
biome = value;
}
else
{
biome = "Unknown";
}
}
}
}
}
///////////////////////////////////////////////////
// Program.cs code
using System;
namespace BasicClasses
{
class Program
{
static void Main(string[] args)
{
Forest f = new Forest();
f.Name = "Congo";
f.Trees = 0;
f.age = 0;
f.biome = "Tropical";
Console.WriteLine(f.Name);
}
}
}
///////////////////////////////////////////////////
// Forest.cs code
using System;
namespace BasicClasses
{
class Forest
{
public string name;
public string Name
{
get { return name; }
set { name = value; }
}
public int trees;
public int Trees
{
get { return trees; }
set { trees = value; }
}
public int age;
public string biome;
public string Biome
{
get { return biome; }
set {
if(value == "Tropical" || value == "Temperate" || value == "Boreal")
{
biome = value;
}
else
{
biome = "Unknown";
}
}
}
}
}
///////////////////////////////////////////////////
// Program.cs code
using System;
namespace BasicClasses
{
class Program
{
static void Main(string[] args)
{
Forest f = new Forest();
f.Name = "Congo";
f.Trees = 0;
f.age = 0;
f.biome = "Tropical";
Console.WriteLine(f.Name);
}
}
}
Codecademy Fields 3/12
// Sample Solution
///////////////////////////////////////////////////
// Forest.cs code
using System;
namespace BasicClasses
{
class Forest
{
public string name;
public int trees;
public int age;
public string biome;
}
}
///////////////////////////////////////////////////
// Program.cs code
using System;
namespace BasicClasses
{
class Program
{
static void Main(string[] args)
{
Forest f = new Forest();
f.name = "Amazon";
f.trees = 390000000;
f.age = 55000000;
f.biome = "Yes, I think the Amazon is a biome.";
Console.WriteLine(f.name);
}
}
}
///////////////////////////////////////////////////
// Forest.cs code
using System;
namespace BasicClasses
{
class Forest
{
public string name;
public int trees;
public int age;
public string biome;
}
}
///////////////////////////////////////////////////
// Program.cs code
using System;
namespace BasicClasses
{
class Program
{
static void Main(string[] args)
{
Forest f = new Forest();
f.name = "Amazon";
f.trees = 390000000;
f.age = 55000000;
f.biome = "Yes, I think the Amazon is a biome.";
Console.WriteLine(f.name);
}
}
}
Codecademy Making Classes 2/12
// Sample Solution
///////////////////////////////////////////////////
//Forest.cs code
using System;
namespace BasicClasses
{
class Forest{
}
}
///////////////////////////////////////////////////
//Program.cs code
using System;
namespace BasicClasses
{
class Program
{
static void Main(string[] args)
{
Forest f = new Forest();
}
}
}
///////////////////////////////////////////////////
//Forest.cs code
using System;
namespace BasicClasses
{
class Forest{
}
}
///////////////////////////////////////////////////
//Program.cs code
using System;
namespace BasicClasses
{
class Program
{
static void Main(string[] args)
{
Forest f = new Forest();
}
}
}
Codecademy Jump Statements 7/8
// Sample Solution
using System;
namespace JumpStatements
{
class Program
{
static void Main(string[] args)
{
bool buttonClick = true;
int timesGoneOff = 0;
do
{
Console.WriteLine("BLARRRRR");
timesGoneOff++;
if(timesGoneOff==3){
break;
}
} while(!buttonClick);
}
}
}
using System;
namespace JumpStatements
{
class Program
{
static void Main(string[] args)
{
bool buttonClick = true;
int timesGoneOff = 0;
do
{
Console.WriteLine("BLARRRRR");
timesGoneOff++;
if(timesGoneOff==3){
break;
}
} while(!buttonClick);
}
}
}
Codecademy Comparing Loops 6/8
// Sample Solution
using System;
namespace ComparingLoops
{
class Program
{
static void Main(string[] args)
{
string[] websites = { "twitter", "facebook", "gmail" };
foreach(string website in websites)
{
Console.WriteLine(website);
}
}
}
}
using System;
namespace ComparingLoops
{
class Program
{
static void Main(string[] args)
{
string[] websites = { "twitter", "facebook", "gmail" };
foreach(string website in websites)
{
Console.WriteLine(website);
}
}
}
}
Codecademy For Each Loop 5/8
// Sample Solution
using System;
namespace ForEachLoop
{
class Program
{
static void Main(string[] args)
{
string[] todo = { "respond to email", "make wireframe", "program feature", "fix bugs" };
foreach(string item in todo)
{
CreateTodoItem(item);
}
}
static void CreateTodoItem(string item)
{
Console.WriteLine($"[] {item}");
}
}
}
using System;
namespace ForEachLoop
{
class Program
{
static void Main(string[] args)
{
string[] todo = { "respond to email", "make wireframe", "program feature", "fix bugs" };
foreach(string item in todo)
{
CreateTodoItem(item);
}
}
static void CreateTodoItem(string item)
{
Console.WriteLine($"[] {item}");
}
}
}
Codecademy For Loop 4/8
// Sample Solution
using System;
namespace ForLoop
{
class Program
{
static void Main(string[] args)
{
for(int x=1; x<=16; x++)
{
CreateTemplate(x);
}
}
static void CreateTemplate(int week)
{
Console.WriteLine($"Week {week}");
Console.WriteLine("Announcements: \n \n \n ");
Console.WriteLine("Report Backs: \n \n \n");
Console.WriteLine("Discussion Items: \n \n \n");
}
}
}
using System;
namespace ForLoop
{
class Program
{
static void Main(string[] args)
{
for(int x=1; x<=16; x++)
{
CreateTemplate(x);
}
}
static void CreateTemplate(int week)
{
Console.WriteLine($"Week {week}");
Console.WriteLine("Announcements: \n \n \n ");
Console.WriteLine("Report Backs: \n \n \n");
Console.WriteLine("Discussion Items: \n \n \n");
}
}
}
Subscribe to:
Posts (Atom)
This is an example of scrolling text using Javascript.
Popular Posts
-
# Codecademy sample solution # What are the four commonly used HTTP methods ("verbs")? # A: FIND, SEND, UPDATE, REMOVE # B: ...
-
$("#tours > li")
-
<!--sample solution--> <html> <head> <title>Week 13 Project</title> </head> ...
-
//sample solution def isEven(x): if(x % 2 == 0): return "yep" else: return "nope"
-
<html> <head> <!-- Add the Parse SDK here! --> <script src="http://www.parsecdn.com/js/par...
-
<!-- Sample solution to index.html --> <!DOCTYPE html> <html> <body> <div class="nav"> ...
-
Answer: Alt - p p stands for previous. If you keep pressing Alt - p, you will continue cycling back through commands you typed before. I...
-
#sample solution hungry = false unless hungry puts "I'm writing Ruby programs!" else puts "Time to eat!...
-
// sample solution to panel.js $(document).ready(function(){ var $panel = $("#panel"); var $tab = $("#tab"); ...
-
//sample solution var yourName = "Pam"; var gender = "female"; var result; //Line 10 starts an if statement //Ne...