Skip to content

Instantly share code, notes, and snippets.

@janellbaxter
Created July 18, 2018 18:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janellbaxter/4662ba74972338ea92f40f1e6051e220 to your computer and use it in GitHub Desktop.
Save janellbaxter/4662ba74972338ea92f40f1e6051e220 to your computer and use it in GitHub Desktop.
Simple programming exercise example built during the second class meeting of Introduction to Programming. Concepts discussed in the walk through: namespaces, variables, data types, console window input and output, a conditional statement, class, objects, class fields, class methods, converting from one data type to another, and concatenation.
//Bumblebee.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DayTwoBumblebee
{
class Bumblebee
{
//data
public string Color = "yellow and black";
public double Size = 10;
public bool Fuzzy = true;
public string Name = "The anonymous bee";
//constructor
public Bumblebee()
{
}
public Bumblebee(string name)
{
Name = name;
}
//operations
public void Fly() {
string fuzziness = "not fuzzy";
if (Fuzzy)
{
fuzziness = "fuzzy";
}
Console.WriteLine(Name + ", which is a " + Size + " millimeter " + Color + " " + fuzziness + " bee, flies like a B6.");
}
public void Collect() { }
public void Generate() { }
public void HighFive() { }
public void Sound() { }
}
}
//Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DayTwoBumblebee
{
class Program
{
static void Main()
{
//title for the application title bar
Console.Title = "Make a Bee!";
//variables
string name;
string color;
int size;
bool fuzzy = false;
string input;
Console.WriteLine("Welcome to the \"Amazing\" Make A Bee app!");
Console.WriteLine("What would you like to name the bee?");
name = Console.ReadLine();
Console.WriteLine("Your bee will be two colors. One of those is black. What is the other color?");
color = Console.ReadLine();
color = color + " and black";
Console.WriteLine("What size (in millimeters) is your bee? Bees are usually between 10-32 millimeters.");
size = Convert.ToInt32(Console.ReadLine());
//alternatively two lines could be used:
//input = Console.ReadLine();
//size = Convert.ToInt32(input);
Console.WriteLine("Is your bee fuzzy? Please answer yes or no.");
input = Console.ReadLine();
if (input.ToLower() == "yes")
{
fuzzy = true;
}
Console.WriteLine("Your bee: " + name + " is " + color + ", and is " + size + " millimeters. " + name + "'s fuzzy state is " + fuzzy + ".");
Console.WriteLine("Press enter to continue...");
Console.ReadKey();
Console.Clear();
//create an instance of the Bumblebee class, the identifier name is bee1
//bee1 is not a very descriptive variable name - ideally we'd like better names!
Bumblebee bee1 = new Bumblebee();
bee1.Fuzzy = false;
bee1.Size = 30;
bee1.Name = "Big Meany Pants";
bee1.Color = "red and black";
//create an instance of the Bumblebee class, the identifier name is bee2
Bumblebee bee2 = new Bumblebee("Steven J. Barry");
bee1.Fly();
bee2.Fly();
Console.WriteLine("\n\nExample of concatenation of a string plus a number, and of a number:");
string score = "10";
int Score = 10;
Console.WriteLine("The score is " + (score + 1));
Console.WriteLine("The score is " + (Score + 1));
Console.ReadKey();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment