Practicing initializing objects

"Hi, Amigo! I already miss our lessons. Here are a few tasks to practice object initialization:"

4

Task

Java Syntax, level 5, lesson 7

Create a Friend class

Let's make up our own invisible friends, give them some qualities, and then go play with them, just like the other loners do! No? Okay, another time. We'll get through today by creating a friend template, i.e. a Friend class. And we'll make up three initializers for it: name, age and sex; only name and age; and only name.

8

Task

Java Syntax, level 5, lesson 7

Initializing cats

This task is dedicated to the mysterious and beautiful creatures we call cats. Create a Cat class and define five initializers (only name; name plus weight and age; only weight and color; name and age; weight, color, and address). We need valid cats: they can't exist without a weight and age. Alas, there are cats without names and homes.

2

Task

Java Syntax, level 5, lesson 7

Create a Dog class

The "Man's Best Friend" Bureau has decided to conduct a full census of Terra's dog population. To do this, they need an application that has a special Dog class. The only thing we can learn (or assign) about some dogs is a name. For other pooches, we also know the height. Finally, complete information about other dogs also includes color. This means that we need three initializers.

2

Task

Java Syntax, level 5, lesson 7

Create a Circle class

A circle is the most perfect shape in the world. At least that's what the roly polies on the 2D planet 2piR think. The roly polies needed a registration program to identify fellow roly polies in the plane. The challenge is that different data is known about various roly polies. Let's help them: create a Circle class with three initializers.

4

Task

Java Syntax, level 5, lesson 7

Let's put together a rectangle

OKEA sells unassembled space shuttles. They are all rectangular (we don't know why). These guys ordered a program from Company X for automatically generating shuttle instructions. You've been assigned to create a rectangle class and initializer methods for whatever life might throw at it.

2

Task

Java Syntax, level 5, lesson 7

A programmer creates a person

Let's create a new person... Actually, that would be better done elsewhere. In our case, we'll just create a template for a person. That is, a Person class. We'll give it fields (name and age). To create new Person objects quickly and confidently, we'll write an initialize(String name, int age) method, where we will initialize these fields.

2

Task

Java Syntax, level 5, lesson 7

Initializing objects

We'll initialize objects however we want! In this task, someone previously created the Person class, but their implementation doesn't quite suit us. Something needs to be fixed: we need to rewrite the program so that one and only one initialize method initializes all the Person class's instance variables.

So there cannot be 2 initialize methods in the class with the same vairable type (e.g. int) but for different fields ? e.g.
private void initialize (int top){
}
and
private void initialize (int left){
}

Exactly. The compiler doesn't know how to tell the two apart because they both pass the same type of value. However, the below code would still work because it matters what types of values are being passed, not what the actual values are.

I just learned this the hard way; I worked way harder than I needed to. I though there would be lots of intialize methods and I didn't want to type them all out. So I wrote a python script to generate what I though was all possible initializers. I didn't realize that java can't tell the different between the following: