Last active
September 25, 2018 04:25
-
-
Save janellbaxter/5dbfa568afc10e7e67faef75b49ae592 to your computer and use it in GitHub Desktop.
ToastR 1.0 Example for Introduction to Programming showing classes, objects, and other concepts (in-progress)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace Toastr | |
{ | |
class Item | |
{ | |
public string Name; | |
public double Calories; | |
public double Price; | |
public string[] Ingredients = {"", "", "" }; | |
public int Available; | |
public Item() | |
{ | |
} | |
public Item(string name, double calories, double price, string[] ingredients) | |
{ | |
Name = name; | |
Calories = calories; | |
Price = price; | |
Ingredients = ingredients; | |
Available = 10; | |
} | |
public void Scream() | |
{ | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace Toastr | |
{ | |
class Order | |
{ | |
public string Name; | |
public Item[] Items = new Item[2]; | |
public int[] Quantity = { 0, 0 }; | |
public double Total; | |
public void Print() | |
{ | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace Toastr | |
{ | |
class Program | |
{ | |
//set up items | |
static string[] ingredientList = { "bread", "", "" }; | |
static string[] ingredientList2 = { "strawberry", "cheese", "" }; | |
static Item fireball = new Item("Fireball", 12.69, 2, ingredientList); | |
static Item cakecheese = new Item("CakeCheese", 2000, 30, ingredientList2); | |
static Order order = new Order(); | |
static void Main() | |
{ | |
//start up the application welcome | |
Welcome(); | |
//ask player what they want to order | |
Order(); | |
//print the order | |
//end | |
Console.ReadKey(); | |
} | |
static private void Welcome() | |
{ | |
Console.Title = "Toastr"; | |
Console.WriteLine ("Welcome to Toastr. We got toast."); | |
} | |
static void Order() | |
{ | |
//example cast - this is just to show how it could work | |
//it doesn't fit into the bakery app (yet) | |
double large = 12; | |
int medium = 50; | |
//explicit casts | |
medium = Convert.ToInt32(large); | |
medium = (int)large; | |
//implicit cast | |
large = medium; | |
string input = ""; | |
Console.WriteLine("What is your name?"); | |
order.Name = Console.ReadLine(); | |
Console.WriteLine("What would you like to order? Today we have:"); | |
Console.WriteLine("a)" + fireball.Name + "($" + fireball.Price + ")"); | |
Console.WriteLine("b)" + cakecheese.Name + "($" + cakecheese.Price + ")"); | |
Console.WriteLine("Please enter a or b:"); | |
input = Console.ReadLine(); | |
if (input == "a") | |
{ | |
order.Items[0] = fireball; | |
} | |
else | |
{ | |
order.Items[0] = cakecheese; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment