WSQ06 – Greatest Common Divisor

--Originally published at Alan TC201

In this assignment I was rquired to write a program that calculates the greatest common denominator of two positive integers using Euclid’s algorithm.

If you do not know what Euclid’s algorithm is, here’s a page that explains it. http://www.cut-the-knot.org/blue/Euclid.shtml
WSQ06 – Greatest Common Divisor

 

This is “officially” the second homework and I am still fresh with this of program in Java, this may be easy because I did the same WSQ in the last semester in python. The trick here should be to implement this with message calls, not a simple iterative solution. This must be more oriented programing and nothing like “Python style”, now it is time for JAVA to shine:

WSQ06 – Greatest Common Divisor

This is my second language I am learning and the first object oriented, and I gotta say it is very different, python is very stylish and easy to understand the basics in less than 20 minutes. But Java is different…. very…. very different, just to do a hello world was very weird. This is a new experiences and I hope I can suprius it like in the last semester. The new thing I use in this WSQ was the “input” to give the machine the numbers to fiend the GCD. Video of how to do it. (https://www.youtube.com/watch?v=D3AYFeLjJmU)

WSQ06 – Greatest Common Divisor

And here is the github: https://github.com/alanoswalt/GCD/blob/master/redme.java


WSQ06 – Greatest Common Divisor

Masterie: UML Class Diagrams

--Originally published at Alan TC201

Class Diagrams are usful in diferent situations, for example.

Graphical way to illustrate relationships between classes in an object-oriented system.

Appearance varies between different drawing tools.

Round-trip tools are able to generate UML class diagrams from existing code, and generate template code from existing diaframs.

Masterie: UML Class Diagrams

“UML is popular for its diagrammatic notations. We all know that UML is for visualizing, specifying, constructing and documenting the components of software and non software systems. Here the Visualization is the most important part which needs to be understood and remembered by heart.

UML notations are the most important elements in modeling. Efficient and appropriate use of notations is very important for making a complete and meaningful model. The model is useless unless its purpose is depicted properly.

So learning notations should be emphasized from the very beginning. Different notations are available for things and relationships. And the UML diagrams are made using the notations of things and relationships. Extensibility is another important feature which makes UML more powerful and flexible.

The chapter describes the UML Basic Notations in more details. This is just an extension to the UML buildling block section I have discussed in previous chapter.” (http://www.tutorialspoint.com/uml/uml_basic_notations.htm)

Structural Things:
Graphical notations used in structural things are the most widely used in UML. These are considered as the nouns of UML models. Following are the list of structural things.

Classes
object
Interface
Collaboration
Use case
Active classes
Components
Nodes

Masterie: UML Class Diagrams

More info: http://www.tutorialspoint.com/uml/uml_basic_notations.htm

http://www.lynda.com/Java-tutorials/Diagramming-UML/375490/415273-4.html


Masterie: UML Class Diagrams

Masterie: CRD cards

--Originally published at Alan TC201

CRC cards are a way to se program object orientated.

Masterie: CRD cards

CRC cards are 4 by 6 index cards used in the design of object oriented
programs.  The initials CRC stand for “Class, Responsibility and Collaboration”.
Normally, a significant program written in an object oriented language like Java
is divided into several different classes.  These classes cooperatively work
together to accomplish the goals of the program.

Masterie: CRD cards
It can be difficult to understand how to divide a program into separate
classes, and how to divide a given class into separate methods. CRC cards help in this design process and organize in a very schematic way.

Masterie: CRD cards

This video explains everything in an easy way to understand.


Masterie: CRD cards

Masterie: What is delegation?

--Originally published at Alan TC201

Inheritance”
Other term that plays in Object-Oriented programming is inheritance”, this term tell us that we can “link” or transfer different methods between different classes that have similarities in them and use the same methods besides they use particularly methods. This helps to not duplicated methonds in diferent clases that have methods in commun.

If we couldn’t use Inheritance we will have to specify each method in each class we will have to explicit define each method in each class individually.
Multiple Inheritance means that a class have common things between two classes but those two classes don’t have Inheritance between them.

BUT BE CAREFUL, YOU DON’T CIRCULATE AN INHERITANCE, this means that a class cannot inheritance from itself, like a circle.

Overriding means that you could have different classes chain together and inheritance from the top one. For example, we have class, and we have a method call MON in the class V, normally all the classes below but if we have a method also call MON in the X class the the classes below X will inheritance the MON from the x class.

V – MON
W – MON FROM CLASS V
X – MON
Y – MON FORM CLASS X
Z – MON FROM CLASS X

Intarface is a set of methods that can have commun things inside different classes.

Masterie: What is delegation?

Inheritence uses the java compiler’s type system to implicitly include code from elsewhere, with delegation you explicitly implement the callout.

Inheritance is limited to a single parent class (and ancestors) but it can sometimes be non-obvious where your code is going; delegation is less elegant, but you can bring in functionality from multiple other classes and the flow is clearly visible.

As far as invoking external functions is concerned, delegation is generally preferred for just this reason, inheritance should be reserved for cases where you want to implement a class whose behaviour specifically is like the base-class, so it can essentially be treated as an instance of the baseclass by other code (ie. it is polymorphic).” (http://stackoverflow.com/questions/13245610/what-is-difference-between-inheritance-and-delegation-in-java)

 


Masterie: What is delegation?

Masterie: What is encapsulation?

--Originally published at Alan TC201

“Encapsulation”
Now after all this information we can dig more in terms of Java programing, first of all, the term “encapsulation”.
This means that, to have a better program, that is easy to read, to understand and fix the classes need to be private, so that the methods of a class only affect the data or the objects inside that class.

The encaptulation is used whent you have two packages with objects, clases and methods and you do not want that one package know the variables of the other package.

For example, here I have two diferent packages one that has the spesifications, the other one has the methods.

Masterie: What is encapsulation?

 

Masterie: What is encapsulation?

But when I change my methods to privite the encapsulated class could not recive inmormation from the Persona class.

Masterie: What is encapsulation?

Here is different info about encaptulation: http://www.lynda.com/Java-tutorials/Understanding-encapsulation/377484/421339-4.html

Masterie: What is encapsulation?


Masterie: What is encapsulation?

Masterie: What is abstraction?

--Originally published at Alan TC201

Abstraction in Java is like for example talking about animals, this is abstract because you do not know the context of that animal, it can be a cat, dog or a monkey, but you only know that it is animal.

Masterie: What is abstraction?

Abstraction has the same proces of hiding the implementation details from other people, only the functionality will be provided to the user. In other words user will have the information on what the object does instead of how it does it. Or in other words is telling the people the basic, hiding all the complex process that it requires.

In Java you can create an Abstraction using Abstract classes and Interfaces.

“Abstract Class

  • A class which contains the abstract keyword in its declaration is known as abstract class.
  • Abstract classes may or may not contain abstract methods ie., methods with out body ( public void get(); )
  • But, if a class have at least one abstract method, then the class must be declared abstract.
  • If a class is declared abstract it cannot be instantiated.
  • To use an abstract class you have to inherit it from another class, provide implementations to the abstract methods in it.
  • If you inherit an abstract class you have to provide implementations to all the abstract methods in it.” (http://www.tutorialspoint.com/java/java_abstraction.htm)

Masterie: What is abstraction?

Taking the example of the animals again, you can have a class name Animal and that class is going to be abstract, it has inside methods that all animals do, they eat and an abstract method that says that animals move.

Masterie: What is abstraction?

Then you have another class name Dog that extends from the animal class so the Dog class has in it the method eat, because all animals eat, but there is also an abstract method that the dog class need to verify, the move method, because not all animals move the same way, ones fly, otherones swim and dogs walk in four legs, so the method move this to be verify in the Dog class.

Masterie: What is abstraction?

Now that you have the dog class in is possible to create another class, that extends from the animal class, this new class is going to be a bird, birds can eat, but they move by air while using their wings.

Masterie: What is abstraction?

Finally the main class that controls the other classes and send them inputs to receive outputs.

Masterie: What is abstraction?

Links with more info:
https://docs.oracle.com/javase/tutorial/java/IandI/abstract.html
http://www.tutorialspoint.com/java/java_abstraction.htm
http://www.lynda.com/Java-tutorials/Using-abstract-classes-methods/377484/421352-4.html

 


Masterie: What is abstraction?

WSQ05 – Project

--Originally published at oscarlopez95blog

-This is a Work In Progress-

1st entry:

So, right now our team (Luis, Gio, Itzel and myself) are planning to make an arcade, it’ll have a main menu and at least 2 games to play. That’s the main idea and we have been talking about adding credits and how the user will earn them, but there’s nothing definitive yet.

If you’re interesed, the main menu is basically done, we just have to create each game and link them with the menu.

Here’s the menu in GitHub

I’ll update this post as we move forward with this project.


WSQ05 – Project

WSQ04 Flipped Learning / Abolish Grading

--Originally published at oscarlopez95blog

I just finished reading this post about abolishing grading.

It’s written by a guy who did really well in high school, but then he realized all his dreams about his education were based on getting good grades and not learning. It’s really interesting when you start thinking about it. Students actually care more about getting a good grade than learning something useful, we don’t see a new subject as “Will I ever need this in my career?” we see it as “This will be in the exam”.

It is said that students cheat because in our educational system grading is more important than learning, and it’s actually true. My dad is really strict when it comes to school,  so he always wants me to get the best grades possible, obviously as any person sometimes I fail to do so, and he gets mad. But he has never asked me “What did you learn in this class?”, instead, he asks me “What grade did you get?” and that’s it.

I think is BS that we focus so much in made up numbers that are supposed to be measures of our intelligence and dedication. We should appreciate the time each student dedicates to a subject. We shouldn’t tell students “You need to learn this, and in this way. If you don’t you’ll fail”. Everyone needs to realize you can’t test every person equally, we’re all different with different strengths and weaknesses. And our educational system doesn’t make use of it. They just ignore it.

If you support this idea, please tweet your thoughts and put #AbolishGrading.


WSQ04 Flipped Learning / Abolish Grading

Variables in Java

--Originally published at Alan TC201

This is not a masterie neither a WSQ,  I’m just writing this as an excersise for me to practice and know better the variables in Java.

“Field” and “variable” in In the Java programming language are very confusing because they are basicly the same most of the times, but it depends of the code to know wich term you are going to use.

Instance Variables (Non-Static Fields): Non-static fields are also known as instance variables because their values are unique to each instance of a class (https://docs.oracle.com/javase/tutorial/java/nutsandbolts/variables.html). For example, let’s use an example that my teacher used told me. You have 10 cats, each one has it own color, one is brown other one is black, a little one is red and so on, each cat has its particular value of color.

Class Variables (Static Fields):: A class variable is any field declared with the static modifier; this tells the compiler that there is exactly one copy of this variable in existence, regardless of how many times the class has been instantiated. (https://docs.oracle.com/javase/tutorial/java/nutsandbolts/variables.html). With the same example of cats, but with Class Variables, you will have one behavior, like eat(), and does not matter what color the cat is, it will always eat, so this variable affect all the objects inside the class cat.

Variables in Java

To name a variable there is no specific rule, but it is best to program in a orginice way so that not only you can read it, but other human beings can. So it is better to name a variable correctly.

NOT CORRECT   int c = 10;

CORRECT int cat = 10;

Other rule is that you can not use the list of words that command somthing in Java to name your variable, because the program will get confuse. This is the list of words.(https://docs.oracle.com/javase/tutorial/java/nutsandbolts/_keywords.html)

“The Java programming language is statically-typed, which means that all variables must first be declared before they can be used. This involves stating the variable’s type and name.” (https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html)

int gear = 1;

Doing so tells your program that a field named “gear” exists, holds numerical data, and has an initial value of “1”. A variable’s data type determines the values it may contain, plus the operations that may be performed on it.

But int is not the only command, there is more that holds different cuantitie of bits.

Data Type Default Value (for fields)
byte 0
short 0
int 0
long 0L
float 0.0f
double 0.0d
char ‘u0000’
String (or any object) null
boolean false

(https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html)

Variables in Java

 

 


Variables in Java