Tuesday, May 5, 2015

PHP 2.2.3

Conclusion
1.       What are the advantages of adhering to the first two of the normal forms?

It makes Everything more organized and removed redundancy.



2.      Describe a way that a school might use a relational database.


 A school could use one to find all the students with a certain first name, or with a certaingrade in a class. This is becuase relational databases take advantages of repeated feilds.



3.      What additional functionality do you achieve by airing up PHP with MySQL as opposed to using MySQL from the command line?

PHP allows the relational database to be utilized and allows other types of databases to be presented.

PHP 2.2.2

Conclusion Questions:

 1.       In Activity 2.2.1 you used a version of this site that was constructed entirely from HTML, JavaScript, and CSS. What do you think are the most important improvements made by using PHP and MySQL?

PHP is an easier language to learn. Help and documentation is easy to find becuase it is so widely used. Any text editor can be used to write PHP and it is not OS specific. PHP powers about 30% 0f the web and there is no cost associated with it. PHP is fast and is object oriented with the ability to call objects from Java and Windows COM.


 2.      What language would you use if you wanted to access information on a server?

PHP

 3.      What language would you use to create a zoom feature for images on your website without putting any additional strain on the server?

Javascript


4.      What language would you use to put a pretty frame around a table on your website?

Cascading Syle Sheets, or CSS

5.      What purpose did the comments in 222indexB.php serve for you as you worked through this activity?

It made it easier to know where things go and what parts of code served certain purposes.

Monday, April 27, 2015

Arrays

Arrays have many uses, however their main function is to store values in a list of multiple values. They can be lists of Characters, Integers, Floats, Strings, or really any other variable type, even other arrays. You can add change, and reset values within an array. Each valuein the array can be accessed by using arrayName[numberOfValue]. the number of the value is the spot the value is assigned to. each array has spots that are 0 through whatever the size of the array is. the size of the array is declared when the array is declared. For example: int Array[] = new int[10]. the bolded number is the size of the array. assigning a value to a spot in an array goes something like this: Array[4] = 24. this issigns the value 24 to the 4th spot in the array. Arrays can be used to do many things, such as make a progam the deals a set of cards, or a programming test called FizzBuzz.
This is a program I created to generate a random hand of cards based on a full single deck of 52 cards. Joker not included. The Array of Strings that trails off the screen is an array of every posssible card. The numGen method generates a random number that is not the same as any number previously generated.

This is the frist window that will pop up. It is a list of numbers 1 through 52. You chose what number of cards you want dealt to you.

These are the cards you recieve. The first letter or number is the type of card. For example, 3 is a three, J is a jack, A is an Ace. The second letter is the suit, for example, H is hearts and S is spades.


This is Everything about FizzBuzz. The description is in the top left corner. The code is in the box below the description, and the Box with all the green boxes inside is the tests ran on the program and the green indicates they resulted in the outcome required.

Monday, March 9, 2015

Headfirst Java Chapter 6

In Chapter 6, the Java API is introduced. the Java API is a library of already written code for generic tasks. I had to pull the ArrayList class from the Java API. The ArrayList is an object that one can use methods on, which cannot be done with regular arrays. In fact, ArrayList objects are more powerful and flexible than regular arrays. the only case where a regular Array might be more useful is in a list of primitive values. Since ArrayLists are objects, the use regular Java language, unlike regular arrays that have specialized components. There is also a way to restrict the type of things that are allowed into the ArrayList. ArrayLists do not need an assigned size, things can be added to them and removed and the size will grown or shrink whenever needed. Regular Arrays do not do that. if one exceeds the size of the array, a runtime error pops up.

Within boolean expressions, I leanred new concpets that can be applied, like the 'and' and 'or' operators. within a boolean expression next to an if statement, while loop, etc. && can be used inbetween two statements to say "Hey if both of these are true, do this" or "while bnoth of these are true, do this". || works similarly, except EITHER statement can be true for the whole expression to be considered true. Also, x != 1 means x does not equal 1, and that little thing can be put wherever an expression needs to be true when something does not equal something else. But what about if the code requires the .equals() operator rather than an =? well then a ! gets plopped in front of the entire thing and it means not equal.

In order to use any class from the Java API, one can just use it as if it were their own class he or she made and compiled. The only exception is the FULL package must be imported to the package bein written. For example, to use an ArrayList, one can type "import Java.util.*". "import" is the import function, "Java" is the language, "util" is the package, and "*" is where the class goes, however using the * imports all classes within the package. any code that is imported that begins with "Javax" rather than "Java" originally began as an extension, but then began to  be included in the Java API. other than that, there is no difference.

Wednesday, March 4, 2015

Age Checker Program

I completed the Age Checker activity using Java. The requirement of the age checker is 18 years or older. 

I had to import the JOptionPanel class from the swing package and i imported all classes from the util package so i could get the Date class. All code was done within one class, the Age class, and in the main method.

First, I declared my 3 string variables, day month and year. these will turn into the users day month and year of birth.

Next came the option panels. 3 pop up. the first one asks for the day of birth in 2 digits. Then another pops up asking for the month, again in two digits. Lastly one pops up asking for the year, however, instead if the mandatory two digits like before, the year requires 4. The users input will be stored within the string variables day, month and year.

Now, strings will not work for what this code needs to do, so they need to be converted to integers. The day variable gets turned into d, and is now an integer. The same thing happens from month to m, and year to y.

The users birthday has been gathered, now the current date needs to be gathered to verify if the user is 18. to do this, I created a new GregorianCalendar object. this object can supply alot of information using the imported Date class. I declared a new integer variable cd (stands for current day). cd is equal to calendar.get(Calendar.DAY_OF_MONTH). This snags the day of the month and puts it  as an integer stored as cd. this is all done within the imported Date class. Similar code with minor, yet important differences is written for cm (current month), and cy (current year).

Finally the program has all the data it needs. Now it just needs to do a few things with it. there is an if statement with a condition creating a new Date object set up (year,month,day). the variables represent the user's birthday. the .before method asks if this date is before the following date, which is another new Date with variables representing the current date plugged in, except the year is subtracted by 18 becuase the required age is 18. In English, this is saying "Is this date before this other date?" but in java it is comparing the time in milliseconds between them both since January first, 1970. if the first one is less than the second, then the statement will be true. Now if the user is in fact over 18, then an option panel will pop up saying "Access Granted.". What if the user is not old enough? well a very similar line of code is written to solve this, however, instead of .before, .after is used. Also the month needs to have 1 added to it, otherwise The program would say you were not old enough if you turned 18 in the current month! but what about if you just turned 18 today? Well, that's what the final else is for. that else ensures that if you are exactly 18 on the current day, you can still get "Access Granted.". 

That is how I designed my Age Checker Program.

Thursday, February 26, 2015

Headfirst Java Chapter 5

This chapter was about bigger, stronger methods, and the beginnings of creating a game of battleship. This chapter focused on creating a simpler version than the 2D grid with three ships. Instead I made a one row board with one ship that will be expanded into the full game in Chapter 6.

One method to writing code is to first write prep-code, then test code, then the real code. The prep-code is just what you want to happen and not how to do it. then the test code is where you start to test certain parts of the code without implementing methods. then the real code id the full blown code where everything will work.

A few new things were explained in this chapter. The Integer.parseInt() method was explained. the "Integer" is a class that ships with Java. "parseInt()" converts whatever is in the parenthesis into an integer if, and only if, it is a digit. For example, a string "3"  would be changed into an integer 3. For loops were explained. They are formatted like so; for (variable : array). They mean for every variable in the array repeat. The post-increment operator, or ++ after a variable, was explained and it just adds 1 to whatever variable it is in front of. There is also a post-decrement operator which is a variable with -- after it. it subtracts 1 rather than adds 1. "Pre" versions of both exist and mean add or subtract 1 then use the new value of the variable, if they are in an expression of some kind. Break statements were explained. They just immediately end loops by saying "break". How to make a random number was explained. "int randomNum" declares an integer that is called randomNum. Then "= (int) (Math.random() * 5) follows it. The "(int)" forces the random number to be an integer. "Math" is a class that comes with Java, and "random()" is a method within that class. it generates a random number from zero to just less than 1 (so 0.999999...). The "* 5" increases the range of the random number from anywhere between 0 and just below 5 (or 4.9999999...). Since the variable must be an integer, any of those decimal nines will be cut off, leaving a number between 0 and 4. How to get user input was also explained. "String guess = helper.getUserInput("enter a number");" is how to do so. "String guess" declares the string variable guess. "helper" is an instance of a class made to help specifically with the battleship game. "getUserInput" is a method of the "helper" class that takes what the user has typed when the user pressed return, and gives it back as a string. "("enter a number")" is what is going to be displayed right before the method starts looking for user input. There is also another kind of for loop. "for(int i = 0; i < 100; i++) {}". "int i = 0" declares a new integer variable. "i < 100" is the boolean test. this specific for loop will run 100 times. "i++" adds 1 to "i" every time the loop is run. When the amount of times a loop is wanted to run, a for loop should be used rather than a while loop.
This is the be the JVM secion of the textbook. It was easy to complete because all that was needed was to run through the program and add variables. the writing on the page explains what I did to figure out the output.
I completed the simpledotcom game with the code shown below.
Game.class This is the main class.

GameHelper.class


Simpledotcom.class
This is the result when a game is played. The player won without missing.

Tuesday, February 10, 2015

Headfirst Java Chapter 4

As described in previous sections, a class is a blueprint for an object. All objects within a class will have the same methods, however, they may behave differently depending on instance variables. Arguments are passed on to methods as parameters.  Arguments are generated within a method, and sent somewhere. Parameters are arguments from one method that were sent to another method. values can be returned from methods using the return command. When a method is declared to return a value, the method must be declared using the same, or a compatible variable type as the returned value. methods can have multiple parameters, but they will be arranged in the order they were sent in as arguments, regardless of what the parameters are named.

Getters and setters, or accessors and mutators, set and retrieve data. For example, a setter method will set a variable, then the getter method is called to retrieve the value that was originally set. However we have a problem because all of our data thus far has been exposed, meaning any reference variable can change anything with a dot operator. This can be prevented by making all instance variables start with "private" and all getter and setter methods "public" so they can be accesses anywhere.

Even if Instance variables are not assigned values, they have a default value. integers is 0, floats are 0.0, booleans are false, and references are null. Instance variables are declared within a class but not within a methoid and local variables are declared within a method. Local variables, unlike Instance variables, need a value assigned to them before use. They do not have a default value. to see if any primitive variables are equal, one can use the == operator. The same goes to see if two reference variables refer to the same object. However the == operator cannot be used when seeing if two objects are the same. for that one must use the equals() method.

This is the "Be the Compiler" Section of Chapter 4. The annotations on the page explain what needs to be done. A will run as it stands, and it will output '42 84'. In B the getter "getTime()" needs to be declared with the same variable type that it is returning, which is a string. the output of the corrected code would be 'time: 1245".


Monday, February 2, 2015

First Program

Number Guesser:

I created a number guesser, in which, one must enter a number in an attempt to guess a random number of one through twenty five. If the guess is too high, the program will tell the player than their guess was too high, and it will say too low if the player guesses too low. The goal is to try and guess the number the program is thinking of in the least amount of guesses.
This is the code for the number guesser.

Sunday, January 25, 2015

Headfirst Java Chapter 3

Chapter 3 was all about variables and all the uses they have and how to utilize them to the fullest extent. There are two types of variables, primitive and reference. primitive variables are variables such as boolean, integer, or float variables that hold bits representing a value. Reference variables reference an object and use it in a method  by utilizing the dot operator.If a reference variable has no object to reference, it will return "null". I was able to complete the "dog" code.

This is the "dog" code, however there is an error. This can be seeen becuase of the "null" in the output. a reference variable is not referencing an object. I fixed it by moving "dog1.name = "Bart";" above "dog1.bark();" because when the method "dog1.bark();" was ran, there was no name associated with dog1 so then dog1 was supposed to bark, it returned "null says Ruff!" instead of "Bart says Ruff!"


Here is the corrected version of the code.
I was also able to complete the "Be the Compiler" section of this chapter pretty easily.



With A, "myBooks[0]","myBooks[1]", and "myBooks[2]" were not declared as the object "new Books();". threee lines of code, one fore each "myBooks" needed to be included to make the array of "myBooks" into objects. B was simple. Arrays begin at zero so z should equal -1 to begin rather than 0, and the while loops should continue until z is greater than or equal to 3. The 2 in the image should be a 3.

Sunday, January 18, 2015

Headfirst Java Chapter 2

Chapter two was all about objects and classes and how they relate and interact. I found this to be a very helpful refresher on how java works and used OOP (Object Oriented Programming). I am beginning to remember how to read and write java. Because classes are like a blueprint of how an object will function, it is not hard to make one class and several objects. This allows for adding more things to a program without changing previously edited code. Objects have their own variables and methods that are either global variables and methods, inherited variables and methods from its class, or local variables and methods. A super class can be created so many classes can inherit traits from the larger class. I was able to complete the "Be the Compiler" page in Chapter 2 with relative ease.

The errors were relatively easy to spot. In the "A" section, the "t" variable was never defined. It would appear that the programmer would have wanted to declare "t" as a "new TapeDeck". To do this, they would have had to type TapeDeck t = new TapeDeck();" in the "TapeDeckTestDrive" class.

The error in the "B" section was also simple. The "playDVD" function that was called in the "DVDPlayerTestDrive" class was not defined. In order to do this the programmer would need to type "void playDVD() { //some code to run }" in the "DVDPlayer" class. this way the code in the "DVDPlayerTestDrive" class would call the "playDVD" fuction of the "new DVDPlayer" as defined by "d" from the "DVDPlayer" class.

Friday, January 9, 2015

Headfirst Java, Chapter 1

Chaper 1 of this book was interesting, and its much better than the boring textbooks like in history or math. However, it was only chapter 1, and since I already have a small background in java, I did not really learn too much from this. I did get better at what I already know, however. I was able to troubleshoot the 99 bottles of beer program and successfully make it run. My corrected code is shown below.
99 Bottles of Beer Program.

The error was one line was saying "1 bottles of beer on the wall" and that improper grammar. I simply added an else if statement so that if there was 1 bottle left, it would print "bottle" instead of "bottles". Also, this chapter served as a refresher for me since it has been a year or two since i have done any coding in java, and since then I have learned python. Python syntax is like java in many ways but is less complex. I have found myself almost writing python syntax when writing the code above. I have high hopes for this book, not only as a refresher for what I already know, but also later, to teach me more of the language.