代写接单-Java / Object Oriented 2 COMP1009-E1

欢迎使用51辅导,51作业君孵化低价透明的学长辅导平台,服务保持优质,平均费用压低50%以上! 51fudao.top

1. Java / Object Oriented 2 COMP1009-E1 Total 50 marks

 This question requires you to provide an object-oriented design for a system to allow a game to be played. You should not try to produce full Java code for the system and will instead need to provide Java code for specific elements of the system. Consider the requirements on pages 3 to 5 and answer the following questions. Page 3 provides an overview of the game that should be supported, page 4 explains some details of requirements to support and page 5 gives you details of a supplied class and some hints. 1 a) Describe your design [18 marks] • Provide a class diagram for your system. Include all of your own classes, as well as the TextInputOutput class in your class diagram. Include all relationships, attributes, and operations for the classes shown. • Explain what each of your classes will do, the relationships that it has with other classes, and why, and outline what each method of each of your classes will do. You do not need to provide code for any of the methods (but see Q1c), just an outline to a similar level of detail given for the methods of the class TextInputOutput earlier. • Explain briefly how your program works – what objects are created, when, and which methods call which other methods to achieve the aims of your program. You may provide Java code samples if it will help your explanation, or may refer to any code from Q1c later, as long as you explain it here. 1 b) Describe your use of common design patterns [16 marks] • Explain briefly where and how you have used any common design patterns, explaining what each pattern is, why it is used, and how you would implement the pattern in your design. You should include any code samples you feel will clarify your answer. 1 c) Provide code and explanation for parts of your program [16 marks] Assuming that the rules are implemented as described above (the basic rules), provide Java code and a brief explanation of what it is doing/how it works for the following parts of your design/program: • Your main() function. • Your own sub-class of TextInputOutput, and lineRead() method. • Your validateMove() method. You should assume that any other methods and classes described in your answer to Q1a exist and work appropriately, so that you can call them from your code here without having to provide implementations for them yourself. COMP1009-E1 3 COMP1009-E1 Assume that someone is designing a new board game and wants a computer version of the game to try it out. • The game is played on an 8x8 grid. The columns are labelled with letters and the rows with numbers. Any square is empty, contains a red piece, or contains a blue piece. • There are two players, one player (the blue player) has 16 identical blue pieces, which start on rows 1 and 2, and the other player (the red player) has 16 identical red pieces, which start on rows 7 and 8. Figure 1 shows the initial position, where B denotes a blue piece and R a red piece. ABCDEFGH 1BBBBBBBB 2BBBBBBBB 3 4 5 6 7RRRRRRRR 8RRRRRRRR Figure 1: Initial position on the board • Any square can be specified by its column letter and row number. E.g. Square A2 is the square in column A, row 2; square G4 is the square in column G, row 4; the top left corner is A1 and the bottom right corner is H8. • Any move can be specified as a five-character string, specifying the column and row to move from, a dash/minus ( ‘-‘ ) then the column and row to move to. E.g. ”A2-A3” means move the piece in position A2 from A2 to position A3. “A3-B2” means move the move the piece from position A3 to position B2. • There are specific rules about how a piece can move and these can be changed for testing. The basic rules to get you started are considered below, but it should be assumed that these ‘basic rules’ could be changed by the designer. • For the basic rules, players must take it in turns to move, starting with the player playing blue. The red player wins if they move a piece to any square on row 1, and the blue player wins if they move a piece to any square on row 8. Either player wins if the other player is not able to make a move when it is their turn. • For the basic rules, in their turn a player can move a piece to any empty adjacent square (horizonally, vertically or diagonally). Making a move could result in capturing one or more of the opponent’s pieces, but for simplicity, the rules for capturing do not matter for this exam and you will not need to write the code to check for this or to implement it. You should provide functionality to allow pieces to be moved around the board, and to be removed from the board if they are captured. Description of the game to support COMP1009-E1 Turn over 4 COMP1009-E1 Your designed program should meet the following requirements: Requirement A) Each player must be able to see the board in their own output window, and be able to specify their own moves – i.e. they must each have their own TextInputOutput object that they will use for input and output. Requirement B) The rules should be considered to be flexible and changeable later. You should try to design your program so that it is possible to easily replace the rules with other rules to try out. The programmer will choose when the program is started which set of rules to use at that time (consider how to do this using the design patterns you have looked at). The current rules which are being tested will determine whether the move can be made or not, make it if it is appropriate, and determine how a player wins. To implement the rules, you will need to create the following three methods in some appropriate class(es), which together define the rules of the game: char hasWon() : checks whether either player has won. Returns ‘R’ for a red win, ‘B’ for a blue win, or ‘-‘ for neither player has currently won. boolean validateMove(int player, char colFrom, char rowFrom, char colTo, char rowTo) : validate a move from the specified player (1 or 2), whether it is a valid action for them to move a piece from the position given by colFrom,rowFrom (e.g. ‘A’,’1’ for A1) to the position given by colTo,RowTo (e.g. ‘B’,’2’ for B2). E.g. validateMove(1,‘A’,’1’.’B’,’2’) would return true if player 1 could move the piece from A1 to B2, or false otherwise. boolean makeMove(int player, char colFrom, char rowFrom, char colTo, char rowTo) : a specific player moves the piece in the column and row specified by colFrom and rowFrom to the new position at colTo,rowTo. If the piece captures any other pieces then this will also remove these captured pieces from the board. Requirement C) You are required to provide an ability for other systems to be notified about any moves which are made, through a function call. It should be possible for the programmer to easily add a new feature, such as a logging facility or an additional display for other people to watch the game, which will get told about every move which is made, by telling it which player made the move and the move details, in the same format as for the makeMove() method described earlier. Requirement D) Your program needs to have exactly one board object, for storing the positions of pieces and should ensure that only one board can ever be created in the program. Note that both players see the same board (possibly from different angles) in their own output window. Specific requirements COMP1009-E1 Provided class 5 COMP1009-E1 You are given the task of designing (not implementing) the Java program to allow players to play this game, using at least the basic rules. To do so, you are provided with the following class to handle input and output, and should not need any other input or output classes: Class: TextInputOutput, this class displays a text-based user interface (like a console window) which allows a specified user to type in text, and can display message strings to users. This could be considered to be reading from the keyboard and writing to the console, command prompt, or shell window on the screen. Multiple objects of this class can be created if desired, and each will act separately – displaying its own text and having its own input from users. This means that for a two player game you could create one per player and each player would have their own input and output facilities. This class has the following methods: • TextInputOutput() : constructor, takes no parameters • void show( int rows, int cols ) : display the text input/output display to the user, with a number of rows and columns specified by the two parameters. • void lineRead( String s ) : this is an abstract method which is called automatically when the user has typed in a string into the input area and pressed enter/return. Your sub-class should implement this method to do something with the text. s is the string which was typed by the user. • void outputString(String str) : outputs the string provided as a parameter to the text output area of this interface, so that a player can see it. Important Notes: You are recommended to consider the common design patterns that you have seen on this course to determine which, if any, could be used in your answer. Your answers to Q1b and Q1c may help you to think about the design, so you are recommended to consider these questions when designing your program. If this design seems very complex, you may want to initially consider a program without the ability to change the rules or to notify other objects about moves (see requirements B and C), then add these features to your design later if you have time. You can completely ignore concurrency issues for this exam. Just assume that your lineRead() method will be correctly called when a player enters information (even if it is not that player’s turn) and don’t consider how it is called, or what calls it. End of Question 1: Total 50 marks COMP1009-E1 Turn over 2. Haskell / Functional Programming 6 COMP1009-E1 Total 50 marks Suppose that you have been recruited to write an article for an online computing magazine on “Mechanisms For Defining Functions in Haskell’’. Write a short article (maximum 1,000 words) on this topic, illustrating each of the mechanisms that you mention with a small practical example written in Haskell. [50 marks] Further instructions: • Please include a word count at the end of your article. The Haskell examples should be devised by yourself rather than being copied or adapted from the course materials, and should not be included in the word count. • Your article should have a clear narrative structure rather than simply being a list of mechanisms. Your article should be self-contained and not include a bibliography or links to external web pages or other resources. • You may assume that your audience is familiar with the basics of programming but has no Haskell experience. Articles must not be posted online. • As this take-home examination replaces a normal exam it will be conducted under normal exam conditions – we are not able to offer help or feedback on draft articles, and students must not seek assistance from others. End of Question 2: Total 50 marks COMP1009-E1 END


51作业君

Email:51zuoyejun

@gmail.com

添加客服微信: abby12468