Project advancements – Hangman done!

So our project as you already know will be an arcade machine simulator, with different games, a credit system and 2 players.

We’ve already finished the hangman game and we’re almost done with the other two.

We just need to implement the game logic into a graphic environment.

Here’s the code for the game.

If you have any questions about how we did it feel free to comment on this post.

Partial 2 masteries

What are inheritance and polymorphism? (Specification and implementation)
Inheritance is the process where one class acquires the properties (methods and fields) of another. The information is managed in hierarchical order.
The class which inherits the properties of other is known as subclass, and the class whose properties are inherited is known as superclass. It uses the “extends” keyword.

class Mammal{

}

class Cat extends Mammal{

}

Polymorphism is the ability of an object to take many forms, the most common use is when a parent class reference is used to refer to a child class object.
Any object that can pass more then one “is-a” relationship is considered polymorphic.

public interface Vegetarian{}
public class Animal{}
public class Deer extends Animal implements Vegetarian{}

By this logic, Deer is-a animal, vegetarian, deer and object.

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.

What are CRC cards and how do we use them?
CRC cards are usually created from index cards. Members of a brainstorming session will write up one CRC card for each relevant class/object of their design. The card is partitioned into three areas:

On top of the card, the class name
On the left, the responsibilities of the class
On the right, collaborators (other classes) with which this class interacts to fulfill its responsibilities

Using a small card keeps the complexity of the design at a minimum. It focuses designers on the essentials of the class and prevents them from getting into its details and implementation at a time when such detail is probably counter-productive. It also discourages giving the class too many responsibilities. Because the cards are portable, they can easily be laid out on a table and re-arranged while discussing a design.

What are overloading and overwriting? How do we implement those in Java?
Method Overloading is a feature that allows a class to have two or more methods having same name, if their argument lists are different. To overload, you have two or more methods with the same name, but different arguments.

The benefit of overwriting is: ability to define a behaviour that’s specific to the subclass type which means a subclass can implement a parent class method, but with different arguments. To overwrite, you re-write a method from the super class, with different arguments.

What do you feel are the benefits to object-oriented programming?
Code Reuse and Recycling: Objects created for Object Oriented Programs can easily be reused in other programs.

Encapsulation (part 1): Once an Object is created, knowledge of its implementation is not necessary for its use. In older programs, coders needed understand the details of a piece of code before using it (in this or another program).

Encapsulation (part 2): Objects have the ability to hide certain parts of themselves from programmers. This prevents programmers from tampering with values they shouldn’t. Additionally, the object controls how one interacts with it, preventing other kinds of errors. For example, a programmer (or another program) cannot set the width of a window to -400.

Design Benefits: Large programs are very difficult to write. Object Oriented Programs force designers to go through an extensive planning phase, which makes for better designs with less flaws. In addition, once a program reaches a certain size, Object Oriented Programs are actually easier to program than non-Object Oriented ones.

Why do you think your change to object-oriented programming is difficult or what makes it difficult for the standard student?
I think it’s difficult to start because it requires more planning than other ways to program. To create an object-oriented program you need to design it very well, and even though it gets easier as the program gets more complex, the beginning of the program is hard, and by consequence, the learning curve for object-oriented programming tends to be harder at the start.