Wednesday, October 12, 2016

Normalization first Take

First normal form:

There should be no repeated fields, and no arrays. All the entries in an attribute should be of the same kind. Break out any repetitions, give everything a key

2nd Normal form:

You should remove all functional dependencies: (Sub Themes, groups of attributes that relate to each other but not to the topic (key) of the entity

3rd Normal form

Is about removing transient dependencies--attributes that modify or describe another attribute and not the key

Here is the student entity not normalized

student entity

Here is the student ERD after normalization

normalized student ERD

Entity Relational Design

An entity is depicted as a box. The top is the title or name of the entity. Next is a primary key, a separator, and then the attributes that describe the entity. Bold font indicates that an attribute is required.

student entity

There are three types of relationships between entities

One-to-Many, which is the normal relationship among entities and will account for 95% of all relationships. Here is one Department has many employees.

one

The one side always points to the primary key, the crow's foot (the three point prong) always points to the many side

One-to-One. This is quite rare but is legal. It says for every record in one table there is exactly one matching record in the second table. One example of this is when a table is split up for security reasons. For instance, the public information about an employee could be in one table and the private in another.

one

The third relationship is Many-to-Many. This is legal in design, but no database can process it. Whenever you have a many to many relationship, you must resolve it into two one-to-many relationships by creating a linking table. For instance, assume an employee can be in more than one department. That means that each employee can be in many departments and each department contains many employees. A many to many relationship. To resolve this we create a linking table, here called EmployeeDepartment.

linking Table

Here is the coffee shop ERD we did in class

coffee shop ERD

Tuesday, October 11, 2016

Selection Statements

Here is the code for our selection examples

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

namespace SelectionExamples
{
    class Program
    {
        /*This program provides examples of
         * if statements and switches
         * Steve Conger 10/11/2016*/

        static void Main(string[] args)
        {
            int number;
            Console.WriteLine("Enter number");
            //try parse returns a boolean (true/false)
            //if the number is good it assigns it to the variable
            //outside the method (out)

            bool goodNumber = int.TryParse(Console.ReadLine(),out number);

            if(goodNumber == false)
            {
                Console.WriteLine("restart and enter a valid integer");
                Console.WriteLine("Press any key to exit");
                Console.ReadKey();
                return; //ends the program
            }

            // >, <, >=, <=, ==, != (not equal)
            //with strings it is often best to use .Equals
            if (number > 10)
            {
                Console.WriteLine("the number is greater than 10");
            }
            else if(number==10)
            {
                Console.WriteLine("the number is 10");
            }
            else
            {
                Console.WriteLine("The number is less than 10");
            }

            Console.WriteLine("Enter the name of the current month");
            string month = Console.ReadLine();
            // || or , && and

            if(month.Equals("October") || month.Equals("october"))
            {
                Console.WriteLine("Happy Halloween");

            }
            else
            {
                Console.WriteLine("You are a bit confused");
            }


            //switch statement
            int choice;
            Console.WriteLine("Enter an integer between 1 and 4");
            bool good = int.TryParse(Console.ReadLine(), out choice);
            //!good same as good !== true or good == false
            if(!good)
            {
                return;
            }

            //switch statement
            switch(choice)
            {
                case 1:
                    Console.WriteLine("You entered 1");
                    break;
                case 2: //fall through to three
                case 3:
                    Console.WriteLine("You chose 2 or 3");
                    break;
                case 4:
                    Console.WriteLine("You entered 4");
                    break;
                default://captures anything else
                    Console.WriteLine("Not a valid choice");
                    break;
            }

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


            
        }
    }
}

here is the code for the birthday program

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

namespace Birthdate
{
    class Program
    {
        static void Main(string[] args)
        {
            DateTime birthday;
            DateTime today = DateTime.Now;
            int age;
            
            
            
            //you can try parse for DateTime as well
            Console.WriteLine("enter your birth date");
            bool goodDate = DateTime.TryParse(Console.ReadLine(), out birthday);

            if (!goodDate)
            {
                Console.WriteLine("enter a valid birth date");
                bool good = DateTime.TryParse(Console.ReadLine(), out birthday);
                //nested if statement
                if(!good) //give a second chance
                {
                    Console.WriteLine("Sorry still not valid");
                    Console.WriteLine("Press any key to exit");
                    Console.ReadKey();
                    return;
                }//end inner if

            }//end outer if
            //just subtract years. We could also do months and days
            age = today.Year - birthday.Year;
            Console.WriteLine("You are {0} years old", age);

            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }//end main
    }//end program class
}//end namespace

Here is a solution for the peer excercise

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

namespace PeerIf
{
    class Program
    {
        static void Main(string[] args)
        {
            string password = "P@ssw0rd1";
            string username = "customer";
            string user;
            string pass;

            Console.WriteLine("Enter your user name");
            user = Console.ReadLine();

            Console.WriteLine("Enter your password");
            pass = Console.ReadLine();

            if(password.Equals(pass) && username.Equals(user))
            {
                Console.WriteLine("Welcome user");
            }
            else
            {
                Console.WriteLine("invalid password or user name");
            }

            /*an alternative way
             * if(username.Equals(user)
             * {
             *     if(password.Equals(pass)
             *     {
             *         Console.WriteLine("Welcome");
             *     }
             *     else
             *     {
             *          Console.WriteLIne("Inavalid");
             *     }

             * }
             * */

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





        }
    }
}

Thursday, October 6, 2016

Using Integers and doubles


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

namespace NumberExamples
{
    class Program
    {
        /// 
        /// This program shows examples of integers
        /// and doubles with math operators
        /// Steve Conger 10/6/2016
        /// 
        /// 
        static void Main(string[] args)
        {
            //integers and doubles
            //operators + - * / %
            //decaring number variables
            string name;
            int number;
            int number2;
            int answer;
            double answer2;
            double number3;

            //getting values from the user
            //anything entered on the console is a string
            //it must be converted into the appropriate
            //type of number
            Console.WriteLine("Enter the first Integer");
            number = int.Parse(Console.ReadLine());

            Console.WriteLine("Enter the second Integer");
            number2 = int.Parse(Console.ReadLine());

            //this takes a console entry and converts into a double 
            //(with decimal places)
            Console.WriteLine("Enter a meal amount");
            number3 = double.Parse(Console.ReadLine());

            

            answer = number + number2;

            Console.WriteLine("The sum of {0} + {1} = {2}", number, number2, answer);
            answer = number2 / number;

            Console.WriteLine("The quotient of {0} / {1} = {2}", number2, number, answer);

            answer = number2 % number;
            Console.WriteLine("The remainder of {0} / {1} = {2}", number2, number, answer);

            //this casts the integer number2 into a double. it allows the division
            //to return decimal places
             answer2= (double)number2 / number;

            //Math is a built in library of math functions. 
            //Unlike the format codes this actually changes
            //the underlying number
            answer2 = Math.Round(answer2, 2);
           
            //{0:F@} would format the number to only show 2 decimal places
            //but it does not change the underlying numbers
            //c formats the number to look like currency
            Console.WriteLine("The double quotient of {0} / {1} = {2}", number2, number, answer2);
            Console.WriteLine("The double quotient of {0} / {1} = {2:C}", number2, number, answer2);

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



        }//end main
    }//end program
}//end namespace

Tuesday, October 4, 2016

First assignment Code

Here is the first part of assignment 1.

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

namespace Assignment1_1
{
    /*This program will take in a user's
    name and email and display it 
    last name, first name -- email
    Steve Conger, 10/4/2016
    */

    class Program
    {
        //starting point of the program
        static void Main(string[] args)
        {
            string firstName;
            string lastName;
            string email;

            Console.WriteLine("Enter your first name");
            firstName = Console.ReadLine();

            Console.WriteLine("Enter your last name");
            lastName = Console.ReadLine();

            Console.WriteLine("Enter your email");
            email = Console.ReadLine();

            Console.WriteLine("{0}, {1}--{2}", lastName, firstName, email);
            Console.WriteLine(lastName + ", " + firstName + "--" + email);

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


        }//end of Main
    }//end of class program
}//end of namespace


Here is the second part of assignment one

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

namespace Assignment1_2
{
    class Program
    {
        /*This program produces a
         * mailing label
         * steve conger 10/4/2016
         * */
        static void Main(string[] args)
        {
            Console.WriteLine("Enter your full name");
            string fullName = Console.ReadLine();

            Console.WriteLine("Enter your street address");
            string address = Console.ReadLine();

            Console.WriteLine("Enter your City");
            string city = Console.ReadLine();

            Console.WriteLine("Enter your State");
            string state = Console.ReadLine();

            Console.WriteLine("Enter your zip code");
            string zipcode = Console.ReadLine();

            Console.WriteLine();

            Console.WriteLine(fullName);
            Console.WriteLine(address);
            Console.WriteLine("{0}, {1} {2}",city, state, zipcode);

            Console.WriteLine();

            //an alternate way with line break excape characters (\n)
            Console.WriteLine(fullName+"\n" + address + "\n" + city + ", " + state + " " + zipcode);

            Console.WriteLine();

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

        }
    }
}


Wednesday, September 28, 2016

Requirements (Afternoon Class)

Requirements

Client information
Name, address, age, phone, email, homeless
Request amount,  paid amount distributed grant, max and min amounts, Employment
Gender, family, language (demographics), education level, number of kids
Nature request, categories
Dates of request—date of review, date paid
Income
How many times, who approved,
Donors (name, email, address (apartment, street, city, state)) main contact 
Donation amount, matching gifts, category of donor, Donation date
Employees—not human resources 

Reporting Requirements

Who donated
How much was donated per year, per month, per quarter
How many loans granted denied
How many per category

Security Requirements

Who should have access to what data?
Enter and edit own
Public access reports Categories

Requirements: Morning Class

Here are the fields (Data Requirements) that we came up with, discussing Community Assist.

Name of clients
Request amounts
Types of services
One time limit, life time limits
Donors—name 
How much they are donate
Address of donors (street, city, state, zip)
Addresses of clients and emails
Email addresses (not required)
Grants applied for—by charity
Grant approved or not and reason
Date of request, Date of Review, Date of donations
Date of dispersal
Direct or payee
Reviewer
Employees
Request status

Reporting requirements

What follow up with clients or record of meetings
Report on percentages for charity vs admin
Totals spent on each type of service
Totals by month and year

Security requirements

Personal information—who should be able to see it, how to protect
Employee access
Public roles 

Business Rules

Business rule—Do we allow anonymous donors?
Rules about who to they will accept money from.
Every grant must reviewed by at least 2 Employees
Every grant must be reviewed within 7 days after being posted
Constraint—will not be a human resources data