Wednesday, October 30, 2013

WPF applicarion Evening

.Here is the windows form XML

<Window x:Class="MileageApplication.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525" Name="MPGWindow">
    <Grid>
        <Label Content="Enter Beginning Mileage" HorizontalAlignment="Left" Margin="40,30,0,0" VerticalAlignment="Top"/>
        <TextBox x:Name="txtBeginMiles" HorizontalAlignment="Left" Height="23" Margin="208,30,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
        <Label Content="Enter Ending Mileage" HorizontalAlignment="Left" Margin="40,74,0,0" VerticalAlignment="Top"/>
        <TextBox x:Name="txtEndingMiles" HorizontalAlignment="Left" Height="23" Margin="208,74,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
        <Label Content="Enter Gallons" HorizontalAlignment="Left" Margin="50,116,0,0" VerticalAlignment="Top"/>
        <TextBox x:Name="txtGallons" HorizontalAlignment="Left" Height="23" Margin="208,119,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
        <Button x:Name="btnCalculate" Content="Calculate" HorizontalAlignment="Left" Margin="50,157,0,0" VerticalAlignment="Top" Width="75" Click="btnCalculate_Click"/>
        <Label x:Name="lblResult" Content="Label" HorizontalAlignment="Left" Margin="208,177,0,0" VerticalAlignment="Top" Width="131" Height="56"/>
        <Button x:Name="btnExit" Content="Exit" HorizontalAlignment="Left" Margin="50,213,0,0" VerticalAlignment="Top" Width="75" RenderTransformOrigin="-0.507,0.1" Click="btnExit_Click"/>

    </Grid>
</Window>


Here is the code behind the form

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace MileageApplication
{
    /// 
    /// Interaction logic for MainWindow.xaml
    /// 
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            MPGWindow.Background = new LinearGradientBrush(Colors.BlueViolet,
                Colors.AliceBlue, 45);
        }

        private void btnCalculate_Click(object sender, RoutedEventArgs e)
        {
            int bMiles;
            Mileage m = new Mileage();

            bool isGoodBegMiles = int.TryParse(txtBeginMiles.Text, out bMiles);
            if (isGoodBegMiles)
            {
                m.BeginMileage = bMiles;
            }
            else
            {
                MessageBox.Show("Enter a valid integer for beginning Miles");
                return;
            }

            m.EndMileage = int.Parse(txtEndingMiles.Text);
            m.Gallons = double.Parse(txtGallons.Text);
            double mpg = m.CalculateGasMileage();
            lblResult.Content = mpg.ToString();

            if (mpg > 40)
                lblResult.Background = new SolidColorBrush(Colors.Green);
            else if (mpg > 30)
                lblResult.Background = new SolidColorBrush(Colors.GreenYellow);
            else if (mpg > 20)
                lblResult.Background = new SolidColorBrush(Colors.Yellow);
            else
                lblResult.Background = new SolidColorBrush(Colors.Red);





        }

        private void btnExit_Click(object sender, RoutedEventArgs e)
        {
            Application.Current.Shutdown();
        }
    }
}


Here is the Mileage Class, the same as we had before with one change: the Namespace was changed to match the rest of the application.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MileageApplication
{
    class Mileage
    {
        //class variables or fields
        //fields should be private
        private int beginMileage;
        private int endMileage;
        private double pricePerGallon;
        private double gallons;

        //constructors are ways of constructing
        //the class, they set the initial values
        //a constructor always has the same name
        //as the the class and no return type
        //A class can have several "overloaded" constructors
        //only one is used per instance of the class
        //the user chooses which constructor he or she
        //wants to use by the signature (what parameters it takes)

        //this is a default constructor. It has no arguments
        //and sets all the properties to their minumum value;
        //If you write no constructor at all this is what you get
        //if you do write a constructor it is up to you to 
        //provide the initial values
        public Mileage()
        {
            PricePerGallon = 0;
            BeginMileage = 0;
            EndMileage = 0;
            Gallons = 0;
        }

        //this is an overloaded constructor that takes three
        //values. A user could choose to do this rather than
        //set the values using the properties
        public Mileage(int begin, int end, double gal)
        {
            BeginMileage = begin;
            EndMileage = end;
            Gallons = gal;
            PricePerGallon = 0;

        }

        //this constructor takes four values
        public Mileage(int begin, int end, double gal, double price)
        {
            BeginMileage = begin;
            EndMileage = end;
            Gallons = gal;
            PricePerGallon = price;
        }


        //public properties are ways 
        //to expose the fields in a 
        //controlled way
        //you can do some validation
        //and testing in a property
        public double PricePerGallon
        {
            get { return pricePerGallon; }
            set { pricePerGallon = value; }
        }
        

      
        public double Gallons
        {
            get { return gallons; }
            set { gallons = value; }
        }
      

      
        public int BeginMileage
        {
            get { return beginMileage; }
            set { beginMileage = value; }
        }

        public int EndMileage
        {
            get { return endMileage; }
            set { endMileage = value; }
        }

        //a class can contain both private (internal)
        //methods and public methods
        private int TotalMiles()
        {
            return EndMileage - BeginMileage;
        }

        //public method accessible from other
        //classes
        public double CalculateGasMileage()
        {
            int total = TotalMiles();
            double milesPerGallon = total / Gallons;
            return milesPerGallon;
        }

        //this is an overloaded method. It has the same
        //name but a different signature than the previous method
        //again it gives a user of the class another option
        //of how to use the class and call the method
        public double CalculateGasMileage(int bMiles, int eMiles, double gals)
        {
            BeginMileage = bMiles;
            EndMileage = eMiles;
            Gallons = gals;
            int total = TotalMiles();
            double milesPerGallon = total / Gallons;
            return milesPerGallon;


        }

        //this is "overriding" the ToString method
        //which every class inherits from Object
        //the parent of all classes in .NET
        //the combination of overloading and overwriting is 
        //what constitutes the object oriented principle of
        //polymorphism--the ability of a class
        //to behave differently in different environments
        public override string ToString()
        {
            double mpg = CalculateGasMileage();
            return "Your gas mileage is" + mpg.ToString("##.##");
        }


    }
}

Here is a picture of the application running


Tuesday, October 29, 2013

Morning Class Example 2

View the Evening class post to see commented code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ClassicExamples
{
    class Mileage
    {
        //private fields
        private int beginningMileage;
        private int endingMileage;
        private double pricePerGallon;
        private double gallons;

        public Mileage()
        {
            BeginningMileage = 0;
            EndingMileage = 0;
            Gallons = 0;
            PricePerGallon = 0;
        }

        public Mileage(int begin, int end, double gals)
        {
            BeginningMileage = begin;
            EndingMileage = end;
            Gallons = gals;
            PricePerGallon = 0;
        }

        //public properties
        public int EndingMileage
        {
            get { return endingMileage; }
            set {
                if (value > 0)
                    endingMileage = value;
                else
                {
                    endingMileage = -1;
                }
            }
        }
       

        public double Gallons
        {
            get { return gallons; }
            set { gallons = value; }
        }
       

        public double PricePerGallon
        {
            get { return pricePerGallon; }
            set { pricePerGallon = value; }
        }

      
        public int BeginningMileage
        {
            get { return beginningMileage; }
            set { beginningMileage = value; }
        }
       // public int EndingMileage { get; set; }

        //methods
        private int CalculateTotalMiles()
        {
            return EndingMileage - BeginningMileage;
        }

        public double CalculateMilesPerGallon()
        {
            int totalMiles = CalculateTotalMiles();
            double mPG = totalMiles / Gallons;
            return mPG;
        }

        public double CalculateMilesPerGallon(int begin, int end, double gals)
        {
            BeginningMileage = begin;
            EndingMileage = end;
            Gallons = gals;
            int totalMiles = CalculateTotalMiles();
            double mPG = totalMiles / Gallons;
            return mPG;

        }

        public void CalculateCostPerMile()
        {
            throw new System.NotImplementedException();
        }

        public override string ToString()
        {
            return "Your miles per gallon is " + CalculateMilesPerGallon().ToString();
        }
    }
}

