You are on page 1of 2

OBJECT-ORIENTED PROGRAMMING

HOMEWORK#2
NAME:Osman Seçkin
SURNAME:KARABAŞ
ID:09253031

1.What’s the problem?


We have got a turtle.This turtle want to walk around the floor.We have some commands
for our turtle.Our turtle is smart.It has a pen in its hand.It can write “1” wherever it walk if the
pen is down.According to commands,The problem is to display the path that the turtle passed
2.How do you encode this program?
I used some variables.The turtle’s position,direction,pen’s position etc.My direction variable
holds 4 value for North,South,East,West.I declared a matrix that called Floor(20x20).After,I
declared a string array to hold the commands.I used a nested loops.İnner loop is do-while
loop.The other loop is while(infinite) loop. I used a lot of nested if-else statements.I checked
what the direction is and what the pen position is.After,I moved the turtle on floor.If the com-
mand is 1,pen position switches to up.If the command is 2 ,pen position switches to down.If
the command is 3,the turtle turns right.If the command is 4,the turtle turns left.If the command
İs 6,the program displays the path the turtle passed.If the command starts with 5,the turtle mo-
ves forward some spaces that comes after 5,. If the command is 9 ,the program will end.
3.What is the purpose of this program?
İt is to solve the problem.
4.What is the difficult part of this homework?
This homework is not difficult for me.
5.How do the program work?
The program reads the command array.According to commands,the turtle walks around on
floor.The program displays the path that the turtle passed.If the turtle was out of bounds,it
closes.
6.What does the methods that you used?
Turtle Class
Methods
public bool OutOfBounds
This method takes two integers as parameters.This method checks if the turtle was out of
bounds.
public void Path
This method takes an array as a parameter.This method displays the path that the turtle
passed.
public void Puzzle
This method takes an array and a string array as parameters.This method helps the turtle to
walk around.
public void Display
This method takes an array as a parameter.This method displays Floor matrix
Properties
public bool IsPenDown
This is a property for variable isPenDown.
public int Way
This is a property for variable way.
public int Space
This is a property for variable space.
public int I
This is a property for variable i.
public int J
This is a property for variable j.
7.Any Bug?Any Limit?
There is a bug.The bug is if a element of command array contains something except number,
The program will crash. I solved this bug but my solution isn’t the best algorithm.

You might also like