Tuesday, May 14, 2013

Final Blog Post

I took AP Computer Science without any prior knowledge of programming or learning Java at all. That being said, this class was supposed to be more challenging than all of my other courses, and at times, it definitely was. What I favored the most about this class was its leisureliness in terms of deadlines and labs throughout the year. The first weeks were the most uncomfortable for me as I did not understand the purpose of the code and the syntax that went along with it. Interestingly enough, I found myself understanding more three weeks into the first semester. Once I got past the first roadblock, I was able to accumulate knowledge easier. I think learning about strings was the turning point for me because I had to use Codingbat.com to essentially learn by myself. I sometimes spent hours on those assignments, but I became much more familiar with boolean, while, and for loops as a result. 
After that, learning about other concepts became that much easier as we learned about 2D arrays, references and parameters, etc. The thing that I found most helpful in the learning process was to not leave anything out. What happened during the second semester was that several questions/misunderstandings that were left unanswered came back to bite me, and at that point, it was almost too late to patch up any holes that had emerged from first semester. If I could go back to relearn everything, I would be less lenient with my learning of every concept, because everything in the course is cumulative and important to future topics. 
As a result of these circumstances, the labs and assignments seemed all the more confusing to me during the second semester. I certainly could not catch up at this point because second semester was not as simple as first semester was. The tests and quizzes became progressively harder, but I ultimately did my best. The problem that I felt as we worked on labs in class was that I needed help a lot during these times, but so did other students on the other side of the room. I ended up not getting enough help and had to work on these assignments at home. 
Another thing that disrupted my ability to bounce back was my lack of retention of information. To me, it seemed as though everyone else could understand certain topics such as sorting, which is one of the subjects I struggled with the most. Eventually I was able to understand the different types of sorting, but unfortunately it took me much longer to understand it and therefore, I fell behind. I reasoned with myself that learning Java wasn't exactly my forte, but I still tried my best. I'm honestly not regretting anything from this course because it definitely satisfied my curiosity of what computer science actually was. It was a challenge, but I enjoy challenges as long as they aren't too taxing. In the end, although I am not the best coder, I still have an interest in this field and will definitely take CS-related courses in college. 
Overall, I think that this class was a good introduction to what Java is. I don't think my grades nor my understanding represent my capabilities or how hard I tried very well, but I learned much more than I thought I would about the basics such as how to use arrays, array lists, inheritance, composition, etc. The class in itself was a lot of fun, especially since my peers and I could bond over how stressful and confusing the labs were. I am certainly interested in learning about Python in the future because it has a much simpler syntax than Java does. Either way, I’m glad that I had to work to understand everything in this class because it gave me a perspective on what college courses might be like. While senior year might have not been the best time to take Computer Science since there were a lot of other responsibilities and jobs to be accomplished, I do think that my mind expanded a lot during this course. I hope that I can continue learning more  about what computer science can do in college and possibly in future occupations. I would definitely recommend this to anyone who doesn’t know or has never experienced programming because it has impressed me more than I thought it would.



Friday, May 10, 2013

Python Notes

Strings can be enclosed in either single or double quotes:

type("17")
<type 'str'>

Assignment operator:

17 = n

Printing:

print message
>>What's up, Doc?
print n
>>17
print pi
>>3.14159

Types:

type(message)
<type 'str'>

** is exponentiation

def NAME(LIST OF PARAMETERS):
STATEMENTS

a print statement with no arguments prints a new line

or type: new_line()
or type: three_lines() if you want 3 lines instead of 1

True and False, not true and false

3 logical operators: and, or, and not

int() and float()

Sunday, March 24, 2013

Blog Post for 4/7

Recursion is the method where the solution of a problem depends on the solutions to smaller instances of the problem. Although I don't relate coding to food much, I recently watched an episode of Masterchef where the contestants were required to produce a lemon meringue pie from scratch, and it strangely reminded me of the recursive method. In order to get the whole pie to work, the contestants needed to make sure that they had all three parts of the pie nailed, including the crust, the lemon curd, and the meringue on top. The two contestants who were required to make this pie did not impress the judges with their final product because their pies always had one or two components that were subpar. The first contestant's pie had a soggy crust because she didn't give it enough time in the oven, and while her lemon curd was very good because she had been "tasting it constantly" as she made it, her meringue was sparse and raw because she did not torch the egg whites enough before serving it. The overall presentation of her pie was criticized as well by the judges because it lacked the aesthetics. The second contestant's pie had a good crust, and one of the judges commented that the pie "held together well and had good structure." His pie also had a good lemon curd because he had been tasting his as well throughout the process. Unfortunately, his meringue turned out to be airy because the egg whites had separated throughout the cooking process, and therefore his meringue was not as crisp and creamy as it could have been. In the end, the second contestant won because 2/3 of his pie was well-executed, while the first contestant only had 1/3 of her pie that was well-executed. I thought of the recursive method because each part of the solution depends on smaller solutions of the problem, and each solution has a specific recipe to its success. The whole method will only work if each solution turns out to be well-executed like the three stages of a lemon meringue pie, and each stage has specific steps to acquiring the perfect taste and texture. Baking is as precise as using recursion in a code, and the idea of building up layers in a recursive statement can be compared directly to building up the layers of a pastry. The overall effect of recursion relies on the parts that create it just as the success of a pie can rely on the whipping of egg whites, the proper baking time in the oven, and the visual aspects of the pie.

Tuesday, March 19, 2013

Blog Post for 3/17 - Sorting in General

There are obviously many ways to sort things in Java, yet having said that, I don't really see how sorting applies to practical real-life scenarios. I do see a value in learning the basic code to improve our understanding of how logic/code works in the language, so don't get me wrong. There's nothing wrong with what we're doing by starting with the basics and working up from there. However, whenever I try to imagine using sorting in a real-life application, it would seem that game-creators or animators would use pre-written codes to write their programs and not bother with re-writing sort methods at all. After all, what's the point of writing a snippet of code that sorts integers when what you're ultimately trying to create a complex gaming system? I'm not bashing the idea of learning these methods because I'm sure there are more complicated ways of writing them, but I'm wondering how much they actually help in a normal job/career.
Now, when I think about the value of sorting things in more tangible way, sorting makes a little bit more sense. Sorting a card deck, for instance, could be a very useful invention, but it would definitely be difficult to create a device that could perform that task. If one were to sort an augmenting card deck (instead of shuffling cards, they would be doing the complete opposite), there would be both faster and slower methods of sorting the cards, similar to sorting in Java. I can certainly understand how sorting might apply to material objects.
Having said that, I'm probably too naive to understand the magnitude of how important sorting is, but it's something to think about. The problem I have with connecting coding with the real world is that it's too abstract, strict, and logical for me. For example, when I first saw the Bubble Sort method, I had to stare at it and break down every single for loop and > or < sign, and it actually took me a couple of minutes to actually understand it. Sometimes I wonder how other people can understand a huge chunk of code in 5 seconds. Anyway, I like to learn about different things when I am aware of the benefits/potential that they can bring to the real world. Just my two cents!
During Spring break, I caught up on reading, which is something I haven't done in a while. Usually, the only things I'm allowed to read during the school year are worksheets and assigned readings from English. I'll admit that I broke into The Woman Warrior (which is required for English), but I read it just to see how it was. I wanted to read Life of Pi before seeing the movie, but I didn't have any time. Speaking of movies, I saw Wreck-It-Ralph, which turned out to be a lot better than I thought it was going to be. It's one of the movies that is actually better than the trailer.
Luckily, I didn't have to worry about college notifications during Spring break (unlike Winter break). It definitely feels weird getting into my top choice (Vandy) while everyone else is waiting to hear back. Interestingly enough, I was accepted to SMU and Case Western over the break, so that was fun. My brother was waitlisted at 7 schools before he was accepted to Carnegie Mellon (which is #1 in CS, coincidentally!), so I can imagine how he felt about that. Regardless, I'm happy that my second semester senior year played out like this and am grateful for my teachers, friends, and family's support.

Monday, March 4, 2013

Sort Lab/compareTo


One mistake I made on my sort lab that took me forever to figure out was the < vs. > sign when comparing two different arrays. I think I had < before in the if statement below, but the compareTo method compares the first to the second.

If i1 = 5 and i2 = 6, the < sign would switch them, which is what we don't want to do in this case. We want an augmenting list, so we should only swap them if the first is bigger than the second. Therefore, we want the > sign in the if statement instead (just a technical error on my part).

The actual code went something like this. Also, the code was really, really slow, probably because String temp = myArray[j-1]; kept creating a new temp during each pass and that just made the process a whole lot longer. There were probably other things too that made it incredibly slow, but I optimized it by just creating String temp and then temp would just be reassigned in the case that the if statement was true.
In the end, it was actually interesting to see how much slower my code was compared to the Collections sort in java, but it was also kinda sad and funny at the same time. :)

private static void bubblesort(String[] myArray)
         {
            String temp;
            //before: not here^
            for(int i=0; i<myArray.length; i++)
            {
               for(int j=1; j<myArray.length; j++)
               {
                  if(myArray[j-1].compareTo(myArray[j])>0)
                  {
                     temp = myArray[j-1];
                     //before: String temp = myArray[j-1];
                     myArray[j-1] = myArray[j];
                     myArray[j] = temp;
                    
                  }
               }
            }
           
         }

Saturday, February 23, 2013

Blog post 2/17

Sort method:

A good way to sort a list of names is to use this method, which sorts things alphabetically. Here's a good example:

//Sort alphabetically and ascending:
var myarray=["Bob", "Bully", "Amy"]
myarray.sort() //Array now becomes ["Amy", "Bob", "Bully"]

However, if you wanted to sort in descending order, you would use array.reverse() instead:

//Sort alphabetically and descending:
var myarray=["Bob", "Bully", "Amy"]
myarray.sort()
myarray.reverse() //Array now becomes ["Bully", "Bob", "Amy"]


With numbers, sorting them numerically and ascending would go something like this: 

var myarray=[25, 8, 7, 41]
myarray.sort(function(a,b){return a - b}) //Array now becomes [7, 8, 25, 41]


Sorting them numerically and descending would go something like this:

var myarray=[25, 8, 7, 41]
myarray.sort(function(a,b){return b - a}) //Array now becomes [41, 25, 8, 71]


Say you wanted to sort the order of the items in an array randomly. Here's an example on how to do that:

var myarray=[25, 8, "George", "John"]
myarray.sort(function() {return 0.5 - Math.random()}) //Array elements now scrambled



Tuesday, February 19, 2013

Quiz Inheritance Corrections

Example 1:

Consider the following class definitions.
public class A{
private int a1;
public void methodA() {
methodB();          // Statement I
}
}
public class B extends A {
public void methodB() {
methodA();          // Statement II
a1 = 0;             // Statement III
}
}
Which of the labeled statements in the methods shown above will cause a compile-time error?


II and III
exact_answernone8514

III only
exact_answernone9197
I and II
exact_answernone8885
I and III
 
EXPLANATION:
I think a1 is declared as a private int in class A, so when class B extends A, it does not need to re-assign it to 0. I'm actually  not sure if this is the real reason, but that's what I'm going with for now. When it does this, it causes a compile-time error. methodB() will also cause this error because it is not defined.
 
exact_answernone6792
 Example 2:

true_false_question 26865425
A subclass of an abstract class must always implement every defined abstract method.
exact_answernone238
 
False

 EXPLANATION:
If the subclass is also an abstract class, it does not need to implement the abstract methods.