Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help with the assignment please, due at midnight tonight. Thank you. Figure 1: A diagram showing a bug in a 5y Stage1: In the

Need help with the assignment please, due at midnight tonight. Thank you. image text in transcribed
image text in transcribed
image text in transcribed
Figure 1: A diagram showing a bug in a 5y Stage1: In the first file Bug- java, create a class named Bug that models a bug that mowes in a 5 10 grid (Figure 1). Your Bag class should contain the following: Three private instance variables rou (or y.coordinate): The row value must be between I and S -column (x.coordinate): The column valae must be between 1 and 10 direction: The direction can be N,E.S or W(You may use 0, 1,2,3 to reprsent tbem) default coestructor that takes no inputs: A constractor takes three inputs (row, column and direction) Three accessor methols to return ench of three instance variables A mutator aethod to change the direction (public void turn(int d)) A mutatoe method to reset all instaace varialds (public void reset 0) 8 7 Stage 2: In the second file BugTester java, your need to test the methods you implement In particular, you need to do the followings: L. Create a Bug object, and initialize the object with your or 2. Print out the bug's initial position 3. Ask the user to euter the direction for the bag to tura, and the number of units for the bag to sove. These information shoukd be the inputs for the methods of turn and 4. Print out the bug's current position from the previous action 5. Ask the user to try it again Your outputs may look like the one as in Figare 2 Additional requirements of your program: 1. Your prograan should alw users to try as many tines as we they want. 0 . A method to move some number of units in one dire public void sove(int num) Important: You should not let the bug move out of the grid if the bug hits the boundary -If the current row value is 1, then the bug cannot move north further - If the current column value is 10, then the bug cannot move east further. - If the current row value is 5, then the bug cannot move south further - If the current column value is 1, then the bug cannot move west further .A method to display the current position and direction of the bug in the grid. public void printCurrentPositionO Hint: Basically you can print out a 5 x 10 matrix of dots () except for the bug's position. For the bug's position, you may print out a character of "N-ESW indicate its current direction to Prtscn Home End 5 7

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions