SQL SAMSON

everything sql

Archive for September 2008

Visual c# 2008 Hello (Unicode) World (Hexidecimal)…

leave a comment »

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

namespace HelloWorld
{
   class Program
   {
      static void Main(string[] args)
      {
         ConsoleTitle();
         Greeting();
      }
      static void Greeting()
      {
         string strHello = “\u0048\u0065\u006C\u006C\u006f\n”;
         // Unicode of Hello

         string strWorld = “\x77\x6F\x72\x6c\x64\x21\b”;
         // Hexidecimal of world

         Console.Write(“{0}”, strHello);
         Console.Write(“{0}”, strWorld);
         Console.ReadLine();
      }
      static void ConsoleTitle()
      {
         string strTitle = “Hello(Unicode) World(Hexidecimal) v0.01”;
         Console.Title = strTitle;
      }
   }
}

Written by Samson Loo

September 26, 2008 at 12:17 am

Java Centimeters to Inches Calc…

with one comment

As before here is the Java version of the Centimeters to Inches calculator.

[ Main.java ]
public class Main
{
   public static void main(String[] args)
   {
      GetUserInput.GetInput();
   }
}

[ GetUserInput.java ]
import java.util.*;
public class GetUserInput
{
  &nbspstatic void GetInput()
   {
      String strUserInput;
      Scanner in = new Scanner(System.in);
      System.out.print(“Enter Centimeters: “);
      strUserInput = in.nextLine();
      in.close();
      ConvertUserInput.ConvertInput(strUserInput);
   }
}

[ ConvertUserInput.java ]
public class ConvertUserInput
{
   static void ConvertInput(String s)
   {
      double d;
      d = Double.parseDouble(s);
      PerformCalculation.Calculate(d);
   }
}

[ PerformCalculation.java ]
public class PerformCalculation
{
   static void Calculate(double i)
   {
      double cm = 0.393700787;
      double total;
      total = (i * cm);
      DisplayResults.Results(total);
   }
}

[ DisplayResults.java ]
public class DisplayResults
{
   static void Results(double r)
   {
      System.out.println(“total Inches: “ + r);
   }
}

Written by Samson Loo

September 22, 2008 at 9:18 pm

Visual c# 2008 Centimeters to Inches Calc…

leave a comment »

My spouse needed to figure out what 83 cm equaled in inches. I know the formula, so I could have easily written this out by hand…but why? I also know that I could have written this using one file…but why? This is another example of how to separate methods into separate class files.

Well 1 inch = 0.393700787 centimeters, so 83 * 0.393700787 = 32.677165321 inches!

[ Program.cs ]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CM2IN
{
   class Cent2Inches
   {
      static void Main(string[] args)
      {
         SetConsoleTitle.ConsoleTitle();
         GetUserInput.UserInput();
      }
   }
}

[ SetConsoleTitle.cs ]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CM2IN
{
   class SetConsoleTitle
   {
      public static void ConsoleTitle()
      {
         string strTitle = “Centimeter to Inches Calculator v1.0”;
         // Set Console Title
         Console.Title = strTitle;
      }
   }
}

[ GetUserInput.cs ]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CM2IN
{
   class GetUserInput
   {
      public static void UserInput()
      {
         string strUserInput;
         Console.Write(“Enter Centimeters: “);
         // Prompt for user input
         strUserInput = Console.ReadLine(); // Read user input
         ConvertUserInput.ConvertInput(strUserInput);
         // Pass user input to Convert Class
      }
   }
}

[ ConvertUserInput.cs ]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CM2IN
{
   class ConvertUserInput
   {
   public static void ConvertInput(string s)
      {
         double d;
         d = Convert.ToDouble(s); // Convert string to double
         PerformCalculation.Calculate(d);
         // Pass double value to Calculation Class
      }
   }
}

[ PerformCalculation.cs ]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CM2IN
{
   class PerformCalculation
   {
      public static void Calculate(double i)
      {
         double cm = 0.393700787;
         double total;
         total = (i * cm); // Perform Calculation
         DisplayResults.Results(total);
         // Pass Results to Display results Class
      }
   }
}

[ DisplayResults.cs ]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CM2IN
{
   class DisplayResults
   {
      public static void Results(double r)
      {
         Console.WriteLine(“Total Inches: ” + r); // Print results
         Console.ReadLine();
         Console.Clear();
      }
   }
}

Written by Samson Loo

September 22, 2008 at 6:28 pm

Visual c# 2008 Hello User 1.2 Console App…

leave a comment »

I decided to split up the code into two files to illustrate how to call a separate class. It is overkill for such a simple application, but it is an example!

[ Program.cs ]

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

namespace HelloUser
{
   class Program
   {
      public static void GetUserInput()
      {
         string strInput;

         Console.Write(“Enter your first name: “);
         strInput = Console.ReadLine();
         Console.WriteLine(“Hello “ + strInput);
         Console.ReadLine();
      }
      public static void SetGreeting()
      {
         string strTitle = “Hello User 1.2”;
         Console.Title = strTitle;
      }
   }
}

