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

MVC Design One principle often used in software design is \"separation of concer

ID: 3599468 • Letter: M

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 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 3

This part of the project will provide the main program for your SimpleBot interpreter. Running SimpleBotMain should prompt the user for two files (a world file and a SimpleBot program file), then it should hook each file to a Scanner and pass the Scanners to a SimpleBotController. If the SimpleBotController successfully reads the two files, the SimpleBotController should be asked to start the simulation.

SimpleBotMain

Write a static main method in a class called SimpleBotMain. Your main should first prompt for the name of a SimpleBot program file. Once it has a valid file name, your main should prompt for the name of a SimpleBot world file. Each time the user types in a file that does not exist or types in a file that does exist but results in an error when read by the SimpleBotController, your main should immediately report the error and give the user a chance to try the file name again. Once the files have been read and the Scanners have been accepted by SimpleBotController, a message should be issued that the simulation is starting, and SimpleBotController's start method should be called. Here's an example interaction:

Note that prompting for the program file and prompting for the world file are identical operations except that prompts differ slightly. You should write a private helper method that takes a prompt as a parameter and returns a Scanner. The method should repeatedly prompt the user until it is is able to open the user response as a file and connect a Scanner to it.

Explanation / Answer

import java.io.FileNotFoundException;

import java.io.FileReader;

import java.util.Scanner;

public class SimpleBotMain {

public static void main(String[] args) {

// TODO Auto-generated method stub

//declaring status variables to keep track of weather files have loaded

int pf_status=0,wf_status=0;

//declaring scanner variable to take file name as input from user

Scanner in = new Scanner(System.in);

//declaring file reader variables

FileReader pf_fileReader,wf_fileReader;

// looping for program file

do{

//asking word file name from user

System.out.println("Program file name: ");

String file = in.nextLine();

try {

//reading program file

pf_fileReader = new FileReader(file);

pf_status = 1;

} catch (FileNotFoundException e) {

// TODO Auto-generated catch block

//e.printStackTrace();

//if file doesnot exist

System.out.println("Error. That file does not Exists.");

}

}while(pf_status==0);//break if file found

// looping for word file

do{

//asking word file name from user

System.out.println("word file name: ");

String file = in.nextLine();

try {

//reading program file

wf_fileReader = new FileReader(file);

wf_status = 1;

} catch (FileNotFoundException e) {

// TODO Auto-generated catch block

//e.printStackTrace();

//if file doesnot exist

System.out.println("Error. That file does not Exists.");

}

}while(wf_status==0);//break if file found

System.out.println("Starting simulation...");

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote