"Hi, Amigo. Here are some tasks involving integer type conversion. Add cast operators where necessary:"
10
Task
New Java Syntax,
level 10,
lesson 4
Locked
Populate the Friend class
A friend (Friend class) must have three initializers (three initialize methods):
- Name
- Name, age
- Name, age, sex.
Note: name is a String, age is an int, and sex is a char.
10
Task
New Java Syntax,
level 10,
lesson 4
Locked
Populate the Dog class
A dog (Dog class) must have three initializers:
- Name
- Name, height
- Name, height, color.
10
Task
New Java Syntax,
level 10,
lesson 4
Locked
Let's put together a rectangle
The data for the rectangle (Rectangle class) will be top, left, width, and height.
Create as many initialize(...) methods as possible
Examples:
- 4 parameters are specified: left, top, width, height
- width/height is not specified (both are 0);
- height is not specified (it is equal to the width), w
10
Task
New Java Syntax,
level 10,
lesson 4
Locked
Initializing objects
A person (Person class) should have a String name and int age.
Add the initialize(String name, int age) method where you will initialize the variables name and age.
In the main method, create a Person object and store a reference to it in the variable person.
Call the initialize method with any valu
10
Task
New Java Syntax,
level 10,
lesson 4
Locked
Initializing cats
A cat (Cat class) must have five initializers:
- Name
- Name, weight, age
- Name, age (standard weight)
- Weight, color (unknown name, address and age, i.e. a homeless cat)
- Weight, color, address (someone else's pet).
The initializer's job is to make the object valid.
For example, if the weight i
10
Task
New Java Syntax,
level 10,
lesson 4
Locked
Populate the Circle class
The Circle class must have three initializers:
- centerX, centerY, radius
- centerX, centerY, radius, width
- centerX, centerY, radius, width, color.
10
Task
New Java Syntax,
level 10,
lesson 4
Locked
Initializing objects
Study the Person class carefully.
Correct the class so that only one initialize method initializes all of the Person class's instance variables.
GO TO FULL VERSION