[ AppTest.cs ]

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

namespace HelloUser
{
   class AppTest
   {
      static void Main(string[] args)
      {
         Program.GetUserInput();
         Program.SetGreeting();
      }
   }
}

Written by Samson Loo

September 18, 2008 at 7:27 pm

Hello User Java Edition Console App…

leave a comment »

import java.util.*;
public class HelloUser
{
   public static void main(String[] args)
   {
      GetUserInput();
   }
   private static void GetUserInput()
   {
      String strInput;
      Scanner in = new Scanner(System.in);
      System.out.println(“Enter your first name: “);
      strInput = in.nextLine();
      in.close();
      System.out.println(“Hello “ + strInput);
   }
}

Written by Samson Loo

September 16, 2008 at 1:51 am

Posted in hello user, JAVA

Hello World Java Edition Console App..

leave a comment »

As you can see the syntax is similar to that of C#

public class HelloWorld
{
   public static void main(String[] args)
   {
      Greeting();
   }
   private static void Greeting()
   {
      System.out.println(“Hello world!”);
   }
}

Written by Samson Loo

September 16, 2008 at 1:49 am

Posted in Hello World, JAVA

Visual c# 2008 Hello User 1.1 Console App…

leave a comment »

This is a much better approach of writing Hello User. It does require a few more lines of code, but it is better for modularity purposes. It is not a good practice to write everything in the Main method as I did in the previous examples.

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

namespace HelloUser
{
   class Program
   {
      static void Main(string[] args)
      {
         SetConsoleTitle();
         GetUserInput();
      }
      static void GetUserInput()
      {
         string strInput;
         Console.Write(“Enter your first name: “);
         strInput = Console.ReadLine();
         Console.WriteLine(“Hello “ + strInput);
         Console.ReadLine();
      }
      static void SetConsoleTitle()
      {
         string strTitle = “Hello User 1.1”;
         Console.Title = strTitle;
      }
   }
}

Prompt for input

Write to screen

Written by Samson Loo

September 15, 2008 at 4:25 pm

SQL (70-431) Question of the week…Q3

leave a comment »

You are the database administrator for a shipping company named Cargoflow. You are asked to create a database for the company’s marketing department for trend analysis of shipments. This database will be bulk loaded with information from a data warehouse when it is first created. Data will be analyzed but not modified in any way. You are trying to decide on an appropriate recovery model for the database. Which recovery model should you implement for this new database? Choose the best option(s) from those listed below.

a) Full recovery
b) Bulk-logged recovery
c) Simple recovery
d) Warehouse recovery

Self Evaluation:
Compare your answer to the explanation and correct option(s) provided below.

Explanation:
The simple recovery model is the most appropriate recovery model to use in this scenario. Since the data in the database will never change, point-of-failure recovery is not necessary. This means that data in the transaction log is not critical to recovering the database and does not necessitate being backed up. The simple recovery model relies strictly on full and differential backups of the database to recover.

Correct Option(s):
c) Simple recovery

Incorrect Option(s):
a) Full recovery – The full recovery model is inappropriate in this scenario due to the unnecessary administrative overhead associated with transaction log backups.
b) Bulk-logged recovery – The bulk-logged recovery model is inappropriate in this scenario due to the unnecessary administrative overhead associated with transaction log backups.
d) Warehouse recovery – SQL Server 2005 does not support a warehouse recovery model.

Questions Provided by SkillSoft

Written by Samson Loo

September 15, 2008 at 12:38 pm

Visual c# 2008 Hello User Console App…

leave a comment »

The HelloWorld app showed you how to make a simple app that uses static data. Here is an app that prompts for user input. Same concept just a few more lines!

// Directive
using System;
using System.Collections.Generic;
using System.Linq; // Remove if being used in Visual C# 2005
using System.Text;

namespace HelloUser
{
   class Program
   {
      // Main Method
      static void Main(string[] args)
      {
         // Data Members
         string strTitle = “Hello User 1.0”; // Set string value
         string strInput; // Declare variable
         Console.Title = strTitle; // Set console title
         Console.Write(“Enter your first name: “); // Prompt for input
         strInput = Console.ReadLine(); // Read user input
         Console.WriteLine(“Hello “ + strInput); // Write line of text
         Console.ReadLine(); // Read line of text
      }
   }
}

Written by Samson Loo

September 15, 2008 at 4:13 am

Visual c# 2008 Hello World Console App…

leave a comment »

I figured I would post a simple Hello World Console Application built with Visual C# 2008. So here we go.

// Directive
using System;
using System.Collections.Generic;
using System.Linq; // Remove if being used in Visual C# 2005
using System.Text;

namespace HelloWorld
{
   class Program
   {
      // Main Method
      static void Main(string[] args)
      {
         // Data Members
         string strOutput = “Hello World”; // Set string value
         Console.Title = strOutput; // Set console title
         Console.WriteLine(strOutput); // Write line of text
         Console.ReadLine(); // Read line of text
      }
   }
}

Written by Samson Loo

September 15, 2008 at 3:27 am