Monday, October 28, 2013

Evening Mileage class Revised with comments

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ClassesExample
{
    class Mileage
    {
        //class variables or fields
        //fields should be private
        private int beginMileage;
        private int endMileage;
        private double pricePerGallon;
        private double gallons;

        //constructors are ways of constructing
        //the class, they set the initial values
        //a constructor always has the same name
        //as the the class and no return type
        //A class can have several "overloaded" constructors
        //only one is used per instance of the class
        //the user chooses which constructor he or she
        //wants to use by the signature (what parameters it takes)

        //this is a default constructor. It has no arguments
        //and sets all the properties to their minumum value;
        //If you write no constructor at all this is what you get
        //if you do write a constructor it is up to you to 
        //provide the initial values
        public Mileage()
        {
            PricePerGallon = 0;
            BeginMileage = 0;
            EndMileage = 0;
            Gallons = 0;
        }

        //this is an overloaded constructor that takes three
        //values. A user could choose to do this rather than
        //set the values using the properties
        public Mileage(int begin, int end, double gal)
        {
            BeginMileage = begin;
            EndMileage = end;
            Gallons = gal;
            PricePerGallon = 0;

        }

        //this constructor takes four values
        public Mileage(int begin, int end, double gal, double price)
        {
            BeginMileage = begin;
            EndMileage = end;
            Gallons = gal;
            PricePerGallon = price;
        }


        //public properties are ways 
        //to expose the fields in a 
        //controlled way
        //you can do some validation
        //and testing in a property
        public double PricePerGallon
        {
            get { return pricePerGallon; }
            set { pricePerGallon = value; }
        }
        

      
        public double Gallons
        {
            get { return gallons; }
            set { gallons = value; }
        }
      

      
        public int BeginMileage
        {
            get { return beginMileage; }
            set { beginMileage = value; }
        }

        public int EndMileage
        {
            get { return endMileage; }
            set { endMileage = value; }
        }

        //a class can contain both private (internal)
        //methods and public methods
        private int TotalMiles()
        {
            return EndMileage - BeginMileage;
        }

        //public method accessible from other
        //classes
        public double CalculateGasMileage()
        {
            int total = TotalMiles();
            double milesPerGallon = total / Gallons;
            return milesPerGallon;
        }

        //this is an overloaded method. It has the same
        //name but a different signature than the previous method
        //again it gives a user of the class another option
        //of how to use the class and call the method
        public double CalculateGasMileage(int bMiles, int eMiles, double gals)
        {
            BeginMileage = bMiles;
            EndMileage = eMiles;
            Gallons = gals;
            int total = TotalMiles();
            double milesPerGallon = total / Gallons;
            return milesPerGallon;


        }

        //this is "overriding" the ToString method
        //which every class inherits from Object
        //the parent of all classes in .NET
        //the combination of overloading and overwriting is 
        //what constitutes the object oriented principle of
        //polymorphism--the ability of a class
        //to behave differently in different environments
        public override string ToString()
        {
            double mpg = CalculateGasMileage();
            return "Your gas mileage is" + mpg.ToString("##.##");
        }


    }
}

Chapter five Assignments

Wednesday, October 23, 2013

First take at a class evening

Here is the Program class

  using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ClassesExample
{
    class Program
    {
        static void Main(string[] args)
        {
            //call the mileage class and make it new
            Mileage m = new Mileage();
            //for now we are just hard coding
            //values to show the point
            //here we are assigning values to the 
            //properties
            //m is the name we gave this instance of a class
            //the dot . is a membership operator
            //it shows what belongs to the Mileage class
            m.BeginMileage = 300;
            m.EndMileage = 600;
            m.Gallons = 7;
            //in the console writeline we are calling the public
            //method CalculateGasMileage()
            Console.WriteLine(m.CalculateGasMileage().ToString("#.##"));
            Console.ReadKey();
            
        }
    }
}


Here is the Mileage class --so far

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ClassesExample
{
    class Mileage
    {
        //class variables or fields
        //fields should be private
        private int beginMileage;
        private int endMileage;
        private double pricePerGallon;

        //public properties are ways 
        //to expose the fields in a 
        //controlled way
        //you can do some validation
        //and testing in a property
        public double PricePerGallon
        {
            get { return pricePerGallon; }
            set { pricePerGallon = value; }
        }
        private double gallons;

      
        public double Gallons
        {
            get { return gallons; }
            set { gallons = value; }
        }
      

      
        public int BeginMileage
        {
            get { return beginMileage; }
            set { beginMileage = value; }
        }

        public int EndMileage
        {
            get { return endMileage; }
            set { endMileage = value; }
        }

        //a class can contain both private (internal)
        //methods and public methods
        private int TotalMiles()
        {
            return EndMileage - BeginMileage;
        }

        //public method accessible from other
        //classes
        public double CalculateGasMileage()
        {
            int total = TotalMiles();
            double milesPerGallon = total / Gallons;
            return milesPerGallon;
        }
    }
}

Here is a more complete version of the showtime diagram

Tuesday, October 22, 2013

Using the Random Object

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RandomNumbers2
{
    class Program
    {
        //this program is just a demonstration
        //of using the Random object.
        //when declared at class level
        //the random actually displays
        //different numbers in the loop below.
        //first you have to make the Random
        //object new
        Random rand = new Random();
        static void Main(string[] args)
        {
            Program p = new Program();
            //call display random
            p.DisplayRandom();
            //call random loop
            p.RandomLoop();
            Console.ReadKey();
        }

        int GetRandom()
        {
            //the Next method lets you set
            //the minimum (1) and the Maximum(100)
            //bounds for the number to be returned
            return rand.Next(1, 100);
        }

        void DisplayRandom()
        {
            //just display the random number returned
            Console.WriteLine("the random number is {0}" ,GetRandom());
        }

        void RandomLoop()
        {
            //declare an array
            int[] myArray=new int[6];
            //loop through the array and add random
            //numbers for each index
            for (int i = 0; i < myArray.Length; i++)
            {
                //add random to array
                myArray[i] = GetRandom();
            }
           
            //In the foreach loop you specifiy
            //the kind (int) of object stored in the
            //array or collection and it controls
            //the number of times you loop
            //looping once for each object of that type
            //in the array
            foreach (int j in myArray)
            {
                Console.WriteLine(j);
            }
        }
    }
}

Monday, October 21, 2013

Random and while loop for validation

a bit of a mess

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RandomNumbers
{
    class Program
    {
        int number;
        Random rand;
        static void Main(string[] args)
        {
            Program p = new Program();
            p.ValidateEntry();
            Console.ReadKey();
        }

        void GenerateRandomNumber()
        {
           rand = new Random();
           number = rand.Next(1, 1000);
            
            
        }

        void PopulateArray()
        {
        //    int[] grades = new int[5];
           GenerateRandomNumber();
        //    for (int i = 0; i < 5; i++)
        //    {
        //        rand.Next(0, 4);
        //        int x = rand.Next(10000, 100000);
        //        for (int j = 0; j < x; j++)
        //        {
        //        }
        //        grades[i] = number;
        //    }
        //    ReadArray(grades);
            number = rand.Next(1, 100);
            Console.WriteLine(number);
        }

        void ReadArray(int[] grades)
        {
            foreach (int i in grades)
            {
                Console.WriteLine(i);
            }
        }

        void ValidateEntry()
        {
            int[] myArray = new int[5];
            

            for (int i = 0; i < myArray.Length; i++)
            {
                int number = -1;
                while (number < 1 || number > 500)
                {
                    Console.WriteLine("Enter a number 1 and 500");
                    number = int.Parse(Console.ReadLine());
                    if (number < 1 || number > 500)
                    {
                        Console.WriteLine("invalid numbers");
                    }
                }
                myArray[i] = number;
               
            }

            ReadArray(myArray);
        }
    }
}

First Entity Relation Diagram(ERD)

Tuesday, October 15, 2013

