Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

can you write the code for SimpleBotModel and SimpleBot Controller SimpleBotModel You will write a complete SimpleBotModel class in a later project, but you will

can you write the code for SimpleBotModel and SimpleBot Controller

SimpleBotModel

You will write a complete SimpleBotModel class in a later project, but you will need a SimpleBotModel class in this project to allow your SimpleBotController to create a SimpleBotModel object. Use the following class to allow compilation (but don't turn it in).

public class SimpleBotModel { public SimpleBotModel(char[][] world, SimpleBotStatement[] program) { } } 

--------------------------------------------------------------------------

SimpleBotController

Your controller will have the ability to read a new description of the robot's world, the ability to read in a new program, and the ability to start a simulation. Write a class called SimpleBotController with the following public methods (it should have no other public methods except a constructor if you want it).

public void readWorld(Scanner in) 

readWorld should read lines from the Scanner until there are no more lines to read. Each line will represent a row in the robot's world. The line is allowed to have whitespace characters (spaces and tabs) and the four characters (r, w, b, t). The total number of (r, w, b, t) characters found should be the same on each line, and this number indicates the number of columns in the robot's world. The input lines should have at least one row and at least one column. There should be exactly one r. If any of these specifications are violated or in is null an IllegalArgumentException should be thrown.

public void readProgram(Scanner in) 

readProgram should read lines from the Scanner until there are no more lines to read. For each line, you should first remove any comment and then any whitespace from the beginning and end of the de-commented string. (A comment begins with the first '#' and goes to the end of the line.) If the resulting string is empty the line can be ignored. Otherwise, the modified line should be used to construct a new SimpleBotStatement object. If the modified line is an illegal program statement, the construction of the SimpleBotStatement will fail with an IllegalArgumentException. Your readProgram method should not catch this exception and instead should allow it to continue to the caller of readProgram. You should document that an IllegalArgumentException is thrown if a program is illegally formatted.

Note that readWorld and readProgram can each be called more than once, but it is always the most recent call to either of these methods that defines what the robot's world and program.

public void start() 

When start is called, a SimpleBotModel object should be created and the most recently read world and program should be passed to its constructor. If not both a world and program have been read, an IllegalStateException should be thrown.

The world should be represented as a two-dimensional array of char, following the same conventions used in Project 1 to represent the robot's world. The program should be represented as an array of SimpleBotStatement with the first element of the array being the first statement of the program and the last element of the array being the last statement of the program.

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

Concepts Of Database Management

Authors: Joy L. Starks, Philip J. Pratt, Mary Z. Last

9th Edition

1337093424, 978-1337093422

More Books

Students also viewed these Databases questions

Question

Describe Table Structures in RDMSs.

Answered: 1 week ago