Unit 1 Activity 1
open NetBeans IDE and start applying the following activity
Part 1
You are required to develop a programmer-defined class that models the Robot object. Develop a class Robot to the following specifications. No error checking is required in the constructor or methods. You may assume that they will only be invoked using sensible values.
1. The class has two private instance variables, x and y; both are of the type int.
2. The class has a no-argument constructor that sets the values of x and y to 1.
3. The class has two-argument constructor that sets the values of x and y, to given values xPos, yPos.
4. The class has the public getter methods getX() & getY() for each of the instance variables, the getter methods return the current value of x and y.
5. The class has the public setter methods setX() & setY() that set the value of x and y with the new values xPos, yPos
The class has the following public methods
a- moveNorth() that increases the value of y by 1
b- moveSouth() that decreases the value of y by 1
c- moveEast() that increases the value of x by 1
d- moveWest() that decreases the value of x by 1
e- moveTo() which changes the position of x and y by given values xPos and yPos
f- The public method toString() that returns a string representation of the record, giving the x, y as follows:
Robot1, x= 5, y= 2
Part 2
Write a class TestRobot_yourName to test the above class. It should contain the following specifications:
1. Create an object of the type Robot, robot1, which is initialized to the following values: x=5 , y=2 , using two-argument constructor.
2. Create an object of the type Robot, robot2, using no-argument constructor then initialize its properties using appropriate setter methods as the following values: x=3, y=10
3. Increase the value of x of robot1 tree times
4. Decrease the value of y of robot1 2 times
5. Invoke the method toString() on both robot 1 and robot 2 to display their values using Standard Output.
6. Provide a screen shoot for the output
Part 3
You are required to develop a programmer-defined class that models the MagicRobot object which is a special kind of Robot class. It inherits all Robot class features. Develop a class MagicRobot to the following specifications. No error checking is required in the constructor or methods. You may assume that they will only be invoked using sensible values.
1. The class has one private instance Boolean variable visible.
2. The class has the following methods
a- makeVisible () that alter the value of visible to true
b makeInisible () that alter the value of visible to false
c- isVisible () that returns the current state of variable visible
3. The class has a no-argument constructor that sets the value of visible to false using - makeInvisible() method
Part 4
Add the following part to class TestRobot_yourName to test the above class. It should contain the following specifications:
1. Create an object gandalf of the type MagicRobot,
2. Invoke the method toString() on gandalf to display its values using Standard Output.
3. Check the response of Gandalf to the following methods moveNorth(), moveSouth(), moveEast(), moveWest(), moveTo(), does it response, Explain Why?
4. Now apply this sentence robot1.makeInvisible(); does it work with you, Explain Why
5. Draw the UML diagram that shows the relation of the two classes Robot and MagicRobot
All best of luck,
Course coordinator
3. Check the response of Gandalf to the following methods moveNorth(), moveSouth(), moveEast(), moveWest(), moveTo(), does it response, Explain Why?
4. Now apply this sentence robot1.makeInvisible(); does it work with you, Explain Why?
5. Draw the UML diagram that shows the relation of the two classes Robot and MagicRobot
Sarah Mitchell wrote:I just finished my very first assignment in Java, and I was wondering if you guys could please take a look at my work and let me know if there are any observations ..
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Looks pretty good to me; 'fraid I haven't check your UML diagram tonight because it's late, but if it's up with the rest of your stuff, I'm sure it'll be fine (and if it's not, you'll be told - and that's how you learn).
Other observations: Don't forget that one of the major signs of a good programmer is how "readable" your code is.
1. (in the words of Einstein) make everything as simple as possible; but no simpler.
2. Stick to standard coding practises - most importantly: Classes and interfaces start with a capital letter; methods and fields names with lowercase.
3. Good documentation keeps your program from the garbage bin for longer.
HIH
Winston