Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

can you write the code for SimpleBotModel and SimpleBot Controller SimpleBotMode

ID: 3590292 • Letter: C

Question

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).

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

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).

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.

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.

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.

Explanation / Answer

/*
* 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.
* */

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;


public class SimpleBotController {
public void readWorld(Scanner in) {
List<List<Character>> charArrList = new ArrayList<>();
int lineLength = 0;
int countB = 0;
int countW = 0;
int countT = 0;
boolean firstLine = true;
while (in.hasNextLine()) { // check for next line
String text = in.nextLine(); // read next line
char[] arr = text.toCharArray();
List<Character> carr = new ArrayList<>();
int loopCountR = 0;
int loopCountB = 0;
int loopCountW = 0;
int loopCountT = 0;
for (int i = 0; i < arr.length; i++) {
if (arr[i] == 'r' || arr[i] == 'b' || arr[i] == 'w' || arr[i] == 't' || arr[i] == ' ' || arr[i] == ' ') {
if (arr[i] == 'r' && loopCountR == 1) {
throw new IllegalArgumentException("Found more than 1 r");
}
if (arr[i] != ' ' && arr[i] != ' ') {
if (arr[i] == 'b') loopCountB++;
if (arr[i] == 'w') loopCountW++;
if (arr[i] == 't') loopCountT++;
if (arr[i] == 'r') loopCountR++;
carr.add(arr[i]);
}
} else {
throw new IllegalArgumentException("Char other than r, b, w, t found");
}
}
charArrList.add(carr);
if (!firstLine && (countB != loopCountB || countW != loopCountW || countT != loopCountT)) {
throw new IllegalArgumentException("Different length line found");
}
else {
firstLine = false;
countB = loopCountB;
countW = loopCountW;
countT = loopCountT;
}
}
int size = charArrList.size();
lineLength = 1 + countB + countT + countW;
char[][] array = new char[size][lineLength];
for (int i = 0; i < size; i++) {
List<Character> temp = charArrList.get(i);
for (int j = 0; j < lineLength; j++) {
array[i][j] = temp.get(j);
}
}
}
  
public void readProgram(Scanner in) {
  
while (in.hasNextLine()) {
String statement = in.nextLine();
int index = statement.indexOf('#');
if (index != -1)
statement = statement.substring(0, index);
statement = statement.trim();
if (!statement.isEmpty()) {
try {
SimpleBotStatement sb = new SimpleBotStatement(statement);
}
catch(IllegalArgumentException e) {
System.out.println("IllegalArgumentException is thrown as a program is illegally formatted");
throw e;
}
}
}
  
}
  
public void start() {
  
}
}

Specification for start are not clear. I even doubt other specification. You need to give link to your exact questionand Project 1.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote