首页 > > 详细

Software Design III (CS 340)

Software Design III (CS 340), Spring 2019 Assignment 01 (40 points) Due by 5:00 PM, Friday, 15 February 2019 1 Word-Search Puzzle (20 points) For this assignment, you will be using the provided WordPuzzle class. This class is almost entirely complete. When its main() method is executed, it will open up a window, featuring a single button; when that button is pressed a le-chooser dialogue window will open, allowing the user to select a text- le. Once a le is chosen, the program calls the solve() method, with the le as input. Your job is to implement a new class, called WordPuzzleSolver. This new class must implement the provided interface, PuzzleSolver, which means:  There will be a public method, readFile(), that takes in a le as input. This method must be called so that the implementing class knows which le it will use to read in the data about the puzzle it needs to solve. (It will not solve the puzzle yet, that will come later). Exactly how this method works is up to you.  There will be a public method, solvePuzzle(), that solves the puzzle contained in the le that was sent as input to the previous method. Thus, this method will only work if the previous method has already been called, with a proper puzzle le as input (the format of puzzle les, and of correct output, is described below).  Back in the WordPuzzle class, you will complete the solve() method so that when called it creates an instance of your new solver class, sends in the input le, and calls the two methods just described to solve the puzzle and print results. A puzzle le is simply a text- le. The rst line consists of two positive integers, giving the number of rows and number of columns, respectively, of a word-search puzzle. Following that will be a block of text of the given size (you can assume that the input is in the right format). After that block of text, there will be one or more words, each on a single line. As an example, the following speci es a (5  6) puzzle grid, along with 4 words for which to search: 5 6 turtle waterb elofem evodek pckrse turtle dove packers fee 1 Your program will read in the grid of letters (using any data-structures you choose). It will then proceed through the list of words, one at a time, in order. For each word, it will search the grid for that word, looking up, down, left, right, and diagonally. Words can run in any of the 8 possible directions, and cannot skip any letters, or run o the sides of the grid. For each word that can be found, the program will report that fact, using the exact format: "" was found at row , column , going . where the row-number and column-number are given as the starting position ( rst character) of the word, counting from the top of the grid of characters, left-to-right, and starting at 0, as in an array or String. The direction reported will be one of the following, depending upon what direction the word can be found: U, D, R, L, UR, UL, DR, DL (up, down, left, right, up-right, up-left, down-right, down-left). You can assume that each word occurs at most one time in the grid, so that if the word can be found, the output will be unique. When a word is not found anywhere in the grid, that will also be reported, using the exact format: "" was not found. For the example puzzle shown on the previous page, then, the correct output would be as follows: "turtle" was found at row 0, column 0, going R. "dove" was found at row 3, column 3, going L. "packers" was not found. "fee" was found at row 2, column 3, going DR. Note 01: the assignment download includes two sample word-puzzle les, along with a le that shows the correct output for each input le. For full points, your code should produce exactly the same output for these sample les. Note 02: your code should be able to handle any input le that it is given, so long as that le is in the basic format described. When grading the work, I will be testing your code using les of my own. If you want to make more puzzle les for de-bugging and testing purposes, feel free to do so. You can create any such les you need using a simple text editor. 2 2 Assembly Language Simulator (20 points) For this part of the assignment, you will be creating a program that simulates a very simple computing system. Your program will read in les consisting of code in a simple version of assembly language (that is, a simple set of basic instructions to follow); it will then simulate execution of that code, printing out the results at the end. You should begin by creating a new class, called Assembler. This code should do the same thing as the WordPuzzle class for the rst part of the assignment. That is, it should create a window with a button and label, and allow the user to choose text- les to open (feel free to cut and paste from the other class, making whatever changes needed). Once your code opens up a le chosen by the user, it should send that le for processing by another class (with whatever name you choose). That other class is where you will implement the simulation of the assembly language processor. The system you are simulating has the following features: 1. It has two registers, A and B, each of which is a memory location that is capable of storing a non-negative integer value (that is, a number n such that 0  n  Integer.MAX_VALUE). At the start of the execution of any program, each register starts o at zero (0). 2. A program is read from a text- le. Each line consists of one of the following instructions:  ADD: this command adds a number to one of the registers; it takes the name of the register, along with an integer value to add, as arguments. For example, the command ADD A 3 adds 3 to the value currently stored in register A; the command ADD B -2 subtracts 2 from the value of register B (by adding 􀀀2). Remember that registers can only handle positive integer values; thus, any subtraction that would make the register value negative in fact only makes it hold the value 0. Similarly, any addition that would make the value too large has the e ect that the register holds maximal value (Integer.MAX_VALUE).  INC: this command increments the register that is named as an argument. For instance, the command INC A increments register A. The command behaves as if it were identical to ADD A 1, which means that if register A is already at the maximum possible value, executing INC A has no e ect.  JIG: this command executes a conditional jump in the code by comparing the two regis- ters; it takes the names of the two registers, in some order, along with an integer value, as arguments. When executed, it checks whether the value in the rst named register is greater than or equal to the value of the second named register, and if so moves forwards or backwards by the number of lines given as the last argument. Thus, the command JIG A B 2 checks if the value of register A  the value of register B, and if so moves 2 lines forward. The command JIG B A -1 checks if the value of B  the value of A, and if so moves 1 line back in the code.  SET: this command sets a named register to a given integer value. Thus, the command SET A 4 sets the value of register A to 4. You can assume that the integer value given is always in the possible range for any register. 3. Unless the program executes a conditional jump forward or back, it proceeds in an imperative sequence, one line at a time. Execution terminates either when the program reaches the end of the le, or when it executes a jump that causes it to move to a position that is outside of 3 the bounds of the program. That is, if we are at the second line of a 3-line program, then a jump forward or backwards 2 or more lines will cause the program to terminate. As an example, consider the following program: INC A JIG A B 2 INC B INC A When this code executes, it starts with both registers set to 0, as always. The rst line then increments register A to 1. At the second line, it checks whether the value of A  the value of B, and since it now is, it jumps forward 2 lines, to the last line of code. That line then increments register A once again, to value 2, and the program terminates. Your program will simulate this process. When the program terminates, it will produce a single line of output, giving the nal values of the two registers, in the exact format: RESULT => A: , B: . That is, for the example program shown above, the output will be: RESULT => A: 2, B: 0. Note: as before, your code must handle any program in the given format, and will be tested on les beyond the two that are included with the assignment download. You can assume that every program will eventually terminate in a nite number of steps. Handing in your work: you will hand in your code via D2L. Your work should consist of a single compressed folder containing all of your source code, for both parts of the assignment. Files should be named as speci ed in this document, where required. The class website contains more information about preparing compressed documents if you need a refresher on that. Coding conventions: Each part of the program has a points total, given above. For full points, you should complete all those components, and observe the basic coding conventions as follows:  Comments should appear at the start of any code- le you write or change, with your name, the date of your work, and a short explanation of what the code does.  Each method should be preceded by a blank line, followed by at least one line of comments explaining what the method does.  Methods should be private if possible, and public only if necessary.  Class variables should be local to methods if possible, and should only appear as global variables if they appear in more than one method of the class.  Unless absolutely necessary, global instance variables should be private. 4  Code can be broken up by blank lines, but keep this to a low level. There should be no more than a single blank line separating pieces of code. Within a line of code, white space should not be too wide, for clarity.  Code should be properly indented and separated into lines.  Standard naming conventions (capitalized class names, lower-case method/variable names, etc.) should be followed. 5
联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!