Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program a Robot in Java. Part One is the Robot program and part Two (GUI) will use Swing to make the Java App. Part One

Program a Robot in Java. Part One is the Robot program and part Two (GUI) will use Swing to make the Java App.

Part One Robot Class 35 Points

In this project you will create a robot class. The robot objects move within a grid similar to the 3x3 grid shown below to pick up and carry the letters on the grid to different locations.

image text in transcribed

The grid size should be declared as constants, use a 25X25 grid for our program.

The Robot class must have the following data members and methods:

  1. The Robot class has three private data members
    1. An integer type variable for the x component of the location of the robot on the grid
    2. An integer type variable for the y component of the location of the robot on the grid
    3. A char type variable payload to hold letters as load
  2. The Robot class must have the following public member functions
    1. A default constructor places the robot at location (0,0) and payload to character space: ( empty)
    2. A constructor that receives three parameters to initialize the private data members.
    3. Include a set and get method for each of the private data members.
    4. Include a member function print() that prints the location of the robot on the grid as well as its loa
    5. Method pickup(int lx, int ly) with boolean return typ This method examines the current location of the robot and if not at location (lx, ly), it should display a message not at (lx,ly) and return false. If the is no load (letters) at the location print No load at this location and return false. Otherwise, the method should examine the payload of the robot and if empty it will pick up the load at location (lx,ly) and place it in the payload and returns true. Note, the character at location (lx,ly) on the grid should be set to blank ( space)
    6. Method dropOff(int lx, int ly) with Boolean return type. This method examines the current location of the robot and if not at location (lx, ly), it should display a message not at (lx,ly) and return false. Otherwise, the method examines the payload of the robot and if full, it will drop its load at location (lx, ly) on the grid and and returns true. Note, the grid element grid[lx][ly] should be set to the character that was placed there.
    7. Method moveRight() with a void return type. The method moves robot one unit to the right on the grid. If the robot hits the right boundary of the grid, it should print Right boundary reached.
    8. Method moveLeft() with a void return type. The method moves robot one unit to the left on the grid. If the robot hits the left boundary of the grid, it should print Left boundary reached.
    9. Method moveUp() with a void return type. The method moves robot one unit up on the grid. If the robot hits the top boundary of the grid, it should print Top boundary reached.
    10. Method moveDown() with a void return type. The method moves robot one unit down on the grid. If the robot hits the bottom boundary of the grid, it should print Bottom boundary reached.
    11. Method MoveTo(int lx, int ly) with boolean return type. This method checks to see whether the location (lx, ly) is within the boundary of the grid, if not returns false. Otherwise, it uses the combination of moveUp(), moveDown(), moveRight(), moveLeft() methods to move the robot to this new location on the grid. Note: if the robot has to move, say 5, units to the right you must write a loop and call moveRight() five times rather that literally writing moveRight() five times.

Write a nonmember function print2D() that reveries a 2D array of characters and prints it ( in our case 25 elements per row).

Write a main function to test the operation of the robot.

  1. You program should define a 2D array representing the grid char grid [26][26] . Initialize all the elements of the 2D array to blank. Then, place character B at location (10, 8) and C at (22, 4). Use print2D() to print the grid
  2. Create two robots R1 and R2 using the two constructors. Print the location of the robots.
  3. Use moveTo() method to place R1 at location (23, 24) and R2 at location (15, 3). Print the location of the robots
  4. Direct R1 to pick up B at location (10, 8) and place it at location (20,20). Print the location of the robot. Print the grid.
  5. Direct R2 to pick up C at location (22, 4) and place it at location (0, 0). Print the location of the robot. Print the grid.

Part Two - Graphical User Interface 65 Points

Create a Graphical User Interface for simulating the robot. A sample GUI for this project may be as following.

image text in transcribed

Display Screen Pick Up Drop Off Move UP Move LEFT Move RIGHT Move DWON Display Screen Pick Up Drop Off Move UP Move LEFT Move RIGHT Move DWON

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

Power Bi And Azure Integrating Cloud Analytics For Scalable Solutions

Authors: Kiet Huynh

1st Edition

B0CMHKB85L, 979-8868959943

More Books

Students also viewed these Databases questions

Question

a. How do you think these stereotypes developed?

Answered: 1 week ago

Question

7. Describe phases of multicultural identity development.

Answered: 1 week ago