Sunday, April 22, 2012

New PC.

Well, I've got the new PC built. Here are the specs, for anyone interested:
  • Case: NZXT Switch 810 (Black) 
    • 2x Superbright LED bars (red) 
    • 10x 140mm Enthusiast 3 Speed Fluid Dynamic Bearing Fans (2k RPM) 
    • NZXT Sentry Mix 6 Channel Fan Controller
  • Mobo: Gigabyte GA-Z77X-UD5H LGA 1155 Socket 
  • CPU: Intel Core i5-2550k (Overclocked to 4.3 Ghz from 3.6 Ghz) 
    • Corsair Hydro Series H100 CPU Liquid Cooler 
  • RAM: 16 GB (2x 8GB sticks) Corsair Vengeance DDR3 1600 
  • GPU: Asus Radeon HD 7850 
  • PSU: Corsair AX750 Modular Power Supply (Gold+ Cert'd) 
  • HDD
    • 1x 1TB Seagate Barracuda (Boot drive) 
    • 3x 1TB Seagate Barracuda (RAID 5 array, Intel Z77 Chipset)
I plan to upgrade the boot drive to an SSD eventually, but I'm waiting until the market on pric per gigabyte stabilizes. Right now, 1 GB can range from $1 to $5, depending on manufacturer. It's not a huge issue for me, though.

I mean, boot times have been my largest complaint about PC's since I started using them back in the early 1990s, and while it's gotten better, it still takes a while sometimes. From a hard startup, It's 15 seconds to get the login screen for Windows, which is a LOT better than the 60-90 seconds of the HP Pavilion that just died!

The top of the case has a "fan grill" (for lack of a better term in my brain at the moment) that you can open and close by pulling a lever at the back of the case. Leaving it open means that you have a bit more fan noise, but the case exhausts more heat than if it were closed. Likewise, when closed, the case is pretty silent.

The front two fans (hidden behind a touch-open panel at the front of the case) have an air filter to catch dust and whatnot, and the bottom of the case features a mesh bottom that lets air come in also (which has two mounts for 120mm or 140mm fans, which fit next to the PSU). That bottom mesh area has an air filter for the entire length of the case, 1 accessible from the front and 1 from the back. It's pretty awesome.

Pictures: 

I hate my new phone (Pancrap Breakout). Pictures are crud!

Sunday, April 15, 2012

My Computer Is Dead

[Posting from my phone, so I hope this goes through]

Well, it finally happened.

I was planning my build for a new computer, considering that this one has been acting up for the past 6 months.

The old HP Pavilion It finally died today at about 2PM. Thermal paste, canned air, anti-static wrist strap, and screwdriver ready, I dove in to perform life saving surgery, but unfortunately nothing that I did was the answer.

The motherboard, arguably the heart of the computer (the CPU being the brain, right?) was failing, and so its on-board fan controller wouldn't spin up the system or CPU fans. The Fates decided that it was too late, though. The Laws of Thermodynamics did their job. (I've saved the processor and video card, though!).

I'm throwing the extra cash at next-day shipping so that I can get the new machine built and ready to go before the end of the week (I hope! Hard to do with classes Monday-Thursday, on top of working full time).

I've managed to save the CPU, VGA, and HDD set...so perhaps I'll go buy a cheap case, paint it pink, and grab some cheap components to give my daughter her first computer. She's 6 years old - it's high time she got into fixing computers and learning how everything works!

I'll let it connect to the internet, but will filter that IP so that it can only visit the PBS kids page ;-)


...Who would have thought that the voice-input system on a droid could have typed all this up for me? Pretty awesome!

Monday, April 2, 2012

CIS 217: Enumerated Data Types &, Structures Assignment [Slot Machine Sim]

Another assignment for Chapter 8, the slot machine simulator was a quick and easy project to have some "fun" with. I may pass it off to my wife to see if she has a problem gambling ;-)

Again, my first step was to add an ImageList control ("imglSlots") to the form, set it's ImageSize property to 128 x 128, and add the images that I was going to use. My form looked just as it did in the book, so no change there.

My second step was to create the Enumerated data-type to hold all of the possible fruit choices:
    public enum Fruit { Apple, Banana, Cherries, 
                        Grapes, Lemon, Lime, 
                        Orange, Pear, Strawberry, 
                        Watermelon }

My third step was to create a Spin() method for each slot, called "Slot1_Spin()", which determines what the result is going to be out of the total possible results, and displays the resulting fruit image from the ImageList control. These were created for each slot, and thrown into the _Click event of the "Spin" button:
        public void Slot1_Spin()
        {
            int index = rand.Next(0, 10);         

            switch (index)
            {
                case 0:
                    Slot1Fruit = Fruit.Apple;
                    pbSlot1.Image = imglSlots.Images[index];
                    break;
                case 1:
                    Slot1Fruit = Fruit.Banana;
                    pbSlot1.Image = imglSlots.Images[index];
                    break;
            }
        }

My fourth step, although probably considered even more simple than creating the above methods, was to create the conditionals to deal with winning the game:
                if (Slot1Fruit == Slot2Fruit)
                {
                    Winnings = 2 * AmtEntered;
                    Total += Winnings;
                    MessageBox.Show("You have won 2x the amount entered (" + Winnings.ToString("c") + ")");
                    Win = true;
                }

My thoughts on this section of the chapter are pretty simple: enumerated data types are very important to learn, which I think the examples given in the book plainly show (creating the "days of the week"). Yes, there are other ways to do it, but enums make the process much simpler. The only irksome thing that I've ever had to deal with while using enums is what is also discussed in the book, being that you cannot directly compare some things to the enum itself, but I'm sure that caveat will be addressed later in the book for those who don't know how to get around it.

*Note: Yes, I skimped on the TextBox and getting the bet info from the user, however I wanted to spend time with my wife and children since I haven't seen them much this past week, and so I took shortcuts where I could without impacting the overall running of the program (unless you're blatantly trying to break it).

Here is the full code for the assignment:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SlotMachineSimulation
{
    public enum Fruit { Apple, Banana, Cherries, 
                        Grapes, Lemon, Lime, 
                        Orange, Pear, Strawberry, 
                        Watermelon }
    
    public partial class frmMain : Form
    {
        public Random rand = new Random();
        public Fruit Slot1Fruit, Slot2Fruit, Slot3Fruit;
        public double AmtEntered, Total, Winnings;

        public frmMain()
        {
            InitializeComponent();
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            MessageBox.Show("You won a total of: $" + Total.ToString());
            this.Close();
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            pbSlot1.Image = imglSlots.Images[0];
            pbSlot2.Image = imglSlots.Images[1];
            pbSlot3.Image = imglSlots.Images[2];
        }

        private void btnSpin_Click(object sender, EventArgs e)
        {
            if (txtAmtInserted.Text == "")
            {
                MessageBox.Show("Please place a bet!");
            }
            else
            {
                AmtEntered = double.Parse(txtAmtInserted.Text);
                bool Win = false;

                Slot1_Spin();
                Slot2_Spin();
                Slot3_Spin();

                if (Slot1Fruit == Slot2Fruit)
                {
                    Winnings = 2 * AmtEntered;
                    Total += Winnings;
                    MessageBox.Show("You have won 2x the amount entered (" + Winnings.ToString("c") + ")");
                    Win = true;
                }

                if (Slot2Fruit == Slot3Fruit)
                {
                    Winnings = 2 * AmtEntered;
                    Total += Winnings;
                    MessageBox.Show("You have won 2x the amount entered (" + Winnings.ToString("c") + ")");
                    Win = true;
                }
                if (Slot1Fruit == Slot2Fruit && Slot2Fruit == Slot3Fruit)
                {
                    Winnings = 3 * AmtEntered;
                    Total += Winnings;
                    MessageBox.Show("You have won 3x the amount entered (" + Winnings.ToString("c") + ")");
                    Win = true;
                }
            }
        }


        public void Slot1_Spin()
        {
            int index = rand.Next(0, 10);         

            switch (index)
            {
                case 0:
                    Slot1Fruit = Fruit.Apple;
                    pbSlot1.Image = imglSlots.Images[index];
                    break;
                case 1:
                    Slot1Fruit = Fruit.Banana;
                    pbSlot1.Image = imglSlots.Images[index];
                    break;
                case 2:
                    Slot1Fruit = Fruit.Cherries;
                    pbSlot1.Image = imglSlots.Images[index];
                    break;
                case 3:
                    Slot1Fruit = Fruit.Grapes;
                    pbSlot1.Image = imglSlots.Images[index];
                    break;
                case 4:
                    Slot1Fruit = Fruit.Lemon;
                    pbSlot1.Image = imglSlots.Images[index];
                    break;
                case 5:
                    Slot1Fruit = Fruit.Lime;
                    pbSlot1.Image = imglSlots.Images[index];
                    break;
                case 6:
                    Slot1Fruit = Fruit.Orange;
                    pbSlot1.Image = imglSlots.Images[index];
                    break;
                case 7:
                    Slot1Fruit = Fruit.Pear;
                    pbSlot1.Image = imglSlots.Images[index];
                    break;
                case 8:
                    Slot1Fruit = Fruit.Strawberry;
                    pbSlot1.Image = imglSlots.Images[index];
                    break;
                case 9:
                    Slot1Fruit = Fruit.Watermelon;
                    pbSlot1.Image = imglSlots.Images[index];
                    break;
            }
        }

        public void Slot2_Spin()
        {
            int index = rand.Next(0, 10);

            switch (index)
            {
                case 0:
                    Slot2Fruit = Fruit.Apple;
                    pbSlot2.Image = imglSlots.Images[index];
                    break;
                case 1:
                    Slot2Fruit = Fruit.Banana;
                    pbSlot2.Image = imglSlots.Images[index];
                    break;
                case 2:
                    Slot2Fruit = Fruit.Cherries;
                    pbSlot2.Image = imglSlots.Images[index];
                    break;
                case 3:
                    Slot2Fruit = Fruit.Grapes;
                    pbSlot2.Image = imglSlots.Images[index];
                    break;
                case 4:
                    Slot2Fruit = Fruit.Lemon;
                    pbSlot2.Image = imglSlots.Images[index];
                    break;
                case 5:
                    Slot2Fruit = Fruit.Lime;
                    pbSlot2.Image = imglSlots.Images[index];
                    break;
                case 6:
                    Slot2Fruit = Fruit.Orange;
                    pbSlot2.Image = imglSlots.Images[index];
                    break;
                case 7:
                    Slot2Fruit = Fruit.Pear;
                    pbSlot2.Image = imglSlots.Images[index];
                    break;
                case 8:
                    Slot2Fruit = Fruit.Strawberry;
                    pbSlot2.Image = imglSlots.Images[index];
                    break;
                case 9:
                    Slot2Fruit = Fruit.Watermelon;
                    pbSlot2.Image = imglSlots.Images[index];
                    break;
            }
        }

        public void Slot3_Spin()
        {
            int index = rand.Next(0, 10);

            switch (index)
            {
                case 0:
                    Slot3Fruit = Fruit.Apple;
                    pbSlot3.Image = imglSlots.Images[index];
                    break;
                case 1:
                    Slot3Fruit = Fruit.Banana;
                    pbSlot3.Image = imglSlots.Images[index];
                    break;
                case 2:
                    Slot3Fruit = Fruit.Cherries;
                    pbSlot3.Image = imglSlots.Images[index];
                    break;
                case 3:
                    Slot3Fruit = Fruit.Grapes;
                    pbSlot3.Image = imglSlots.Images[index];
                    break;
                case 4:
                    Slot3Fruit = Fruit.Lemon;
                    pbSlot3.Image = imglSlots.Images[index];
                    break;
                case 5:
                    Slot3Fruit = Fruit.Lime;
                    pbSlot3.Image = imglSlots.Images[index];
                    break;
                case 6:
                    Slot3Fruit = Fruit.Orange;
                    pbSlot3.Image = imglSlots.Images[index];
                    break;
                case 7:
                    Slot3Fruit = Fruit.Pear;
                    pbSlot3.Image = imglSlots.Images[index];
                    break;
                case 8:
                    Slot3Fruit = Fruit.Strawberry;
                    pbSlot3.Image = imglSlots.Images[index];
                    break;
                case 9:
                    Slot3Fruit = Fruit.Watermelon;
                    pbSlot3.Image = imglSlots.Images[index];
                    break;
            }
        }
    }
}

CIS 217: Structures Assignment [Vending Machine Sim]

As the name of the assignment implied, we were directed to create a vending machine simulator. In regards to the design of the form, I went with how the book displayed it.

My first step was to add an ImageList control ("imgListLogos") to the form, set it's ImageSize to 64 x 64, and add the picture collection for each soda's logo. I also added six PictureBox controls, set their BorderStyle to Fixed3D, and named each after the soda that they would represent (pbCola, pbRootBeer, etc).

My second step, creating the event handlers for each PictureBox, was easy since I wasn't going to overload them - double-clicking each control gives it to me.

My third step was to create the Structure to hold the various properties of each soda (it's name, cost, logo, and how many are remaining in the vending machine). As the book dictates, this was done outside of the class, but inside of the project namespace:

public struct Soda
    {
        public string Name;
        public double Cost;
        public int Remaining;
        public int Logo;
    }

I also created the array of the Soda structure for easier maintenance of the data:

public partial class frmMain : Form
    {
        const int arrSIZE = 5;
        public double totalSales = 0.00;
        public Soda[] Sodas = new Soda[arrSIZE];

My third step, after creating the struct Soda, was to create a few methods to create each drink and it's associated data: the cost, number remaining, and the logo for each drink.

The method for creating each Soda structure, with associated properties:
public void CreateDrinks()
        {
            Sodas[0].Name = "Cola";
            Sodas[0].Cost = 1.00;
            Sodas[0].Remaining = 20;
            Sodas[0].Logo = 0;
        }

The method to display the logo, and the cost for each soda:
public void DisplayDrinks()
        {
            pbCola.Image = imglistLogos.Images[0];
            lblColaCost.Text = Sodas[0].Cost.ToString("c");
        }

And two methods to update the remaining number of drinks after a purchase is made:
public void UpdateTotalSales()
        {
            lblTotalSales.Text = totalSales.ToString("c");
        }

        public void UpdateRemaining()
        {
            lblColaRemaining.Text = Sodas[0].Remaining.ToString();
        }

My fourth step was to finally add code to each event handler to deal with the purchasing of each soda. This checks first to see if there are any remaining sodas of that type left. If there are, it will subtract 1 from the current value of .Remaining, update the totalSales with the cost of the soda, and then call the UpdateTotalSales() and UpdateRemaining() methods (which will update the labels associated with each). I did this for each PictureBox, except for the last (the one related to sales and not a particular soda):

private void pbCola_Click(object sender, EventArgs e)
        {
            if (Sodas[0].Remaining > 0)
            {
                Sodas[0].Remaining = Sodas[0].Remaining - 1;
                totalSales = totalSales + Sodas[0].Cost;
                UpdateTotalSales();
                UpdateRemaining();
            }
            else
            {
                MessageBox.Show("I'm Sorry, But That Drink Is Out Of Stock");
            }
        }

Thoughts:
I've done class-based development before in Visual Basic, and I am glad that the author introduces Structures before Classes, as it is a natural progression. However, I do not like how he "left the student hanging" by saying "you can do a lot more, but we're just going to cover the extreme basics". It would have been nice to give a few advanced examples of Struct use, and then re-visit those same examples with Class use, to show the similarities and differences, but oh well. All in all, a good chapter and something that gets closer to the topic that I want to learn about. Finally getting out of the "basics"!

Here is the code for the entire project:

Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DrinkVendingMachineSim
{
    public struct Soda
    {
        public string Name;
        public double Cost;
        public int Remaining;
        public int Logo;
    }

    public partial class frmMain : Form
    {
        const int arrSIZE = 5;
        public double totalSales = 0.00;
        public Soda[] Sodas = new Soda[arrSIZE];

        public frmMain()
        {
            InitializeComponent();
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            CreateDrinks();
            DisplayDrinks();
            UpdateRemaining();
        }

        public void UpdateTotalSales()
        {
            lblTotalSales.Text = totalSales.ToString("c");
        }

        public void UpdateRemaining()
        {
            lblColaRemaining.Text = Sodas[0].Remaining.ToString();
            lblRBRemaining.Text = Sodas[1].Remaining.ToString();
            lblLLRemaining.Text = Sodas[2].Remaining.ToString();
            lblGSRemaining.Text = Sodas[3].Remaining.ToString();
            lblCSRemaining.Text = Sodas[4].Remaining.ToString();
        }

        public void DisplayDrinks()
        {
            pbCola.Image = imglistLogos.Images[0];
            lblColaCost.Text = Sodas[0].Cost.ToString("c");

            pbRootBeer.Image = imglistLogos.Images[1];
            lblRBCost.Text = Sodas[1].Cost.ToString("c");

            pbLemonLime.Image = imglistLogos.Images[2];
            lbLLCost.Text = Sodas[2].Cost.ToString("c");

            pbGrapeSoda.Image = imglistLogos.Images[3];
            lbGSCost.Text = Sodas[3].Cost.ToString("c");

            pbCreamSoda.Image = imglistLogos.Images[4];
            lbCSCost.Text = Sodas[4].Cost.ToString("c");
        }

        public void CreateDrinks()
        {
            Sodas[0].Name = "Cola";
            Sodas[0].Cost = 1.00;
            Sodas[0].Remaining = 20;
            Sodas[0].Logo = 0;

            Sodas[1].Name = "Root Beer";
            Sodas[1].Cost = 1.00;
            Sodas[1].Remaining = 20;
            Sodas[1].Logo = 1;

            Sodas[2].Name = "Lemon Lime";
            Sodas[2].Cost = 1.00;
            Sodas[2].Remaining = 20;
            Sodas[2].Logo = 2;

            Sodas[3].Name = "Grape Soda";
            Sodas[3].Cost = 1.50;
            Sodas[3].Remaining = 20;
            Sodas[3].Logo = 3;

            Sodas[4].Name = "Cream Soda";
            Sodas[4].Cost = 1.50;
            Sodas[4].Remaining = 20;
            Sodas[4].Logo = 4;
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void pbCola_Click(object sender, EventArgs e)
        {
            if (Sodas[0].Remaining > 0)
            {
                Sodas[0].Remaining = Sodas[0].Remaining - 1;
                totalSales = totalSales + Sodas[0].Cost;
                UpdateTotalSales();
                UpdateRemaining();
            }
            else
            {
                MessageBox.Show("I'm Sorry, But That Drink Is Out Of Stock");
            }
        }

        private void pbRootBeer_Click(object sender, EventArgs e)
        {
            if (Sodas[1].Remaining > 0)
            {
                Sodas[1].Remaining = Sodas[1].Remaining - 1;
                totalSales = totalSales + Sodas[1].Cost;
                UpdateTotalSales();
                UpdateRemaining();
            }
            else
            {
                MessageBox.Show("I'm Sorry, But That Drink Is Out Of Stock");
            }
        }

        private void pbLemonLime_Click(object sender, EventArgs e)
        {
            if (Sodas[2].Remaining > 0)
            {
                Sodas[2].Remaining = Sodas[2].Remaining - 1;
                totalSales = totalSales + Sodas[2].Cost;
                UpdateTotalSales();
                UpdateRemaining();
            }
            else
            {
                MessageBox.Show("I'm Sorry, But That Drink Is Out Of Stock");
            }
        }

        private void pbGrapeSoda_Click(object sender, EventArgs e)
        {
            if (Sodas[3].Remaining > 0)
            {
                Sodas[3].Remaining = Sodas[3].Remaining - 1;
                totalSales = totalSales + Sodas[3].Cost;
                UpdateTotalSales();
                UpdateRemaining();
            }
            else
            {
                MessageBox.Show("I'm Sorry, But That Drink Is Out Of Stock");
            }
        }

        private void pbCreamSoda_Click(object sender, EventArgs e)
        {
            if (Sodas[4].Remaining > 0)
            {
                Sodas[4].Remaining = Sodas[4].Remaining - 1;
                totalSales = totalSales + Sodas[4].Cost;
                UpdateTotalSales();
                UpdateRemaining();
            }
            else
            {
                MessageBox.Show("I'm Sorry, But That Drink Is Out Of Stock");
            }
        }
    }
}