Tuesday, October 28, 2014

Gas Mileage with Methods(Morning)

Here is the program in Main

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

namespace GasMileageCalculator
{
    class Program
    {
        /***********
         * this program will calculate
         * miles per gallon given 
         * an input of mile and gallons
         * ***************/
        static void Main(string[] args)
        {
            //program variables
            double miles;
            double gallons;
            double mpg;
            bool goodMiles;
            bool goodGallons;

            //we use a do loop and a try parse to make sure the entry is
            //in the correct format
            do
            {
              
                Console.WriteLine("How many miles were traveled");
                //the try parse returns a bool true or false
                //if good it assigns the result to the out parameter miles
                //if false it assigns 0 to miles
                goodMiles = double.TryParse(Console.ReadLine(), out miles);
                if (!goodMiles)
                {
                    Console.WriteLine("Enter a valid mileage as numbers");
                }//end if

            } while (!goodMiles); //end do

            do
            {

                Console.WriteLine("How many Gallons");
                goodGallons = double.TryParse(Console.ReadLine(), out gallons);
                if (!goodGallons)
                {
                    Console.WriteLine("Enter a valid  number for Gallons");
                } //end if

            } while (!goodGallons); //end do

            mpg = miles / gallons;

            Console.WriteLine("You got {0:F2} miles per gallon", mpg);
            //Console.WriteLine("You got " + mpg.ToString("#0.00") + " miles per gallon");
            //Math.Round(mpg, 2);
            
            Console.ReadKey();


        }//end main
    }//end class
}//end namespace

Here is the program with methods

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

namespace GasMileageMethods
{
    class Program
    {
        /// 
        /// this program calculates miles but
        /// breaks it into methods
        /// GetMiles() prompts the user for miles
        /// GetGallons() prompts the user for gallons
        /// CalculateMPG() calcualtes the miles per gallon
        /// Display(double mileage) displays the results
        /// the mileage is passed to display as a
        /// parameter from CalculateMPG()
        /// 
        /// 
        static void Main(string[] args)
        {
            //load the program class into memory
            Program p = new Program();
            //call the Method to calculate the mpg
            p.CalculateMPG();
            //call the end program method
            p.EndProgram();
        }

        /// 
        /// this method prompts the user for miles
        /// it uses a try parse and a do loop
        /// to check if its a valid entry
        /// 
        /// miles
        private double GetMiles()
        {
            double miles;
            bool goodMiles;
            do
            {
                Console.WriteLine("Enter the miles traveled");
                goodMiles = double.TryParse(Console.ReadLine(), out miles);
                if (!goodMiles)
                {
                    Console.WriteLine("Enter a valid number for miles");
                }//end if
            } while (!goodMiles);//end while

            return miles;
        }//end GetMiles

        /// 
        /// This method prompts the use for Gallons 
        /// and uses a try parse and a do loop to check
        /// for the validy of the answer
        /// 
        /// gallons
        private double GetGallons()
        {
            double gallons;
            bool goodGallons;
            do
            {
                Console.WriteLine("Enter the Gallons used");
                goodGallons = double.TryParse(Console.ReadLine(), out gallons);
                if (!goodGallons)
                {
                    Console.WriteLine("Enter a valid number for Gallons");
                }//end if
            } while (!goodGallons);//end while

            return gallons;
        }//end GetGallons

        /// 
        /// the calculate method calls the GetMiles()
        /// and the GetGallons() method to  get
        /// the values and then calculated the miles 
        /// per gallon. It passes the variable storing the
        /// result to the 
        /// 
        private void CalculateMPG()
        {
            double distance = GetMiles();
            double gas = GetGallons();
            double mpg = distance / gas;
            //double mpg=GetMiles()/GetGallons();
            Display(mpg);
        }//end CalculateMPG

        private void Display(double mileage)
        {
            Console.WriteLine("You mileage is " + mileage.ToString("F2"));
        }//end Display

        private void EndProgram()
        {
            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }//

    }//end class
}

Thursday, October 23, 2014

Parallel arrays and methods (morning)

This is the second in class example. I will post the first one soon

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

namespace parallelArrays
{
    class Program
    {
        /// 
        /// This program shows how to use 
        /// parallel arrays and methods.
        /// Parallel arrays are arrays in which
        /// related values are kept on identical 
        /// indexes. [0] =[0], [1]=[1] etc.
        /// the methods are broken into 
        /// CreateArrays which declares the arrays
        /// Populate arrays which loops through the
        /// arrays and lets the user enter values
        /// CalculateArea multiplies the parallel values
        /// (values with the same index in the two arrays)
        /// Each area is passed to the display method
        /// 
        /// 
        static void Main(string[] args)
        {
            //make the program new (load into memory)
            Program p = new Program();
            p.CreateArrays(); //call the CreateArrays program
            p.EndProgram(); //call end program

        }

        private void CreateArrays()
        {
            //declare the arrays
            int[] height = new int[5];
            int[] width = new int[5];

            //call PopulateArrays and pass the two arrays to it
            PopulateArrays(height, width);
        }

        private void PopulateArrays(int[] height, int[] width)
        {

            //loop through the arrays and prompt
            //the user to provide values
            for(int i = 0; i < height.Length; i++)
            {
                Console.WriteLine("Please enter Height");
                height[i] = int.Parse(Console.ReadLine());
                Console.WriteLine("Please enter Width");
                width[i] = int.Parse(Console.ReadLine());
            }
            //call CalculateAreas and pass the arrays
            CalculateAreas(height, width);
            
        }
        private void CalculateAreas(int[] height, int[]width)
        {
            Console.BackgroundColor = ConsoleColor.DarkBlue;
            Console.Clear();
            //this loop multiplys the parallel values
            //from the arrays to get the area
            //then passes each area to the Display method()
            for(int i = 0; i<height.Length;i++)
            {
                int area=height[i] * width[i];
                DisplayArea(area);
            }
        }

        private void DisplayArea(int area)
        {
            
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("the area is : " + area.ToString());
        } 
        private void EndProgram()
        {
            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }
    }
}


Monday, October 20, 2014

Mehtods and Arrays (Evening Class)

Here is the code we did in class with comments

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

namespace ShoppingList
{
    class Program
    {
      
        /// <summary>
        /// This program we are going to
        /// enter a shopping list into an array
        /// have a second array to store the prices
        /// and third array to store discounts.
        /// these parrallel arrays
        /// Use methods and only use the Main
        /// to start the program
        /// </summary>

        int number; //this variable has class scope
        //meaning it can be seen by any method
        //in the class
        static void Main(string[] args)
        {
            //initialize the program
            Program p = new Program();
            //call the Start method
            p.Start();
            //call the end program method
            p.EndProgram();
        }

        /// <summary>
        /// the start method starts the program by
        /// calling the PopulateArrays method (which
        /// calls the create arrays methods and the 
        /// display method). It also puts that method
        /// into a while loop so that the program can be
        /// run as many times as the user would like
        /// </summary>
        private void Start()
        {
            //set the variable for the while loop
            string shopping = "yes";
            //loop as long as the shopping variable equals yes
            while (shopping.Equals("yes"))
            {
                //call the PopulateArraysMethod
                PopulateArrays();
                //ask user whether to continue or not
                Console.WriteLine("Continue Yes--any other = no");
                shopping = Console.ReadLine().ToLower();
            }
        }

        /// <summary>
        /// This array gets the number of items
        /// that the user wants to enter
        /// number is a class level variable
        /// and can be seen by any method
        /// </summary>
        private void GetNumberOfItems()
        {
            Console.WriteLine("How many items do you want to enter");
            number = int.Parse(Console.ReadLine());
        }

        /// <summary>
        /// This method declares and initializes
        /// an array for the shopping list
        /// it returns a string[] array
        /// </summary>
        /// <returns>string[]</returns>
        private string[] CreateShoppinglist()
        {
            
            string[] shoppingList = new string[number];
            return shoppingList;
        }

        //creates and returns an array for prices
        private double[] CreatePriceList()
        {
            double [] priceList = new double[number];
            return priceList;
        }

        //creates and returns an array for discounts
        private double[] CreateDiscountList()
        {
            double[] discountList = new double[number];
            return discountList;
        }

        /// <summary>
        /// this is the main method of the program
        /// it call the methods that create the arrays
        /// it loops through the arrays and lets
        /// the user enter values. the arrays are 
        /// parallel in that item [0] is parallel to price [0]
        /// is parallel to discount[0] etc.
        /// When the arrays are populated it passes
        /// them to the calculate method
        /// </summary>
        private void PopulateArrays()
        {
            //call GetNumberOfItems method to 
            //make sure number has a value
            GetNumberOfItems();
            //get the arrays created from the
            //methods that create  and return the arrays
            string[] itemList = CreateShoppinglist();
            double[] prices = CreatePriceList();
            double[] discounts = CreateDiscountList();

            //loop through the arrays and prompt
            //the user to enter values
            //by doing the three together we keep 
            //the index values in parallel
            for(int i=0;i<number;i++)
            {
                Console.WriteLine("enter the item name");
                itemList[i] = Console.ReadLine();
                Console.WriteLine("Enter the item price");
                prices[i] = double.Parse(Console.ReadLine());
                Console.WriteLine("enter any discount as a decimal");
                discounts[i] = double.Parse(Console.ReadLine());
            }
            //call the Calculate method and pass the arrays
            //as parameters. parameters are passed 1st to 1st, 
            //2nd to second, etc. the program only knows if
            //the data type is right, not if it is the correct value
            Calculate(itemList, prices, discounts);
        }

        /// <summary>
        /// This method takes the three arrays as
        /// parameters and loops through them
        /// determing the price. It does this by
        /// subtracting the discount amount from
        /// the give price (price=price - (price * discount)
        /// then it gets the name of the item from the
        /// items array and concatinates it with the price
        /// and passes the string to the Display()
        /// method where it is printed to the console
        /// </summary>
        /// <param name="items"></param>
        /// <param name="prices"></param>
        /// <param name="discounts"></param>
        private void Calculate(string[] items, double[] prices, double[] discounts)
        {
            double price = 0;
            for(int i = 0; i< number; i++)
            {
                //get the price by taking the price from the given
                //index of the array and subtracting the price * discount 
                //taken from the same index in discount array
                price = prices[i] - (prices[i] * discounts[i]);
                //put the name and the new price into a string
                //ToString() is a method that converts a number
                //to a string. The "C" formats it as currency
                string itemString = items[i] + " " + price.ToString("C");
                //call the display method and pass it the string
                //as a parameter
                Display(itemString);
            }
        }
        /// <summary>
        /// this method takes a string as a parameter
        /// and writes it to console
        /// </summary>
        /// <param name="itemPrice"></param>
        private void Display (string itemPrice)
        {
            Console.WriteLine(itemPrice);
        }
        private void EndProgram()
        {
            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }

    }
}

BookReview ERD

Here is an ERD (Entity Relation Diagram) of the BookReview database. I did not include all the attributes for each table. Note the One to One relationship between Reviewer and Login.

You can click the image to get a larger view

Comments on relationships:

There is a many to many relationship between Book and Author. Each book can have many authors, each author can have many books. To resolve this we need to create a linking table BookAuthor that matches author with book. I made the key for the linking table a composite key that contains both the BookKey and the AuthorKey. This makes it so the same author can't be cited twice for the same book. The pair always must be unique.

The relationship between Category and Book is also many to many and requires a linking table: BookCategory.

The review table is tied to the reviewer and the book table. Both are one to many. One book can be reviewed many times. On reviewer can review many books.

Comments are related to Review and Reviewer in the same way. On Review can have many comments and one Reviewer can make many comments.

There is one other table related to Reviewer. LoginTable stores the username and password for the Reviewer. The LoginTable has one child which is the LoginLog that logs every time a reviewer logs in.

Wednesday, October 15, 2014

First Methods (Evening)

Here are our two examples of using methods

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

namespace MethodsExample
{
    class Program
    {
        /// 
        /// This class shows the use of methods
        /// specifically it shows the use of methods
        /// that have a return type of int
        /// steve 10/15/2014 Evening
        /// 
    
        static void Main(string[] args)
        {
            //instantiate the program by making it new
            //because main is static it is loaded into
            //memory automatically, but the rest
            //of the class is not. Making it new
            //loads it into memory. p is the local variable name
            //of the class. The dot stands for membership
            //p.Display() calls the GetDisplay()
            //method which is a member of Program
            Program p = new Program();
            
            // I only need to call the Display method because
            //it calls the GetSum() method and the GetSum()
            //method calls the GetNumber() method. 
            p.Display();
            p.EndProgram();
        }

       
        //the get number method gets the user's input
        //of a number and returns that number
        private int GetNumber()
        {
            Console.WriteLine("Enter Number");
            int number = int.Parse(Console.ReadLine());
            return number;
        }
        //this method gets two numbers and adds them.
        //Notice it calls the GetNumber() method twice
        //this is an example of reuse. We only have to write
        //the method once. but can use it whenever we need
        //it. The GetNumber() method returns an integer
        //so the addition is not adding the methods it is adding
        //the integers returned by the method
        private int GetSum()
        {
            int sum = GetNumber() + GetNumber();
            return sum;
        }

        private void Display()
        {
            //Call GetSum to get the sum and display it
            int sum = GetSum();
            Console.WriteLine("the sum is " + sum);
        }


        private void EndProgram()
        {
            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }
       
    }//end class
}

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

namespace MethodsWithParameters
{
    class Program
    {
        /// 
        /// This class shows the use of methods
        /// and passes values as parameters
        /// from one method to another.
        /// Specifically, it gets the diameter of
        /// a circle in one method, passes it to 
        /// a separate method for calculation
        /// and then to a final method for display
        /// steve  10/15/2014 Evening class
        /// 
        /// 
        //declare a constant for PI
        private const double PI = 3.14156;
        static void Main(string[] args)
        {
            //instantiate the program by making it new
            //because main is static it is loaded into
            //memory automatically, but the rest
            //of the class is not. Making it new
            //loads it into memory. p is the local variable name
            //of the class. The dot stands for membership
            //p.GetDiameter() calls the GetDiameter()
            //method which is a member of Program
            Program p = new Program();
            p.GetDiameter();
            //call end program method
            p.EndProgram();
        }

        private void GetDiameter()
        {
            //ask the user for the diameter
            Console.WriteLine("Please give the diameter of your circle");
            double diameter = double.Parse(Console.ReadLine());

            //call the GetCirucumerance method and pass it
            //diameter as a parameter
            GetCircumference(diameter);
        }

        //GetCircumference method which takes a parameter
        //that is a double in type
        private void GetCircumference(double diam)
        {
            double circumference = diam * PI;

            //call Display and pass it the Circumference
            Display(circumference);
        }

        private void Display(double circ)
        {
            //display the parmater that was passed
            Console.WriteLine("the circumference is " + circ);
        }

        private void EndProgram()
        {
            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }
    }//end class
}

Tuesday, October 14, 2014

Arrays(Morning)

String arrays

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

namespace ArraysExampleMorning
{
    class Program
    {
        static void Main(string[] args)
        {
            //declare a string array. an array is
            //a variable that can store more than 
            //one value at a time. It is marked by
            //the use of squlare brackets [] after 
            //the data type
            string[] members;

            //before you can use an array
            //you must make it new and give
            //it a length
            //each member of an array
            //has an index number to identify
            //it. Indexes always start at 0
            members = new string[7];
            members[0] = "Brad";
            members[1] = "Josephine";
            members[2] = "Paul";
            members[3] = "Alice";
            members[4] = "Lewis";

            //here we added the last member
            //but not the fifth
            members[6] = "Sally";

            //you can access members by means of their index
            Console.WriteLine("the third member is " + members[2]);

            //this loops through the array members
            for (int i = 0; i < members.Length;i++ )
            {
                //if the value for the index is not empty
                if(members[i] != null)
                { 
                    //print it
                    Console.WriteLine(members[i]);
                }
            }

            //an alternate way of initializing an array.
            //just less typing
            string[] colors = new string[] { "red", "green", "blue", "purple", "yellow" };

            //you can use a variable for the size of the array
            //as long as you assign a value to the variable
            //before you initialize the array
            Console.WriteLine("How many books do you want to enter");
            int numberOfBooks = int.Parse(Console.ReadLine());

            string[] books = new string[numberOfBooks];

            //loop through the array to add values
            for (int i = 0; i < books.Length; i++ )
            {
                Console.WriteLine("Enter a Book");
                books[i] = Console.ReadLine();
            }

            Console.WriteLine("******************");
            //loop through the array to display
            //its contents
            for (int i = 0; i < books.Length; i++ )
            {
                Console.WriteLine(books[i]);
            }

                Console.ReadKey();

        }
    }
}

Number Arrays

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

namespace NumberArraysMorning
{
    class Program
    {
        /// <summary>
        /// this program shows how to manipulate number
        /// arrays
        /// </summary>
     
        static void Main(string[] args)
        {
            //make a new random number
            Random rand = new Random();

            //declare an array. an array is a variable
            //that can store more than one value
            //at a time. An array is marked by using
            //square brackets [] after the data type
            //an array must always have a value fo length 
            //before you can use it. Arrays are also
            //objects and must be made new to use
            int[] numberArray = new int[50];
            int ones = 0, twos = 0, threes = 0, fours = 0;

            //populate the array
            for(int i=0;i<numberArray.Length;i++)
            {
                //at each index (represented by the
                //counter i )place a random number
                //between 1 and 4
                numberArray[i] = rand.Next(1, 5);
            }

            //loop through the array and count how
            //many of each number there is
            for (int i = 0; i < numberArray.Length; i++)
            {
                if (numberArray[i] == 1) { ones++; }
                if (numberArray[i] == 2) { twos++; }
                if (numberArray[i] == 3) { threes++; }
                if (numberArray[i] == 4) { fours++; }
              
            }

            //display the results
            Console.WriteLine("ones {0}, twos {1}, threes {2}, fours {3} ",
                ones,twos,threes,fours);

            //make string with the same number of astrics
            //as the number of ones
            Console.Write("\nOnes\t");
            for (int i = 0; i < ones; i++ )
            {
                Console.Write("*");
            }
            //twos
            Console.Write("\nTwos\t");
            for (int i = 0; i < twos; i++)
            {
                Console.Write("*");
            }
            //threes
            Console.Write("\nThrees\t");
            for (int i = 0; i < threes; i++)
            {
                Console.Write("*");
            }
            //fours
            Console.Write("\nFours\t");
            for (int i = 0; i < fours; i++)
            {
                Console.Write("*");
            }

            //new array of 50 elements
            int[] numberArrayB = new int[50];
            //populate the array with numbers between
            //1 and 999
            for (int i = 0; i < numberArrayB.Length; i++ )
            {
                numberArrayB[i] = rand.Next(1, 1000);
            }

            //declare a vaiable to store the maximum
            int max = 0;
            //loop through the array
            for (int i = 0; i < numberArrayB.Length; i++)
            {
                //check to see if the number at the index
                //is bigger than the current max
                //if it is replace max with the new number
                if (numberArrayB[i] > max)
                {
                    max = numberArrayB[i];
                }
            }

            //declare variables
            int sum = 0; 
            double average = 0;
            //loop and accumulate values into a sum
            for (int i = 0; i < numberArrayB.Length; i++)
            {
                sum += numberArrayB[i];
                //same as sum = sum + numberArrayB[i];
            }

            //get the average
            average = (double)sum / numberArrayB.Length;
            
            //display the average
            Console.WriteLine("\nthe average is {0}", average);

            //two ways to do max--our loop above
            //and using the Max() function built into arrays
            //Console.WriteLine("\nthe max is " + max);
            Console.WriteLine("\nthe max is " + numberArrayB.Max());
                Console.ReadKey();
        }
    }
}


Monday, October 13, 2014

Arrays (Evening)

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

namespace ArrayExamples
{
    class Program
    {
        static void Main(string[] args)
        {
            //an array is a variable can store more than one value
            //this declares a string array that has 4 elements
            //the square brackets [] are the mark of an array
            //rather than just a string variable
            //arrays must always be made new before they
            //can be used
            string[] members =new string[4];
            members[0] = "Rebecca";//arrays values are indexed
            members[1] = "George";//indexes begin at 0
            members[2] = "Karen";
            members[3] = "Joe";

            //you can access the array's members
            //by their index
            Console.WriteLine("the Third member is {0}", members[2]);

            string[] colors;
            Console.WriteLine("How many colors do you want to enter");
            int number = int.Parse(Console.ReadLine());

            //the length of an array can be a variable
            //but the variable must have a value
            //before you declare the array
            colors = new string[number];
            for (int i = 0; i < colors.Length; i++ )
            {
                //prompt the user for the values
                //to store in the array
                //the i is the for loop counter
                //it can substitute as a variable
                //for the array index
                Console.WriteLine("enter Color");
                colors[i] = Console.ReadLine();
            }

            Console.WriteLine("*******************");
            //loop through and write out the array values
            for (int i = 0; i < colors.Length; i++)
            {
                Console.WriteLine(colors[i]);
            }

            //another way to declare an array
            //the literal values are placed betwee
            //curley braces {}
            //you don't have to give the lenth
            //it can figure it out
            string[] dogs = new string[] 
            { "spaniel", "pug", "golden retreiver", "huskey", "Yorkie" };

            //can still access the values by index value
            Console.WriteLine("Choose a number 1 to 5");
            int dog = int.Parse(Console.ReadLine());

            //minus one to adjust for the 0 index
            Console.WriteLine("Your dog is {0}", dogs[dog-1]);

                Console.ReadKey();
        }
    }
}

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

namespace NumberArrays
{
    class Program
    {
        static void Main(string[] args)
        {
            //declare and initialize variables
            int ones = 0, twos = 0, threes = 0, fours = 0;
            //create a random object
            Random rand = new Random();
            //create a new integer array with 50 elements
            int[] numberArray = new int[50];

            // populate array by looping through and 
            //assigning a random number to each index
            for(int i=0;i<numberArray.Length;i++)
            {
                numberArray[i] = rand.Next(1, 5);
            }

            //loop through the array and count
            //how many times each number occurs
            foreach (int i in numberArray)
            {
                if (i == 1) { ones++; }
                else if (i == 2) { twos++; }
                else if (i == 3) { threes++; }
                else { fours++; }
        
            }

            //create an asteric graph
            //for each number
            Console.Write("\nOnes:\t");
            for (int i = 0; i < ones; i++)
            {
                Console.Write("*");
            }

            Console.Write("\nTwos:\t");
            for (int i = 0; i < twos; i++)
            {
                Console.Write("*");
            }

            Console.Write("\nThrees:\t");
            for (int i = 0; i < threes; i++)
            {
                Console.Write("*");
            }

            Console.Write("\nFours:\t");
            for (int i = 0; i < fours; i++)
            {
                Console.Write("*");
            }

            // new array declaration
            int[] numbersArray2 = new int[50];
            for (int i = 0; i < numbersArray2.Length; i++)
            {
                numbersArray2[i] = rand.Next(1, 1000);
            }

            //declare max variable
            int max = 0;
           
            //if the current number is larger than
            //the stored maximum number
            //then make it the maximum
            foreach(int i in numbersArray2)
            {
                if (i > max) { max = i; }
            }

            //or you could just use the built in
            //max function
            int maxb=numbersArray2.Max();

            Console.WriteLine("\nthe max is " + max);

            //*************************
            //here is a two dimensional array
            //as declared it has 3 rows and 2 columns
            string[,] books=new string[3,2];
            books[0, 0] = "The Lord of the Rings";
            books[0, 1] = "Tolkein";
            books[1, 0] = "The Grapes of Wrath";
            books[1, 1] = "Steinbeck";
            books[2, 0] = "The martian chronicles";
            books[2, 1] = "Ray Bradbury";

            Console.WriteLine("Enter an author");
            string author = Console.ReadLine();
            //all of our titles are in the 0 column
            //all our authors are in the 1 column
            for (int i = 0; i < 3; i++)
            {
                //see if the authors match
                //i is the counter for the current row
                //1 is the author column
                if (author.Equals(books[i, 1]))
                {
                    //return the title
                    Console.WriteLine(books[i, 0]);
                }
            }
                Console.ReadKey();
        }
    }
}


Requirements and Business Rules

Requirements:

Def: Something the database has to do in order to fulfill its purpose.

The database must store data about any book that is reviewed
The database must store Reviews and comments on Reviews
It will have a list of registered reviewers
Every review will have a numerical rating
The database will list of categories and books that belong to those categories
It must be searchable by Title, Author, Rating, Date of Review, Reviewer, Category, ISBN, Publication date

Security Rules (Access Rules)

Only registered reviewers can enter reviews and comments
A registered reviewer can only edit their own reviews and comments
Any use can read and search the database

Business Rules:

Def: (How) the way the organization processes and manages data

Only registered Reviewers can enter or edit reviews
Only registered Reviews can comment
All reviews and comments must be signed
To register the user has to agree to terms and provide a user name, a password, a valid email address
Passwords will be hashed
The numerical rating will range from 1 to 5, 5 being highest.
The lengths of reviews is unlimited.
Allow reviews of self published ebooks.
Violation of terms can get a reviewer removed from Database
Abusive reviews and comments can be removed

Nouns:

Book, author, Isbn, reviewer, email, Title, Review, Comment, Rating, Date of Review, Publication Date, Category, Password, user Name

Entities

Book
ISBN
Title
Publication date
Category
Author

Review
Book
Reviewer
Date of Review
Rating
comments

Author
name
description

etc.

Candidate Keys:

Def: an attribute or attributes that might make a good key field

Types of keys

Natural—uses attributes that belong to the entity as a key

Composite—combination of attributes that are unique

Surrogate--autogenerated

Thursday, October 9, 2014

For Loops (Morning)

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