Arrays and loops Morning

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace loopyExample
{
    class Program
    {
        static void Main(string[] args)
        {
            Program p = new Program();
            //set up a string variable for the while loop
            string status = "yes";
            //loop as long as the status variable = "yes"
            while(status.Equals("yes"))
            {
                //call methods
                p.ArrayBasedOnVariable();
                p.CreateArray();
                p.AnotherWayToCreateAnArray();
                //check to see if user wants to continue
                Console.WriteLine("Continue yes/no");
                status = Console.ReadLine();
                
              status.ToLower();
            }
            //don't need readkey with the loop
            //Console.ReadKey();
        }

        void CreateArray()
        {
            //this just looks at how an array is structured
            //declare it with a type and []
            string[] movies = new string[4];
            //4 is the number of elements the array can contain
            //each array item is indexed
            movies[0] = "The Princess Bride";
            movies[1] = "Die Hard";
            movies[2] = "Breakfast at Tiffany's";
            movies[3] = "Galaxy Quest";
            //you can access an particular array item
            //by its index
            Console.WriteLine(movies[2]);

        }

        void AnotherWayToCreateAnArray()
        {
            //another way to declare and array
            string[] dogBreeds = new string[] { "collie", "poodle", "Labrador", "spaniel", "bull dog" };

            //a for loop to read through the array's items
            //int i is a counter we set it to 0 (all arrays begin with zero)
            //we keep looping until i is no longer less than the length
            //of the array. With every loop we increment i (add 1)
            for (int i = 0; i < dogBreeds.Length; i++)
            {
                Console.WriteLine(dogBreeds[i]);
            }
        }

        void ArrayBasedOnVariable()
        {
            //here we get the length of the array from the user
            Console.WriteLine("how many integers do you want to enter?");
            int size = int.Parse(Console.ReadLine());

            //size must have a value before you can use
            //the variable in the array
            int[] numbers=new int[size];

            //loop through the array and add numbers to it
            for (int i = 0; i < size;i++)
            {
                Console.WriteLine("enter an Integer");
                numbers[i] = int.Parse(Console.ReadLine());
           }
            Console.Clear(); //this just clears the stuff above

            //I calculate the total in two different ways
            //you only need to use one of them
            //the .Sum() and .Average() methods
            //exist only in C# . In most languages you
            //have to accumulate the values itself
            int total = 0;
            for (int i = 0; i < size;i++)
            {
               
                Console.WriteLine(numbers[i]);
                //the += is the same as total + total + numbers[i];
                total += numbers[i];
            }

            //this is the same as the Average() method
            double average = (double)total / numbers.Length;

            //this displays both sets of results. they are the same
            Console.WriteLine("total manually {0}", total);
            Console.WriteLine("Average Manually {0}", average);
            Console.WriteLine("*********************");
            Console.WriteLine("the total using Sum is {0}",numbers.Sum());
           Console.WriteLine("the average using Average is {0}",numbers.Average());


        }
    }

}

Monday, October 14, 2013

Arrays and loops

Here is the first set of array examples

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ArrayloopExample
{
    class Program
    {
        static void Main(string[] args)
        {
            Program p = new Program();
            //p. CreateArray();
           // p.CreateArray2();
           // p.CreateArrayWithVariable();
            p.CreateTwoDimensionalArray();
            Console.ReadKey();
        }

        void CreateArray()
        {
            //this creates and populates an array of movies
            string[] movies = new string[3];
            movies[0] = "Gravity";
            movies[1] = "Apollo 13";
            movies[2] = "Space Cowboys";

            Console.WriteLine("Enter a number 1 to 3");
            int number = int.Parse(Console.ReadLine());
            Console.WriteLine(movies[number - 1]);
        }

        void CreateArray2()
        {
            //this is another way to populate an array
            string[] books = new string[] { "American Gods", "Alchemist", 
                "Cat in the Hat", "IQ84", "SnowCraft" };

            Console.WriteLine("Enter a number 1 to 5");
            int number = int.Parse(Console.ReadLine());
            Console.WriteLine(books[number - 1]);
        }

        void CreateArrayWithVariable()
        {
            //this give an array a size using a variable
            //the variable must have a value before it can
            //be used in the array
            Console.WriteLine("How many items do you wish to store?");
            int number = int.Parse(Console.ReadLine());

            int[] myArray = new int[number];

            Console.WriteLine("the array has {0} elements", myArray.Length);
        }

        void CreateTwoDimensionalArray()
        {
            //this shows a 2 dimensional array
            string[,] books = new string[3, 2];
            books[0, 0] = "War and Peace";
            books[0, 1] = "Tolstoy";
            books[1, 0] = "The lord of the Rings";
            books[1, 1] = "Tolkein";
            books[2, 0] = "Enders Game";
            books[2, 1] = "Card";

            //Console.WriteLine("Select an author: Tolstoy, Tolkein or Card");
            //string author = Console.ReadLine();

            //this for loop loops through the array and displays
            //its contents in reverse (-- instead of ++)
            for (int i = 2; i >=0; i--)
            {
                //if (books[i, 1].Equals(author))
                //{
                    Console.WriteLine(books[i, 0] + ", " + books[i,1]);
                //}
            }

        }
    }
}

this one focuses more on loops

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LoopsandStuff
{
    class Program
    {

        static void Main(string[] args)
        {
            Program p = new Program();
            string status = "yes";

            //the while loop loops as long as status = yes
            while (status.Equals("yes"))
            {
            p.CreateArray();
            Console.WriteLine("Continue: yes / no");
            status = Console.ReadLine();
             status.ToLower(); //sets the reply to all lower case
            }
            //Console.ReadKey();
        }

        void CreateArray()
        {
            Console.WriteLine("How big do you want your array?");
            int size = int.Parse(Console.ReadLine());

            int[] numbers = new int[size];
//call method populate arrays and passes the array
            PopulateArray(numbers);
        }

        void PopulateArray(int[] num)
        {
            //loop through the array and add values
            for (int i = 0; i < num.Length; i++)
            {
                Console.WriteLine("Enter an integer");
                num[i] = int.Parse(Console.ReadLine());
            }
            ReadArray(num);
        }

        void ReadArray(int[] num)
        {
            Console.Clear();
         
            //loop through the array and display its contents
            for (int i=0; i < num.Length; i++)
            {
                Console.WriteLine(num[i]);
                
            }
            //use built in math functions to analyze array values
            Console.WriteLine("the sum is {0}", num.Sum());
            Console.WriteLine("the Average is {0}", num.Average());
            Console.WriteLine("the maximum value is {0}", num.Max());
            int range = num.Max() - num.Min();
            Console.WriteLine("the range is {0}", range);
           // int add = num[1] + num[2];
          //  Console.WriteLine("the sum of values 2 and 3 is {0}", add);
        }

    }
}

Requirements and Business Rules

Requirement is something a database has to do.

Data Requirements (what has to be in database)

:

It has to list local venues
(name, address, description , website? Restrictions, capacity)
It has to list acts (artists)
(name, description, genre(s), email, website?)
It has to list show times and show information
(times, date, address, restrictions, price,
admission requirements(cover charge or tickets)
Fan information
(name and email, genres and acts they are interested in)
Login table

Reporting Requirements (have to get out of database)

You must be able to:
Search venues to get lists of coming shows
Search by calendar
By area (neighborhood, city, zipcode)
By Act (name), genre,
By price (including free)
By Age restriction
Search fans who are interested in a particular genre or act
Administrative reports

Access and Security Requirements

Venues can enter and edit their own venue and
show information but they should not be able to edit or enter
for any other venue (login) (insert update)
Fans can register which means they can enter and their own
Info including bands and genres they want to follow
But nothing else (insert and update)
Artists enter and edit their own info/ genres (insert/ update)
Public can select artists, venues and shows

Admin all permission

(wish list)

Business Rules

Venues will be able to enter and edit their information and show information
Acts and fans have same rule
Local consists of defined zip codes
Only (local) artists can register
Venues (local) can list all acts at their venue even if not local
Artist list will be public
Venue list and shows will be public
Fan emails will be private
How long keep records?
Fan, artist (1 year after last show) and venue information
remains as long as accurate

Keys

Unique identifiers for each row primary key
Candidate keys (looking at data to determine which fields
Are potential keys)
Natural key—sconge01
Surrogate—auto-numbers
Composite key 3206 Fall 2013
Foreign Key
Artist

ArtistKeyArtistNameEmail
1 Adarna adrana@gmail.com

 

GenreKey ArtistKey GenreName
1 1 Alternative

Monday, October 7, 2013

Ifs and Switches

Here is the if and if else statement example

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IfStatementExamples
{
    class Program
    {
        /// 
        /// This program just shows how to use if
        /// and if else statements
        /// it also shows how to use tryParse
        /// to catch errors in entry
        /// 
        /// 
        static void Main(string[] args)
        {
            //initialize the program
            Program p = new Program();
            //call the GetTemperature method
            p.GetTemperature();
            Console.ReadKey();
        }

        void GetTemperature()
        {
            //set the temp variable
            int temp=0;
            //prompt the user
            Console.WriteLine("Enter the Temperature.");
            //this is the try parse. 
            //if the value entered on the console is a
            //valid integer it returns true to isInt and assigns
            //the value to the "out" parameter temp
            //if not, it returns false and ignores the out parameter
            bool isInt = int.TryParse(Console.ReadLine(), out temp);

            //so if it isn't true we want to tell them
            //and give them one more chance to enter
            //a good value
            if (isInt != true)
            {
                Console.WriteLine("Enter a valid integer");
                temp = int.Parse(Console.ReadLine());
            }
            //call the ReactToTemp method and pass it the temperature
            ReactToTemp(temp);

        }

        void ReactToTemp(int temperature)
        {
            //this method uses if and else if to evaluate the temperature
            //and change the console background based on the temperature
            if (temperature >= 100 )
            {
                Console.BackgroundColor = ConsoleColor.Red;
                Console.Clear();
                Console.WriteLine("Hot");
            }
            else if (temperature >= 80)
            {
                Console.BackgroundColor = ConsoleColor.DarkYellow;
                Console.Clear();
                Console.WriteLine("Warm");
            }
            else if (temperature >= 60)
            {
                Console.BackgroundColor = ConsoleColor.Green;
                Console.Clear();
                Console.WriteLine("Pleasent");
            }
            else if (temperature >= 30)
            {
                Console.BackgroundColor = ConsoleColor.Blue;
                Console.Clear();
                Console.WriteLine("Cool");
            }
            else
            {
                Console.BackgroundColor = ConsoleColor.Cyan;
                Console.Clear();
                Console.WriteLine("cold");
            }
        }

    }
}


Here is the switch example

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SwitchExample
{
    class Program
    {
        /// 
        /// this program shows an example of a switch
        /// structure. It takes a grade as an integer
        /// and returns a letter grade
        /// 
        
        static void Main(string[] args)
        {
            //initialize the program
            Program p = new Program();
            //call the method GetGrade();
            p.GetGrade();
            Console.ReadKey();
        }

        void GetGrade()
        {
            //Declare the variable grade
            int grade;
            //prompt the user
            Console.WriteLine("Enter your grade");
            //use the try parse to test the input--see
            //the explanation on the if example
            bool goodGrade = int.TryParse(Console.ReadLine(), out grade);
            if (!goodGrade)
            {
                //in this case we don't give them a second chance
                //we just tell them what's wrong and exit
                Console.WriteLine("Next time do a valid grade as an integer");
                return;
            }
            //call translate grade
            TranslateGrade(grade);
        }

        void TranslateGrade(int grade)
        {
            //create a string variable for the letter grade
            //and give it a default value
            string letterGrade ="Unavailable";
            //set up the switch. Cases have to be
            //exact values. No ranges or > < 
            switch (grade)
            {
                    //case 4 means literally the grade must be 4 to match
                case 4: //note the colon here.
                    letterGrade="A";
                    break;
                case 3:
                    letterGrade = "B";
                    break;
                case 2:
                    letterGrade = "C";
                    break;
                case 1:
                    letterGrade = "D";
                    break;
                case 0:
                    letterGrade = "F";
                    break;
                default:
                    letterGrade = "Undefined";
                    break;
            }
            Console.WriteLine("Your Letter grade is {0}", letterGrade);
        }


    }
}

Chapter Two Practices

Fields gathered from forms and reports

Band name
Time and Date
Location/ venue (name, address, contact)
Age restrictions
Web site
Contact information
Cover charge
Picture
Genre
Live/ dj
Description
Ticket information
Other acts (opening, main)
Bar 21 w/ID (make sure you understand the abbreviations and terms)

Stakeholders

Bands
Fans
Venues
Database admin
Ticket sellers

Interview

 

Question To Allotted Time
1. What would you most like to see from the database? Fans 10 minutes
2. Would you like to follow bands of a particular genre, or just the individual bands? Fans  
What kinds of genres do you follow? Fans  
4. What information do you need about a show? Fans  
5. How do you search for shows now? Fans 
6. Would you sign up for alerts for bands or genres?Fans 

Questionnaire

1. Would you like to follow bands of a particular genre, or just the 
individual bands?
           Yes____ No___
2. Would you sign up for alerts for individual bands?
           Yes____ No___
3. Would you sign up for alerts for different genres of music?
           Yes __ No ___
4. What do you consider to be a local band?
          a. One located in the greater Seattle area
          b. One located in the I5 corridor (Everett, Seattle, Tacoma)
          c. One located in the Northwest (Portland to Bellingham)
5. How often do you think you would access the database?
          a. Daily
          b. Weekly
          c. Monthly
          d. One in a while
          e. never

Job Shadowing

Some bands keep fan lists (emails) could you use?
Sometimes the opening act is unknown until close to the time of the performance.
May need to be generic

Wednesday, October 2, 2013

Math methods

So, here is the code we did in class. I commented it to try to make it clearer.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MathExamples
{
    class Program
    {
        /*******************
         * this program creates
         * separate methods for 
         * each of the the basic math
         * operations
         * Steve Conger 10/2/2013 
         * *******************/

        int number1, number2;

        static void Main(string[] args)
        {
            //initialize the Program class and make
            //an instance of it in memory
            Program p = new Program();
            //call the GetNumbers() method
            p.GetNumbers();
            //call the Display() method
            p.Display();
            //pause for a key stroke
            Console.ReadKey();
        }

        //Get input
        void GetNumbers()
        {
            Console.WriteLine("Please enter the first integer");
            number1 = int.Parse(Console.ReadLine());

            Console.WriteLine("Please enter the second integer");
            number2 = int.Parse(Console.ReadLine());
        }

        int Addition()
        {
            //do addition and return the answer
            int answer=number1 + number2;
            return answer;
        }

        int Multiplication()
        {
            //do multiplication and return the answer
            int answer = number1 * number2;
            return answer;
        }

        int Subtraction()
        {
            //do subtraction and return the answer
            int answer = number1 - number2;
            return answer;
        }

        int Division()
        {
            //check to make sure the denominator
            //is not 0
            //the double equal signs == tests
            //for equality
            if (number2 == 0)
            {
                //if it is equal to 0 give a message
                //and just return zero for the answer
                Console.WriteLine("Can't Divide by zero");
                return 0;
            }
            //if the denominator is not 0 just do the 
            //division
            int answer = number1  / number2;
            return answer;
        }

        

        void Display()
        {
            //int sum = Addition();
            //display the answers. The method can be put directly
            //into the writeline because it returns a number
            //which can be displayed
            Console.WriteLine("the sum of {0}and {1} is {2}", 
                number1, number2, Addition());
            Console.WriteLine("the product of {0} and {1} is {2}", 
                number1, number2, Multiplication());
            Console.WriteLine("the difference of {0} and {1} is {2}",
                number1, number2, Subtraction());
            Console.WriteLine("the quotient of {0} and {1} is {2}",
               number1, number2, Division());
        }
    }
}