Sunday, September 30, 2012

Book/BookRunner

This past week, we started a lab called Book/BookRunner, where we created different constructors and utilized different methods. We created a default constructor, an initialization constructor, modifier method, accessor method, toString() method, etc. Until about 75% of the way through the lab, it finally dawned upon me that the setbookName() method meant to set the name of the book to a new name. Oh, so the names of the methods actually do mean something! While I admit it was a rather slow epiphany, it made things easier as I started to work on BookRunner and as I utilized all the methods to do what I wanted. Also, I liked the fact that I could combine System.out.println() with an object and another method. For instance, I could say System.out.println(textbook.getbookName()); and it's interesting how it can do everything at once in the same line of code. Another thing that I found interesting was the fact that I could dictate which constructor I would use based on setting the parameters in BookRunner. For instance, if I wanted to call the initialization constructor, I just had to set two arguments in the parameters: a book name and a book ISBN number. Likewise, if I just left it as an empty set, I would call the default constructor. After doing these things, it helped me realize the purpose of creating those constructors in the first place. In the beginning, I had no idea what a constructor was or what it did, so I struggled a bit in understanding what was going on. The same applies to the methods, such as toString(), because I simply didn't know what it did. I like the whole idea of trial and error in a lab like this, but often it depends on the type of lab we're doing. Certain labs need more examples while others simply need to be tried and done.

Sunday, September 23, 2012

Turtle

The most exciting thing that we did in Comp Sci this week was the Turtle lab, where we had to make the given turtle do various things through programming. The whole process became significantly easier this week for some reason, and I think that I'm starting to get the hang of it. Assigning one turtle to a preexisting one was perhaps the most difficult to wrap my head around, but I looked back to the power-point presentation and eventually remembered that two references can point to the same thing. The act of doing the lab really helps because, if we missed something during the presentation, we can always look back to it and then apply the rules to our work.
Secondly, creating methods was really interesting to me because I could simply make a turtle draw a square without having to retype everything at once. It's almost like a shortcut, and I luckily didn't seem to have any problems with that. All in all, I never expected to be able to create something in Java other than text (although technically, I didn't actually program the Turtle files beforehand). I was surprised that I was able to do something of this magnitude within the first six weeks of school. I think as we move through other topics, I am able to fully grasp concepts that we have covered in the past. For instance, a few weeks back, I didn't fully understand the purpose of a method, but I understand it a little better now. The most important thing to do (for me) is to make sure that I know what I want to accomplish, the steps to accomplish the task, and what coding couples with those steps. Starting a program is always the hardest for me, but hopefully that will change as the course continues.

Sunday, September 16, 2012

Strings

Strings seem to be one of the most frightening concepts in CS (according to my peers), and I kind of agree and disagree. Over the weekend, as I attempted to finish all of the CodingBat exercises, strings proved to be nothing short of complicated and confusing. However, the one thing I love about CodingBat is that it tells you when you have an error and WHY. Furthermore, when you run your program, it shows you which tests work and which ones don't, allowing you to decipher what was wrong in the first place. After hours of banging my head against the wall, I finally decided to surf the web to find out exactly how strings work. Strings are sort of like those magnets that you can attach and rearrange into different forms. I read about substrings and string lengths and tried them out on CodingBat. Learning and then applying was kind of like a trial-and-error process, because I simply didn't know how to dissect a string and rearrange it. Luckily, as I tried and failed, I learned from my mistakes and I was able to get through each exercise, one at a time. The whole process, albeit more than a little frustrating, was a great learning experience for me. I learned that you're not always going to get everything the first time, and that it's always good to go the extra mile by taking an interest in the subjects that you're learning as opposed to just memorizing little tidbits of information. While the concepts may be difficult to comprehend at first, once you let the knowledge sink in, the whole subject turns out to be quite fascinating. During class, I always find it a bit intimidating when my classmates know exactly what to do instantaneously, while I struggle just knowing where to START. A lot of people in CS seem to already have a background in programming Java, Python, etc. while I had no idea what I was getting into in the first place. Anyway, I'm super grateful that we are using CodingBat, because I believe that practice is key to succeeding in this class. I just have to keep working at it. Java may seem frustrating and tedious at first, but in the end, the reward is more than satisfactory.

Sunday, September 9, 2012

The first week of AP Computer Science was one of the most nerve-wracking and exciting classes of the week. Somehow, I pulled through. Because I don't have a background in CS, I was thoroughly confused with Java syntax. I was told that Java syntax is more confusing than most of the other CS languages out there, and I can see why. On Friday, we programmed 4 different programs in order to learn data types, variables, and input. Here are the steps to create such a program:

1) import java.util.Scanner; // This imports Scanner

2) public class ______ (topic... Ex: Age) // This is the class

3) {

4) public static void main(String args[]); // This is within the class

5) {

6) int _____; // This will be your first variable (Ex: years), put all variables at beginning

7) Scanner scan = new Scanner(System.in); // This creates a new Scanner object

8) System.out.println("_______?"); // Type something directing user to input a value

9) years = scan.nextInt(); // Scanner brings in an int value

10) years = years*2; // Type your function or calculation here

11) System.out.print("Your age doubled is "); // You will see this before the number that gets calculated

12) System.out.println(years); // This shows the calculated number

13) }

14) } 


Depending on what program you want to create, the calculations and variables will vary. This was complicated for me because we basically flipped through the slides very fast and I couldn't exactly comprehend or absorb any of the information. Until I actually did it, I didn't know where to start, and maybe if there was more clarification on what each line actually DOES, I would catch on quicker. Java syntax is so confusing to me, so it will probably be helpful for the present and future if the function of each line was explained in more detail. Otherwise, programming is really fun once you actually get it to work. CS turned out to be more fun than I anticipated.