Tuesday, October 27, 2015

arrays

Here is the code from class such as it is.

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

namespace arraysExample
{
    class Program
    {
        static void Main(string[] args)
        {
            //let someone enter test scores
            //let them enter as many as they want
            // enter -1 to quit
            double[] grades;
            double grade = 0;
           // double sum = 0;
            int counter = 0;
            /*
            every value is distinquished by an index

                    double[] grades = new double[20];
                    grades[0]=100;
                    grades[1]=98;
                    grades[2]=10;
                    grades[3]=84;
                    grades[19]=34;
            this is an alternate way to declare an array
            double grades[] = new double[] {90, 30, 24.5, 60, 21.5};
            */
            Console.WriteLine("about how many grades do think you want to enter");
            int number = int.Parse(Console.ReadLine());

            grades = new double[number];


            Console.WriteLine("Use -1 to exit");
            do
            {
                Console.WriteLine("Enter Grade");
                grade = double.Parse(Console.ReadLine());

                if (grade != -1)
                {
                    if (counter < grades.Length)
                    {
                        //sum += grade;
                        grades[counter] = grade;
                        counter++;
                    }
                }

            } while (grade != -1);

            for (int i = 0; i < grades.Length; i++)
            {
                Console.WriteLine(grades[i]);
            }

            double average = grades.Sum() / counter;
            Console.WriteLine("you entered {0} grades", counter);
            Console.WriteLine("The average is {0}", average);

            Console.WriteLine("the Fifth Element is {0}", grades[4]);
            grades[4] = 90;
            Console.WriteLine("the fifth element is now {0}", grades[4]);

            Random rand = new Random();
            int[] randomNumbers = new int[10];

            for (int i = 0; i < randomNumbers.Length; i++)
            {
                randomNumbers[i] = rand.Next(1, 101);
            }

            for (int i = 0; i < randomNumbers.Length; i++)
            {
                Console.WriteLine(randomNumbers[i]);
            }

            Console.WriteLine("the total is {0}", randomNumbers.Sum());
            Console.WriteLine("The Average is {0}",
                randomNumbers.Average());


            string[,] songs = new string[3, 2];
            songs[0, 0] = "Royals";
            songs[0, 1] = "Lorde";
            songs[1, 0] = "Hard Days Night";
            songs[1, 1] = "Beatles";
            songs[2, 0] = "Satisfaction";
            songs[2, 1] = "Rolling Stones";

            Console.WriteLine("Give me an artist");
            string artist = Console.ReadLine();

            for (int i = 0; i < 3; i++)
            {
                if (artist.Equals(songs[i, 1]))
                {
                    Console.WriteLine(songs[i, 0]);
                }

            }






                Console.WriteLine("Press any key to exit");
            Console.ReadKey();
            

        }
    }
}


Wednesday, October 21, 2015

Types of Entities

Linking-- connect two Entities that have a many-to-Many relationship resulting in two one-to-many relationships

Domain Entity—Entities that cover main business Customer, Album, Sale, Employee

Lookup Entity-Consistency – List of all states, Rating

Weak Entities--depends on another Entity for its meaning Sale/SaleDetail Employees/Dependents

Tuesday, October 20, 2015

Loops

Here is the code from class. It is, of course, not a coherent program just a set of examples

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

namespace LoopExamples
{
    class Program
    {
        static void Main(string[] args)
        {
            //this is a simple for loop
            //first you set the counter, then you set
            //the limit, then you increment (++) the counter
            for (int counter = 0; counter < 20; counter++)
            {
                Console.WriteLine(counter);
            }

            //this is a for loop that outputs the prime numbers
            //from the previous assignment
            for (int i = 1; i < 41; i++)
            {
                int prime = i * i - i + 41;
                Console.WriteLine(prime);
            }

            //your can use a variable for the loop limit
            Console.WriteLine("how many loops do you want to do?");
            int number = int.Parse(Console.ReadLine());

            //avoid an infinite loop--infinite loops result
            //when the end condition will never be met
            for (int x = 1; x < number; x--)//decrement -1
            {
                Console.WriteLine(x);
                if (x == -10)
                {
                    break;
                }

            }

            //you can use other operators that ++ or --
            //this one counts up by 3s
            for (int i = 1; i < 20; i += 3)
            {
                Console.WriteLine(i);
            }

            // +=, -=, *=, /=, %=
            //number -= 2  equivalent to number = number - 2
           // number *= 2 equivelant to number = number * 2

            Console.WriteLine("how many numbers do you want to enter");
            int num = int.Parse(Console.ReadLine());
            //I declare these outside the loop so that I can use them
            //outside--if I declared them in the loop they would 
            //have the "scope" of the loop. In general a variable has the scope
            //of the block "{}" it is declared in
            double sum = 0;
            double average = 0;

            for (int i = 1; i <= num; i++)
            {
                Console.WriteLine("enter a number");
                double myNumber = double.Parse(Console.ReadLine());
                sum += myNumber;

            }

            Console.WriteLine("the sum is {0}", sum);
            average = sum / num;
            Console.WriteLine("The average is {0}", average);

            //a while loop continues looping until the critera
            //set at the beginning is no longer true

            string quit = "no";
           //Equals is equivalent to "==" but works better with strings
            while (quit.Equals("no") || quit.Equals("No"))
            {
                Console.WriteLine("Are your ready to quit 'yes/no");
                quit = Console.ReadLine();
                quit = quit.ToLower();//this forces everything to lower case
            }

            bool goodNumber = false;
            int number2=0;
            //this loops until the user enters a good number
            while (goodNumber == false)
            {
                Console.WriteLine("enter a valid number");
                goodNumber = int.TryParse(Console.ReadLine(), out number2);
            }

            Console.WriteLine("Your Number is {0}", number2);

            // a do while loop is like a while loop except it checks its
            //criteria at the end. that means it is guaranteed to execute
            //at least once
            do
            {
                Console.WriteLine("enter a valid number");
                goodNumber = int.TryParse(Console.ReadLine(), out number);

            } while (goodNumber == false);




            Console.ReadKey();

        }
    }
}

Monday, October 19, 2015

Normalization

First Normal Form

All data in a given attribute must be of the same kind No attribute should contain arrays—(lists of items) and there should be no repeating values

CDKey CDTitle
1     Jakalope
2     Popcorn

TrackKey CDKey  TrackTitle
1         1     Pretty Life
2         1     Feel It
3         1     Go Away
4         2     Please Please Please
5         2     Try me

Second Normal Form

Remove all functional dependencies Every entity should be about only one thing Groups of Attributes that depend on each other rather than on the main theme (key) of the Entity

Third Normal Form

Remove all transient dependencies Usually one field that refers to another field for its meaning rather than describing the whole topic (the key)

Here is the CD ERD after normalization

Here is the sale saleDetail relation

Tuesday, October 13, 2015

Selection examples

The if examples

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

namespace ifStatementExamples
{
    class Program
    {
        static void Main(string[] args)
        {
            int number;
            Console.WriteLine("Enter a number");
            //the tryParse returns a boolean
            //if the number is good it returns true
            //if the number is not good it returns false
            //if the number is good it also assigns it to the variable specified in the
            //out parameter, if it is not good it assigns 0
            bool goodNumber = int.TryParse(Console.ReadLine(), out number);

            // ! not, != not equal, == equals
            if (goodNumber == false)
            {
                Console.WriteLine("Please enter a good number");
                Console.ReadKey();
                return;
            }


            if (number > 20)
            {
                Console.WriteLine("your number is greater than 20");
            }
            else
            {
                Console.WriteLine("Your number is less than 20");
            }
            //&& = and
            //|| = or

            if (number > 0 && number <= 20)
            {
                Console.WriteLine("Your number is between 1 and 20");
            }
            else if (number > 20 && number <=  50)
            {
                Console.WriteLine("Your number is between 21 and 50");
            }
            else if (number > 50 && number <= 100)
            {
                Console.WriteLine("Your number is between 51 and 100");
            }
            else
            {
                Console.WriteLine("Your number is more than 100");
            }

            int number2;
            Console.WriteLine("Enter a number between 1 and 5");
            bool goodNumber2 = int.TryParse(Console.ReadLine(), out number2);

            if (!goodNumber2)
            {
                Console.WriteLine("Please enter a good number");
                Console.ReadKey();
                return;
            }

            //a switch is good for some things but is less
            //flexible than a if elseif. It can't test a range
            //of values but only specific values
            switch (number2)
            {
                case 1:
                    Console.WriteLine("One");
                    break;
                case 2:
                    Console.WriteLine("Two");
                    break;
                case 3: //you can fall through to the next case
                case 4:
                    Console.WriteLine("Three or Four");
                    break;
                case 5:
                    Console.WriteLine("Five");
                    break;
                default:
                    Console.WriteLine("Not between 1 and 5. Follow directions!");
                    break;
            }





            Console.ReadKey();

        }
    }
}

Here is the code for the extra credit

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            //determine how many busses you need
            //each bus has a capacity of 45
            // const is used to declare a constant. that means a value that
            //cannot be changed by the program
            const int CAPACITY= 45;
            int students;
            int busses;

            Console.WriteLine("How many people need a ride");
            bool goodNumber = int.TryParse(Console.ReadLine(), out students);

            //! means not a good number
            if (!goodNumber)
            {
                Console.WriteLine("Please enter a valid number");
                Console.ReadKey();
                return;
            }


            busses = students / CAPACITY;

            if (students % CAPACITY > 0)
            {
                //equivelent to busses = busses + 1
                //also could do busses++ which increments by 1
                busses += 1;
            }

            Console.WriteLine("You will need {0} busses", busses);

            Console.ReadKey();

            //the peer excercise
            //if(number % 2 ==0)
            // even
            //else
            //odd

        }
    }
}

Monday, October 12, 2015

Diagraming a database 1

Modeling a Database

Field list for DVDs

Groups: Entity should be about one thing: No multi valued groups

Candidate Key-- surrogate auto or random number for keys- Natural key is a natural field in the table

DVD

Title, length, Release Date, origin year, purchase year, number of disks, Rating, Description, Price, copyright

Actors

Name, gender, awards, alias

Features

FeatureType, description

Studio

Name, Location

Languages

name

Writer

Name

Genre

Name, description

Original list of fields

Name or title
director
Lead actors
Time length
Release year
Original year
Genre
Number of disks
Studio
Description
Writer
Language choices
Rating
Extras
Plot summary
Country of Origin
Date purchased
Price
copyright

Relationship types

Initial Diagram DVDs Actors

Data Examples

Wednesday, October 7, 2015

Requirements and Business Rules

Requirements and Business Rules

Here are the notes that we did in class, such as they are


Things the database must do
*Data requirements
*Reporting Requirements
*Security Requirements who will be using the database what permissions will they need


Some data requirements

Show Dates and times
Venues address city state zip phone webpage name email
Capacity restrictions description handicap access
Act capacity reserved vs open
Restrictions
Contact for venues acts
Customer list subscription to acts or venues

Reporting Requirements

Calendar
View a particular venue and see upcoming shows
View an act and see where they are playing
Query a venue based on restrictions

Security requirements:

Access management--
support
Application—general
Select (read) (CRUD) (except the customer or fan lists)
Insert (put in new records)
Update (change or edit existing records)
Delete (delete records)
Venues—update, insert, select --constraint
only their own data
Customer fan—select insert update only own information


Business rules

How things
Venues have to enter their own schedules
Rule that venues must update weekly
Confirmation email for new customers

Tuesday, October 6, 2015

Ints doubles and operators

Here is the code from today's class.

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

namespace ExamplesForAssignment2
{
    class Program
    {
        /*************************
        These are examples for assignment 2
        involving operators 
        +   addition
        -    subtraction
        *    multiplication
        /    division
        %   modulus--remainder in integer division
        and the numeric data types
        int, whole number
        and double, float or decimal 
        ****************************/

        static void Main(string[] args)
        {
            //number variables int double
            int number, number2;
            int sum, difference, product, quotient, remainder;
            double  exponent;
            double decimalQuotient;

            //inputs
            Console.WriteLine("enter an integer");
            //C# treats all input from the console as a string
            //Parse removes the quotes and sees if the content
            //is of the correct type--in this case int
            number = int.Parse(Console.ReadLine());

            Console.WriteLine("enter another integer");
            number2 = int.Parse(Console.ReadLine());

            Console.WriteLine("Enter a double");
            //this is an example of parsing a double from the console
            double newNumber = double.Parse(Console.ReadLine());

            //algorithm
            //Here are all the operators
            sum = number + number2;
            difference = number - number2;
            product = number * number2;
            quotient = number / number2;
            remainder = number % number2;
            //in this one we cast one of the sides to a double
            //the equation always defaults to the type with the higher precision
            //doubles always have a higher precision because they contain doubles
            //this makes it so the result returns the decimal part
            decimalQuotient = (double)number / number2;
            //the Math library is static and always available
            exponent = Math.Pow(number, number2);

            //outputs
            Console.WriteLine("The sum of {0}, and {1} is {2}", number, number2, sum);
            Console.WriteLine("The difference of {0}, and {1} is {2}", number, number2, difference);
            Console.WriteLine("The product of {0}, and {1} is {2}", number, number2, product);
            Console.WriteLine("The quotient of {0}, and {1} is {2}", number, number2, quotient);
            Console.WriteLine("The remainder of {0}, and {1} is {2}", number, number2, remainder);
            Console.WriteLine("The exponent of {0}, and {1} is {2}",number, number2, exponent);
            Console.WriteLine("The decimal quotient of {0}, and {1} is {2}", number, number2, decimalQuotient);

            Console.WriteLine("Press any key to exit");
            Console.ReadKey();



        }
    }
}

Monday, October 5, 2015

Information Gathering

Information Gathering

Here are our class notes on information gathering, such as they are.

Ask client (interviews) -- prepare
One retreat profession facilitator record everything
stakeholders (access) security
current problems
why they want a new database
What the database requires
What would they like beyond requirements
Growth scalability

 

Look at the existing systems Budget Security
Phone/dept (should never have two kinds of values in a field)
Forms (entering data) fields
Reports (displaying data) summary

 

Job Shadowing
Exceptions
flow

Thursday, October 1, 2015

First assignment example

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

namespace AssignmentExamples
{
    class Program
    {
        //comments with your name 
        static void Main(string[] args)
        {
            //prompt
            Console.WriteLine("Enter your favorite color ");
            //getting input
            string colorChoice= Console.ReadLine();
            Console.WriteLine("Enter your favorite animal");
            string animal = Console.ReadLine();
            //output results with placeholders
            Console.WriteLine
                ("Your favorite color is {0}, and your favorite animal is a{1}"
                ,colorChoice, animal);
            
            //concatination
            Console.WriteLine("your favorite color is " + colorChoice +
                ", your favorite animal is a " + animal);

            //pause long enough to read it
            Console.ReadKey();


        }
    }
}