Question: MVC Design One principle often used in software design is separation of concerns. Modules should depend on one another as little a possible to do


MVC Design
One principle often used in software design is "separation of concerns". Modules should depend on one another as little a possible to do the job they are given.
This can be seen in a common programming pattern used to design graphical applications: the Model-View-Controller (MVC) pattern.
https://en.wikipedia.org/wiki/Model-view-controller
In an MVC design, the View module is concerned with presenting a graphical view of the application to the user. The Model is concerned with maintaining a valid representation of the current state of the application, and the Controller is responsible for receiving instructions from the user. Java does not do anything to enforce these roles, as with all design patterns, MVC is simply a set of guidelines that help a software designer make decisions about how to decompose a program into smaller, simpler parts. By separating the MVC concerns, each module has a clear role and each can be programmed and tested independently.
You will learn more about design patterns if you take CSC 133, but for now just know that I used one to help me decide how to break SimpleBot into smaller logical parts.
Overview of Project 2
You are going to write and turn in two classes for Project 2: SimpleBotController and SimpleBotStatement. SimpleBotController will take input that the user supplies, validate it, and then give the model object what it needs to do its work. What the model needs is a description of the robot's world and a list of the program statements that the robot should follow.
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.
SimpleBotStatement
Each SimpleBotStatement represents a single SimpleBot program statement (eg, 0 x*** -> n 0). Write a class called SimpleBotStatement with the following public methods (it should have no other public methods).
public SimpleBotStatement(String s)
If you consider each grouping of non-whitespace characters in the string to be "tokens", then the sequence of tokens in the string should be: an integer (the trigger state), a four-character string (the trigger sensors), the string "->" (unused), a single character (the action), and an integer (the new state). The four-character token should have the first character one of n/x/*, the second one of e/x/*, the third one of w/x/*, and the fourth one of s/x/*. The single action character should be one of n/e/w/s/x. Any amount of whitespace is allowed before, between and after each token, but these should be the only tokens in the string and they should occur in this order. If any of these expectations are broken, an IllegalArgumentException should be thrown.
public boolean match(int state, boolean n, boolean e, boolean w, boolean s)
This method will be used to match a robot's current state and sensor readings against a program statement to see if they are a match. The parameters n/e/w/s will each be true if there is a wall in the immediately adjacent square. If state does not match "the trigger state" return false. If n is true and the first character of the trigger sensors is x, or n is false and the first character of the trigger sensors is n, return false. The remaining parameters should behave similarly to n except with the second, third and fourth characters of the trigger sensors. If none of these tests causes the method to return false, then true should be returned.
public int nextState()
This method should return the new state value found by the constructor.
public char nextAction()
This method should return the action value found by the constructor.
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) { } } Notes
~ Playing with the PicoBot simulator and reading about PicoBot programs may help you understand the project (http:/ifty.stanford.edu/2010/dodds-picobot/picobotLocal.html).
~ Although PicoBot allows characters to be upper or lower case, SimpleBot requires the use of lower case only.
~ Your classes should be robust. A class is robust if it can't be made to misbehave and only throws exceptions under conditions described in the javadoc. This requires you to test thoroughly and include all the exceptions mentioned in the specification in your javadoc.
~ In testing your classes, I will try to make them crash. I will use them according to the specification, but my goal will be to try to make them misbehave. So, read the specification carefully and critically, and test as if you were me trying to make thing go wrong.
MVC Design One principle often used in software design is 'separation of concerms". Modules should depend on one another as litle a possible to do the job they are given. This can be seen in a ommon programming pattem used to design graphical applications the Mcdel-Vew-centroller (MVC) pattern htps en wikipedia.orgwikiModel view controller In an MV design, the v ew module s concemed wth presentin graphical View at the application to the user. I h Model ls concerned with maintaining a valid representa on at the current state o the ap ication and the controller s responsible to receiving instructions from the user. Java does not do anything to enforce these roles, as with all design patterns, MVC is simply a set of guidelines that help a software designer make decisions about how to decompose a program into smaller, simpler parts. Dy separalim lhe M oonoerris Bach modulB hasclear 'ole nd (ech uan bB pro ran mu and lesled "depen ertly You will leam more about design patterns it you take CSC 133, but tor now just know that I used one to help me decide how to break SimpleHot into sme ler logical parts. Overview of Project 2 You are going to write and turn in two classes for Project 2: SimpleBotController and SimpleBotStaterment. SimpleBotController will take input thet the user supplies, validate it, and then give the model object wha ncuds is a desc' glion of the 'obct's world and a list of the prograrn stalur'Unls lhal lhe rolx1 should follow. t it needs to do its work What the model Ihe robol SimpleBotController inte a cass called sing 1 with the tolaw ng public methods t should have no Your controler will have tne ability to read a new desc phon of the robot's world tne sblity to read in a new program, and the ability to start a simulation other public methods except a constructor if you want it). et tr 11 readw or shou read nes rom hy canner urt here are no more ines o read. Each lne w represen row n he ro o s world. The 'ne is allowed o havB w "tes ce thal rs spaces and at and he ou characters . w b. The lola number of W b)haracters found shoul bethe same on each line, and this number indicates the number of columns in the robors world The input lnes shculd have at least one row and at ast ane column There shoukd be exacly cner ir any of these spec tications are voated or IS nu11 an :11"galaegun.ntx:a.Fti:n Should be 1hrown readProgram should read lines from the: Scanner until there are no more lines to rad For each line, you should first remove any comment and en any whitespace from the beginning and endothe de-commented string (A comment bogins with the frst #" and goes to the end of the line.) t the resuling string is empty the li se, the modited line should be used to construct a new SimpleHostatement objeci. It the maditied ine is an illegal pragram statement, the construction ot th Si pleBot tatement w ail ith an lleg Argumen Exception. Your eadProgram met d should not catch this exception and instead should allow it to con nue to the c er o reac rogram. You should docume aten lega Argumen xception is hrown if a program is illegaly formialled. ne can be ignored Othewi Note that reedWorld and read Program carn each be called more than once, but it is always the most recenit call to either of these methods that defines what the robol' s world and prograrn . When start is called, a SimpleBotModel object should be created and the most recently read world and program should be passad to its constructor. If not both a world and program have been read, an lleguleLion should be thrown. l the robol's world. The prograrn sh hould be repreerled as an array of SiripleDoSlalerienl wilh the irs eleenl cf Une 1 to represer The workd shoulkd be epreseled as a two-dimensknial array of char, folkwing the saie convenlions used in Project array heing the frst statement ot the pragram and the last element of the array being the last statement a the pragram MVC Design One principle often used in software design is 'separation of concerms". Modules should depend on one another as litle a possible to do the job they are given. This can be seen in a ommon programming pattem used to design graphical applications the Mcdel-Vew-centroller (MVC) pattern htps en wikipedia.orgwikiModel view controller In an MV design, the v ew module s concemed wth presentin graphical View at the application to the user. I h Model ls concerned with maintaining a valid representa on at the current state o the ap ication and the controller s responsible to receiving instructions from the user. Java does not do anything to enforce these roles, as with all design patterns, MVC is simply a set of guidelines that help a software designer make decisions about how to decompose a program into smaller, simpler parts. Dy separalim lhe M oonoerris Bach modulB hasclear 'ole nd (ech uan bB pro ran mu and lesled "depen ertly You will leam more about design patterns it you take CSC 133, but tor now just know that I used one to help me decide how to break SimpleHot into sme ler logical parts. Overview of Project 2 You are going to write and turn in two classes for Project 2: SimpleBotController and SimpleBotStaterment. SimpleBotController will take input thet the user supplies, validate it, and then give the model object wha ncuds is a desc' glion of the 'obct's world and a list of the prograrn stalur'Unls lhal lhe rolx1 should follow. t it needs to do its work What the model Ihe robol SimpleBotController inte a cass called sing 1 with the tolaw ng public methods t should have no Your controler will have tne ability to read a new desc phon of the robot's world tne sblity to read in a new program, and the ability to start a simulation other public methods except a constructor if you want it). et tr 11 readw or shou read nes rom hy canner urt here are no more ines o read. Each lne w represen row n he ro o s world. The 'ne is allowed o havB w "tes ce thal rs spaces and at and he ou characters . w b. The lola number of W b)haracters found shoul bethe same on each line, and this number indicates the number of columns in the robors world The input lnes shculd have at least one row and at ast ane column There shoukd be exacly cner ir any of these spec tications are voated or IS nu11 an :11"galaegun.ntx:a.Fti:n Should be 1hrown readProgram should read lines from the: Scanner until there are no more lines to rad For each line, you should first remove any comment and en any whitespace from the beginning and endothe de-commented string (A comment bogins with the frst #" and goes to the end of the line.) t the resuling string is empty the li se, the modited line should be used to construct a new SimpleHostatement objeci. It the maditied ine is an illegal pragram statement, the construction ot th Si pleBot tatement w ail ith an lleg Argumen Exception. Your eadProgram met d should not catch this exception and instead should allow it to con nue to the c er o reac rogram. You should docume aten lega Argumen xception is hrown if a program is illegaly formialled. ne can be ignored Othewi Note that reedWorld and read Program carn each be called more than once, but it is always the most recenit call to either of these methods that defines what the robol' s world and prograrn . When start is called, a SimpleBotModel object should be created and the most recently read world and program should be passad to its constructor. If not both a world and program have been read, an lleguleLion should be thrown. l the robol's world. The prograrn sh hould be repreerled as an array of SiripleDoSlalerienl wilh the irs eleenl cf Une 1 to represer The workd shoulkd be epreseled as a two-dimensknial array of char, folkwing the saie convenlions used in Project array heing the frst statement ot the pragram and the last element of the array being the last statement a the pragram
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
