Geeky Babble

It's about all things electronic or digital.

Xcode and Objective-C

My self-paced java courses have been going so well that I thought I would take on another programming language simultanesouly. I signed up first for the Mac iOS 5 Developer program and downloaded the Xcode version 4.2.

Next, I purchased another “…for Dummies” book, this one is titled “Objective-C for Dummies.” The first chapter of the book describes how to start a new project.

Since the book was referencing so many programs built from the Mac OS SDK, I immediately signed up (paid $99) to become a member of the Mac OS SDK as well. I’m not sure that I have the correct access to this area of the Mac Develop Member Center to download the actual SDK software needed for the Mac OS X portion and not just iOS.

As I read through the first chapters of the book and create a new project, the book references different files I should see in the project. The book references a .m file and a .pch file. I don’ t see either of these files when I start a new project. The file I do see is a main.c file and it contains most of the code that my “…for Dummies” book references.

The lesson continues to explain the header files contained in the .m file. I see header files in my main.c, but not the header file they are referencing <Foundation/Foundation.h> The remaining code that is discussed in the project is all found in the file main.c in the new project I created.

I continued following the lesson and I was able to modify the code that was in the main.c file as opposed to what the book discussed removing / adding to the .m file.

The book references the NSLog command that is used by first calling upon the line:

#import <Foundation/Foundation.h>

The main.c file that is created instead calls upon the header file:

#include <stdio.h>

Therefore, it uses the printf(“”) command.

So, I’ve made the program work the way it was supposed to, but I’m getting nervous. The “…for Dummies” book I am using references an older version of Xcode and an older version of the Mac OS SDK. I can’t tell if I have the actual Mac OS X SDK info loaded into Xcode yet, and I’m hoping I’m not going to have to constantly translate and figure out how to make these programs work with different header files.

Anyone else out there having Xcode template file confusion?

It’s Only 21 – but in Java

I felt like a complete geek today, and I loved every minute of it. I’m already halfway through my book, “Beginning Programming with Java for Dummies.” I was actually nervous about reading through the book so quickly until I realized many of the programming basics that are taught in the book are concepts that I have already learned. I took C++ courses in college and a “Basic Programming I” course that I mastered in high school. I already have a grasp on things like:

  • variables
  • values
  • types
  • programming nests
  • while statements
  • switches
  • loops

Apparently, these concepts are universal to any programming language. Getting them to work for the language you writing in is just a matter of syntax. As I was reading the chapter regarding “while statements,” I started to type in the sample code that the author provids for a game he refers to as “21.” It wasn’t java code for a blackjack game – apparently the author thought that would be too difficult for beginners who are only halfway through his book.

When I started to read through the sample code, the game uses a “while” loop to continue drawing a ‘card’ (a random number from 1 to 10) until the total of the numbers equals or exceeds 21. I wondered to myself, “What’s the point of that?” I don’t even get to decide if I want to take another card (run through the while loop again) or not. I keep taking cards until I get exactly 21 or until I bust – and that was the moment.

That was the moment when I felt my geeky inspiration and initiative spark. I haven’t felt it in so long, I was beginning to wonder if I still had geeky sparks of inspiration and initiative. Hell, I may only be halfway through the book, but I’m going to at least make this a little more challenging for myself and see what I can do.

The “while loop” in the sample code simple tests to determine if the total of the cards drawn is equal to or greater than 21. I inserted code that the author has already discussed that would ASK the player if they would like to take another card or not. My “while” loop doesn’t depend on the total value of the cards drawn, but to the answer character the player gives when asked if they would like another card. As long as the player answers ‘y’ to the question the “while loop” continues. Any answer other than a ‘y’ or a ‘Y’ breaks the while loop.

I was even inspired to format my output to the screen into columns so that the display of my simple console-based java application would look somewhat professional. I was able to take the sample code from this lesson as well as bits of code from previous lessons to generate a program that more closely resembles “21″ or blackjack – and then it happened again.

I’ve added a phase two to my project. ‘m pretty certain I’ve learned enough to continue this project and use the sample code and a few “if/else” statements to simulate a dealer’s hand. I can use conditions similar to the rules of real blackjack where the dealer would continue to take cards as long as the total is less than 17. In phase three, I can compare the dealer’s total with the player’s total and declare a winner. Phase four, will neaten it up a bit and make it look as close to real blackjack as possible; a player will see the dealer’s “show” card and their own cards before determining if they want to hit or stay – just like real blackjack..

It sounds simple, and I’m sure for those of you who have been programming or scripting as a profession or as a constant hobby, it is relatively simple. I’ll get to where you are eventually. It’s all part of my master plan!

Here’s my code – I’m so proud. Yes, I know it’s simple, but it’s a start! And yes, I know that after reading that long entry about my project you’re probably expecting 100+ lines of code. Nope – just this:

import java.util.Random;

import java.util.Scanner;

public class blackjack {

public static void main(String[] args) {

Scanner myScanner = new Scanner(System.in);

Random myRandom = new Random();

int pcard, ptotal = 0;

char hitreply = ‘y’;

while (hitreply == ‘y’ || hitreply == ‘Y’) {

System.out.println(“Card\tTotal”);

pcard = myRandom.nextInt(10) + 1;

ptotal += pcard;

System.out.print(pcard);

System.out.print(“\t”);

System.out.print(ptotal);

System.out.println();

if (ptotal>21){

System.out.print(“You busted!”);

hitreply = ‘n’;

}else{

System.out.println();

System.out.print(“Would you like another card (y/n) “);

hitreply = myScanner.findWithinHorizon(“.”,0).charAt(0);

System.out.println();

}

}

}

}

A New Beginning – Java for Dummies

I know, I know – a for Dummies book? But each of the “For Dummies” books that I have rad have been really good at explaining the basics and helping you build a solid foundation to build upon. I’ve taken two C++ courses at ODU. I have a general understanding of the concepts related to programming. Yet I feel the need to start from the ground up and get a good working knowledge of what I’m getting myself into.

I think a career change is eminent. I enjoy system architect and working with different customers, but there comes a point where I”m simply regurgitating designs for systems that I’ve already installed for other customers. I need something more challenging – something that requires a little more thought and intuition as opposed to a few template installations. I

I”m starting with #Java and working my way back into C++ as that seems to be where most of the job openings that sound appealing. But programming general really gets me going.. I know that sounds geeky, but that’s just me. I have no problem sitting in front of a computer, coding for hours, Starbucks in hand and thinking I only 10 minutes have gone by only to realize it’s card out and all the take out restaurants no longer deliver.

I’ll keep you all posted on my #Java progress. So far, my programs are very imply calculators that print / input strings or characters from the screen into declared values. It really brings my back to my CC++ days. I ‘m anxious to sew that the actual hangs