Delegation: as interesting as merchants selling apparel in ‘tianguis’

--Originally published at richardctc201

Delegation: as interesting as merchants selling apparel in ‘tianguis’

In preparation for the exam, here is my blog post about mastery topic: delegation. This term may seem as a tough to understand one, but actually is a concept that we as humans practice everyday in almost every situation we have.

I searched in a bunch of web pages trying to understand the concept of delegation; I searched in Wikipedia, in some Community web pages, and plenty of other web pages, and I finally, I got to a final definition that I like a lot: delegation is to ask someone else to help you. In this case (in an POO environment) the definition its transformed to ‘an object that when receives a request, it passes this request to a second object that is more specialized in this task’. As I said it before, humans tend to do this a lot in their daily lives. When someone receives a bunch of tasks, the first thing he/she does is ask for help; he/she delegates part of their tasks to someone else so that the amount of work can be less stressful or less complicated.

I found a number of good examples in code that explain how delegation is performed in code. Something important to mention is that when an object delegates its request to another object, the first object passes its request as well as itself as a parameter to the other object, so the later can complete the task.

The clearer example was published by Mladen Prajdic (cool name!) in a community web page called ‘Stackoverflow’. It’s important to notice the way that a delegation process is declared, and how it is transferred to the object #2 so that this obj#2 inherit the necessary methods to complete the requested task.

delegate void delMyDelegate(object o);
private void MethodToExecute1(object o)
{
    // do something with object
}
private void MethodToExecute2(object o)
{
    // do something else with object
}
private void DoSomethingToList(delMyDelegate methodToRun)
{
    foreach(object o in myList)
        methodToRun.Invoke(o);
}
public void ApplyMethodsToList()
{
    DoSomethingToList(MethodToExecute1);
    DoSomethingToList(MethodToExecute2);

Its important to see how the declaration of a delegation is made,

Delegation: as interesting as merchants selling apparel in ‘tianguis’

Delegation: as interesting as merchants selling apparel in ‘tianguis’

--Originally published at richardctc201

Delegation: as interesting as merchants selling apparel in ‘tianguis’

In preparation for the exam, here is my blog post about mastery topic: delegation. This term may seem as a tough to understand one, but actually is a concept that we as humans practice everyday in almost every situation we have.

I searched in a bunch of web pages trying to understand the concept of delegation; I searched in Wikipedia, in some Community web pages, and plenty of other web pages, and I finally, I got to a final definition that I like a lot: delegation is to ask someone else to help you. In this case (in an POO environment) the definition its transformed to ‘an object that when receives a request, it passes this request to a second object that is more specialized in this task’. As I said it before, humans tend to do this a lot in their daily lives. When someone receives a bunch of tasks, the first thing he/she does is ask for help; he/she delegates part of their tasks to someone else so that the amount of work can be less stressful or less complicated.

I found a number of good examples in code that explain how delegation is performed in code. Something important to mention is that when an object delegates its request to another object, the first object passes its request as well as itself as a parameter to the other object, so the later can complete the task.

The clearer example was published by Mladen Prajdic (cool name!) in a community web page called ‘Stackoverflow’. It’s important to notice the way that a delegation process is declared, and how it is transferred to the object #2 so that this obj#2 inherit the necessary methods to complete the requested task.

delegate void delMyDelegate(object o);
private void MethodToExecute1(object o)
{
    // do something with object
}
private void MethodToExecute2(object o)
{
    // do something else with object
}
private void DoSomethingToList(delMyDelegate methodToRun)
{
    foreach(object o in myList)
        methodToRun.Invoke(o);
}
public void ApplyMethodsToList()
{
    DoSomethingToList(MethodToExecute1);
    DoSomethingToList(MethodToExecute2);

Its important to see how the declaration of a delegation is made,

Delegation: as interesting as merchants selling apparel in ‘tianguis’

UseCases: Answers to the project questions

--Originally published at richardctc201

UseCases: Answers to the project questions

In the activity of the description of the Use Cases of our project, my team and I concluded in four use cases: Installation, Turn on Rasplapse (the fancy name of our app ? ), User let Rasplapse create a Timelapse, and Name and save the video with Rasplapse. In all the cases the actor is the user of the app.

The first is pretty obvious: the user would need to download the Pi4J library, and downlaod the Rasplapse software. The second one enables the user to connect his/her Raspberry Pi to a power source (to turn it on, of course) and then click on the Rasplapse symbol in the desktop to open the program.

The other couple of use cases are more complicated that the last two, since they describe the behavior of the app and its functionality. The third one is the use case where the user name and select the directory where the video is going to be saved.

Finally there’s the action of letting Rasplapse to create a Timelapse: the user is asked for a duration and a photo-rate for the app to take the pictures in that range. After that, the camera takes a few seconds, and then starts to take photos in the photo-rate and duration specified. After this time range is finished, the user can find the video in the directory selected previously.

Our project is in the right path since we’ve bought the engines that are going to move the camera, and we are in the process of testing the code.

 


UseCases: Answers to the project questions

The silliest project ever (and for silly I mean tremendously difficult!)

--Originally published at richardctc201

This week I finally finished #wsq09 “Movies”. I worked in this task for over two weeks; I spent nights in front of my laptop; I couldn’t slept because this task tormented me, but at last I beat one of the most difficult tasks of my life! Here is the description of my experience doing this incredibly, extremely, tremendously, awfully difficult wsq09.

The instructions for this task were: create a program that read a file, outside the program of course, with the names of some actors and movies where they have appeared. You should record this information wherever you want, and ask the user for an input: if the user write two movies separated by either “|”, “&” or “^”, the program should output the actors of the movies the user wrote with their respective restriction. “|” stands for all the actors that appeared in each movie (logic gate OR); “&” stands for all the actors that appeared in both movies (logic gate AND); and “^” stands for all the actors that appeared in one of the movies, but not both (logic gate XOR). Finally there was another option: the user could write the name of an actor and the program should find all the actors with whom he/she has acted in any movie.

The chosen tool or what I called it, the ‘designed hitter’ tool I used was a HashMap. This tool works as a Python’s dictorionary, where you have a key and a set of values of that key. There was only one important problem with the HashMap, the program couldn’t have access to the HashMap once running, in other words, I couldn’t read the HashMap line by line just like an ArrayList or any other similar tool. Once the HashMap was created by reading the file, an ArrayList of every key with their respective values was created too. Now with the movies and their respective actors arranged, an inputBox was shown so the user could wrote whichever option he/she wants and the output would be the actors with the selected restriction.

Another important aspect of my code is the use of an Iterator for displaying the actors in the option ‘b’ where the user simply write the name of an actor, and the program should return all the actors whom he/she has appeared with. The Iterator is an object that works when calling the method ‘iterator ()’. This object enables you to cycle through a collection of data, helping to obtain or remove elements. I used the Iterator to search for the name of the actor, and collect all other actors that appeared in the same list.

Here I leave the link to my Github repository where my classmates can see my code.

Hope that I help someone because this task is tremendously hard!

https://github.com/RichardCT/Movies/tree/master/Movies/src

The silliest project ever (and for silly I mean tremendously difficult!)


The silliest project ever (and for silly I mean tremendously difficult!)

Gunning down 195 numbers

--Originally published at richardctc201

Finally I got to the final task of the first partial: the 196 activity. This activity consisted in creating a program to find possible Lychrel numbers in a specific range of data. Lychrel numbers are natural numbers that do not form palindromes after adding their inverse several times.

As usual, I asked for help to my new best friend Alex, and here is what he did: obviously (like in every previous programs) I created two classes, the main class and an additional class called ‘Range’. In my main class, I used a new thing (well, new for me) called JOptionPane to collect inputs given by the user. I had two of this so that the user could enter the lower and the upper limits of the range of numbers. In Range, I defined 5 variables: low, high, natural=0, non=0, and yes=0. I also created two methods: the first one called ‘rango’ (I’m Mexican so don’t nag me) that has two parameters a and b where a is defined as the lower bound, and b as the upper bound; the second one was the method where all the math calculations were made, this one was called ‘types’.

In main, I created one new object, and called method rango for it, passing the two inputs provided by the user as parameters.  In types, I defines two variables (both strings): palin, and palinInverse, both variables were empty. I also defines 4 varibales as long: p1, p2, suma, and n. Finally I created a For loop with the condition that x=lower bound, and it iterate until x=upperbound. In the for loop, I made three conditions: one if that add one to my variable ‘natural’ if the number was a natural palindrome; another for loop to iterate thirty times to find Lychrel candidates, if there were palindromes in the way, it add one to ‘non’, and if not, it print an “Alert message” and add one to ‘yes’ meaning that it had found a Lychrel candidate.

I had a little problem with this code because first I defined my variables as float, but after just 10 iterations the numbers were incredibly huge, and the float variables couldn’t support it. So I had to change my variables to long, and then the program could successfully run.

Here I leave screens of my program in Github:

Gunning down 195 numbers

Gunning down 195 numbers


Gunning down 195 numbers

Babylonian Territory

--Originally published at richardctc201

Down in Babylonian Territory, I successfully implemented the Babylonian Method to find the square root of a number. Again, I received help from Alex ( the same guy I talked about in my most recent post).

The structure of this program is very similar from the GCD because this one also has two classes: the main class and a ‘Number’ class. In the number class, again, there are two methods: one called ‘setValue’, that assign a value to the objects created in the main class; and another called ‘squareRoot’, in this one there are performed the mathematical calculations. In the main class, there are created two objetcs: val1 and val2. Then it is called the method squareRoot for val1, passing as parameter val2. In this method, there are four variables declared: a, b, div, and ave. Variable a is assigned the value of val1, and b is the parameter. Then there is a for iteration to perform the process of the Babylonian method three times. The variable div gets the value of a/b, and ave gets the value of the average of b and div. Finally b gets the value of ave to perform the next iteration.

I tried the code assigning a the value 7, and b the value 4, and the output I get was 2.6457672, a very accurate square root of number 7.

The reasoning for doing this code was based in this link.

Here I also leave the link and screens of my GitHub account where you can see my code. Greetings from the Babylonian Territory!

Babylonian Territory

Babylonian Territory


Babylonian Territory

GDC reflective post

--Originally published at richardctc201

Here is the very first coding activity of this semester (except for the HelloWorld activity), and is a program that outputs the greatest common divisor of two given numbers. The challenge of this assignment was to create the most objected-oriented code as possible. So that instead of doing a simple iterative solution, one number (defined as an object) would receive a message to give the greatest common divisor of it and another number passed as parameter.

In order to accomplish the task, I asked for help to a friend of my mom (she works at IBM and knows plenty of coding nerds). Her friend is teacher in ITESO, and he assigned me one of his best students to help with Java, his name is Alex Ramirez. I met Alex one Saturday morning, and he taught me a lot of basic stuff of Java.

The way we addressed this problem was basing our thoughts in Euclid’s algorithm. I created a main class, and another public class call ‘Number’. In Number, I created two different methods: the first was a void type named ‘setValue’, to assign a value to both of my objects; and another void type called ‘max’, this was the important method where all of the math operations were going to be made. In my main class, I created two objects, val1 and val2, and by using setValue, I assigned a quantity value to both objects (in this case 1160 and 2013 respectively). With my two objects, I called the method max in val1 passing as parameter val2. In max, I declared 3 variables: a (val1), b (parameter), c (remainder of a/b)… And thathaa… When running the code, the output was 29, and I had a big smile drawn in my face.

Later in class, my teammate Dustin (alias Finn) helped me with the synchronization of Eclipse and GitHub showing me an excellent video that clearly explain the steps to follow to achieve the synchro.  As you can see, I’m very good at getting help of others!

Here a I leave some screens of my code in GitHub:

GDC reflective post

GDC reflective post


GDC reflective post

Project……

--Originally published at richardctc201

Last week my team and I (Luis, David, and Dustin) defined what our final project will be. We found a project on the internet about a platform controlled by a Raspberry Pi that is mobilized by some motors with the objective of carrying a camera device which takes photos in defined periods of time.

This project may sound difficult, but the truth is that we have everything we need to completed. David owns a Raspberry Pi, the components are not expensive, and the library that we need is already included in Java’s library.

Here I leave some web pages that show a similar project, and some advice that are needed to perform this project in the Raspberry Pi.

Project……


Project……

Flipped Learning

--Originally published at richardctc201

Flipped learning is an innovative, revolutionary way of ‘teaching’ that is having its bum in universities all around the world. For the wsq04, I read Afraj Gill´s blog post about the way that A´s grades spoiled his learning process. Afraj blames the educational system based in obtaining the highest possible grade at all price for mispricing the real goal of education: implementing the acquired knowledge in real life. Afraj says that although he always obtained the highest grades, and he was priced with a lot of scholarships and rewards, he realized that he had never used his knowledge in real life situations. He thinks that grades are the biggest obstacles for trully learning because students memorize big quantities of information in their short-term memory, causing that all those concepts are not ‘fully digested’ by the brain, and finally forgotten.

I agree with Afraj´s point of view. I’m used to obtain the highest grades, but I have always thought that someone´s intelligence isn’t based in answering a sheet of paper nor ‘macheteando’ (colloquial way in Mexico to describe the action of memorizing a big quantity of data) every single word that the teacher says in a class. I reflected about the part where Afraj talks about Finnish educational system (the best in the world) where people don’t attend school until 7 years old, and don’t present tests until their teenagers. In my point of view, Mexico needs to change something in its educational strategy (because it sucks!).

I searched for additional information about this topic and found an article of the University of Queensland, Australia that describes a little more how Flipped classrooms works, but the really interesting part of this article is that in the end, there are shown some benefits of the flipped learning style. I specially liked two of them: curate content, students gathering their own sources, and providing opportunities for discourse, the fact that an independent learning brings a bunch of different points of views of the students resulting in an enriching dialogue because they not only talk about what the professor said but also their own ideas.

Here I leave the link to that Queensland article; it is very interesting, and I expect that it gives more information of this revolutionary topic to my classmates:

http://www.uq.edu.au/teach/flipped-classroom/what-is-fc.html

 

 


Flipped Learning

OO Basics

--Originally published at richardctc201

Today we finally finished seeing the video of Object Oriented Basics. Due to the amount of work I had to do, and the fact that my attention wasn’t the best in class, I had to take a second look to my video at my house.

I think that there were two crucial things that the video pointed out: static/dynamic objects or programming and the terms that I had already discuss in past posts such as inheritance and encapsulation.

Beginning with static and dynamic programming, the video said that there are static programming languages such as java, c++ and c#; in the other hand there are dynamic languages like javascript, python, and ruby. The difference between this two terms resides in whether the code need to be compiled before running. If the platform has a compiler then we’re talking about a static programming type because the program needs to be checked for correctness. In languages like Python, there is no compiler because it is a interpreted language, or in our terms, a dynamic language type because the code is not checked before running and if there’s a mistake the output would show it.

The other important stuff is the inheritance between classes, and I specially liked this video because it uses excellent examples that clearly shows how objects relate and can inherit methods and fields.

With this video, the topic of Object Oriented Programming seems to be clearer, so I think it’s a good moment to go and have some fun giving a try to the wsq’s that involves coding!

OO Basics
Google Image photo by Brian Will https://i.ytimg.com/vi/ibXsrHGhBAU/maxresdefault.jpg shared under reutilization license.

 

OO Basics

 

 


OO Basics