namespace LoopExamplesMorning
{
    class Program
    {
        static void Main(string[] args)
        {
            int prime=1; 
            ////a basic for has 3 parts
            ////declare a counter
            ////declare the stop point
            ////increment the counter
            for (int i = 1; i < 5; i++)
            {
                //a mathematical oddity that lists 41 prime number
                //it is only here to show you can do things in
                //a loop and you can use the counter
                prime = i * i - i + 41;

                Console.WriteLine("this is loop {0}", prime);

            }//end of for

            //this loop decrements--that is it counts backwards
            //
            for (int i = 10; i >= 0; i--)
            {

                Console.WriteLine(i);
                //Console.ReadKey();

            }//end for

            //this declares a new random object
            Random rand = new Random();
            // +=, *=, /=, -+, %=

            for (int i = 1; i <= 10; i ++)
            {

                //the Next method of random
                //returns a random number
                //you can specify the lower and upper bounds
                int number = rand.Next(1, 5);

                Console.WriteLine(number);
            }

            //while loops are good for looping
            //when you don't know how many loops
            //you want to do. they keep looping
            //until the condition in parenthesis
            //is no longer true
            string keepLooping="yes";
            int counter = 0;

            while(keepLooping.Equals("yes"))
            {
                counter++; //just counting the loops
                Console.WriteLine("this is loop {0}", counter);
                //get user input on whether to continue
                //or quit the loop
                Console.WriteLine("Do you want to continue; yes, no");
                keepLooping = Console.ReadLine(); 
                //put the answer all in lower case
                keepLooping = keepLooping.ToLower();
                //check the answer. We will only exit
                //if it equals "no
                if (!keepLooping.Equals("no"))
                {
                    keepLooping = "yes";
                }

            }

            do
            {
            } while (keepLooping.Equals("yes"));

            Console.ReadKey();
        }
    }
}

Wednesday, October 8, 2014

Loops(Evening Class)

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)
        {
            //random is a built in object 
            //it is not static so we have to make it new
            //making it new loads it into memory
            //and runs the objects construction
            Random rand = new Random();

            //basic for loop (three parts)
            //declare a counter variable and give it an initial value
            //give it a terminal value
            //increment the counter
            for(int i=0;i<10;i++)
            { 
                //this returns a random number
                //between 1 and 500
                int number = rand.Next(1, 501);
                Console.WriteLine(number);
            }

            for (int i = 10; i >=0; i--) //decrements
            {

                int number = rand.Next(1, 501);
                Console.WriteLine(number);
            }

            Console.WriteLine("***********************");
            int number2 = 3;

            for (int i = 0; i < 10;i++ )
            {
                //same as number2 = number2 + i;
                //other shorcut operators
                // +=, -=, *=, /=
                number2 += i; 
                Console.WriteLine(number2);
            }

            //can use a variable for the end condition
            Console.WriteLine("How many loops?");
            int numberOfLoops = int.Parse(Console.ReadLine());
            for (int i = 1; i <= numberOfLoops; i++)
            {
                //same as number2 = number2 + i;
                // +=, -=, *=, /=
                number2 *= i;
                Console.WriteLine(number2);
            }

            // a while loop loops until the condition
            //is no longer true
            string go = "yes";
            int counter = 0;
            while (go.Equals("yes") || go.Equals("Yes"))
            {
                counter++;
                Console.WriteLine("You have done {0} loops", counter);
                Console.WriteLine("Do you want to do another: Yes or no?");
                go = Console.ReadLine();
            }

            // a do loop evaluates the condition
            //at the end--guarantees at least one
            //loop occurs
            do
            {

            }while (go.Equals("Yes"));

                Console.ReadKey();
        }

      


    }
}

Wednesday, October 1, 2014

Selection Examples (evening Class)

Here is the first example: a mess but with examples of different forms of the if statements

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

namespace SelectionExamples
{
    class Program
    {
        /// 
        /// this program just contains examples
        /// of if statements--it doesn't actually
        /// constitute an actual program
        /// Steve Conger Evening Class 10/1/2014
        /// 
        /// 
        static void Main(string[] args)
        {
            //first example shows a password
            //never put the password in the code
            //in real life
            string pass = "P@ssw0rd1";
            Console.WriteLine("Enter your password");
            string userPass = Console.ReadLine();

            //for string the "Equals" keyword 
            //provides better comparisons than "=="
            if(pass.Equals(userPass))
            {
                Console.WriteLine("thank You");
            }
            else //if the passwords don't match
            {
                Console.WriteLine("Sorry");
                Console.ReadKey();
                return;
            }

            int number;
            Console.WriteLine("enter a number");
            //TryParse returns a bool (true or false). 
            //It returns true if the string can be parsed
            //false if it cannot
            //if it is true it also assigns the value to the
            //variable named as an "out" parameter
           
            bool goodNumber = int.TryParse(Console.ReadLine(),out number);
            if (goodNumber==false) //or if (!goodNumber)
            {
                Console.WriteLine("Restart and enter a valid integer");
                Console.ReadKey();
                return;
            }

            // Or is represented as || 
            //you must repeat the variable name on both sides
            //of the || operator
            if(number < 20 || number > 60)
            {
            }

            // && is for and
            if (number > 20 && number < 60)
            {

            }
            //you can use these comparison operators
            // >, <, <=, >=, !=, ==

            //this is an else, else if, else block
            //it checks each condition
            //if the condition is true executes the commands
            //in the block. It then exits the block and exectutes
            //the commands after the if else bloc
            //If it is false, it skips the block
            //and checks the next condition
            //if none of the conditions are true
            //it does what is in the else block
            if (number == 21)
            {
                Console.WriteLine("Drinks too much");
            }//end if
            else if (number > 21)//resolve to boolean
            { 
                Console.WriteLine("Old enough to drink");
            }//end if
            else 
            {
                Console.WriteLine("Still too young");
            }

            Console.ReadKey();
        }
    }
}

Here is the second example using the birth year

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

namespace AgeGame
{
    class Program
    {
        /// 
        /// This class is just an example of if  and if else
        /// statements. The if statements are nested
        /// first it tests if the entry is the right length
        /// if it is, then it tests if it is a valid integer,
        /// if it is, then it calculates the age of the user
        /// by subtracting the users birth year from the 
        /// current year. When it has the age it ouputs 
        /// a different message based on the age
        /// Steve conger Evening Class 10/1/2014
        /// 
      
        static void Main(string[] args)
        {
            int year;
            //prompt the user for a birth year
            Console.WriteLine("Enter the year of your birth (a 4 digit integer)");
            //read the string from console
            string yearString = Console.ReadLine();
            //make sure the string is 4 characters
            if(yearString.Length == 4)
            {
                //if it is 4 characters make sure it is an integer
                bool goodYear = int.TryParse(yearString, out year);
                if(goodYear)
                {
                    //if it is a good integer
                     //get the current year
                    int currentYear = DateTime.Now.Year;
                    //subract the user's birth year from the current year
                    int yearsOld = currentYear - year;
                    //output the result
                    Console.WriteLine("You are {0} years old",yearsOld);

                    //declare a string variable with no content
                    string message = null;

                    //test the age and assign a different text
                    //to the message string depending on the age
                    if (yearsOld > 50)
                    {
                        message = "Well done";
                    }
                    else if (yearsOld > 40)
                    {
                        message="Age perfection";
                    }
                    else if(yearsOld > 30)
                    {
                        message = "Just getting going";
                    }
                    else if(yearsOld > 20)
                    {
                        message = "Youth is wasted on the young";
                    }
                    else
                    {
                        message = "just getting started";
                    }
                //output the message
                    Console.WriteLine(message);
                }//end inner if
                else
                {
                    //if the value isn't a good integer
                    Console.WriteLine("Start over and enter a four digit integer for a year");
                }
      
            }//end outer if
            else
            {
                //if the value isn't four characters long
                Console.WriteLine("Start over and enter a four digit integer for a year");
            }
            Console.ReadKey();
        }//end main
    }
}

Interview and questionnaire questions for Book Reviewers Database

I would define two basic stakeholders:
a: the core book club of reviewers
b: the unregistered user

There were no forms or reports to review, though it would be useful to look at other sites that provide reviews and check their conventions and rules.


Questions for the core book club of Reviewers

What are the minimum requirements to register as a reviewer? What information would a reviewer need to provide?

What conditions would require a registered reviewer to be removed from the database?

What information about the book is required for the database?

Do you intend to review self published eBooks? (no ISBN)

Are there minimum requirements for a review?

How long is the average review?

Are there limits to the size of the review?

You mentioned a rating scale. Is it 1-5 or 1-10 or something else?

Do reviews ever expire? That is do they go away after a certain length of time or do the stay forever?

What are the rules for commenting on a review?

Is there a maximum length for a comment?


Questionnaire for potential unregistered users

When searching for reviews, which of the following terms would you like to be able to search by? check all that apply."

Title
Author
Category/genre
Rating
Reviewer
Review Date
Other

What book information would you consider essential? Mark all that apply?

Title
Author
publisher
publish date
ISBN
Price
Other

Which of the above are most important. Rank them 1-6(7)

Title
Author
publisher
publish date
ISBN
Price
Other

Do you see yourself as using this site to search book reviews?

Yes No

Would you consider registering as a reviewer?

Yes No