


全文预览已结束
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
c Manfred Kerber School of Computer ScienceAlexandros Evangelidis University of BirminghamWorksheet 5MSc/ICY Software WorkshopAssessed Exercise: 9% of the continuous assessment mark.Submission: Thursday 1 December 2016 2pm5% late submission penalty within the rst 24 hours. No submission after 24 hours.JavaDoc comments are mandatory. Follow the submission guidelines onhttps:/canvas.bham.ac.uk/files/3242907.Assessment via viva. In your submission write all classes in a single directory, calledWS1-5, from which you create your zip le.Exercise 1: (Basic, 20%) A Sudoku is a 9 9 quadratic structure with some numbersgiven in which the digits from 1 through 9 have to be lled so that in every row, in everycolumn, and in 9 sub-squares of size 3 3 each digit occurs exactly once. For more details,see /wiki/Sudoku.Let a fully solved Sudoku (of size 9 9) be given as a two-dimensional array of numbersbetween 1 and 9 so that each number occurs exactly once in each row, each column, andeach of the 9 sub-squares. For instance, the following is a fully solved Sudoku:+=+=+=+=+=+=+=+=+=+| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |+-+-+-+-+-+-+-+-+-+| 4 | 5 | 6 | 7 | 8 | 9 | 1 | 2 | 3 |+-+-+-+-+-+-+-+-+-+| 7 | 8 | 9 | 1 | 2 | 3 | 4 | 5 | 6 |+=+=+=+=+=+=+=+=+=+| 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 1 |+-+-+-+-+-+-+-+-+-+| 5 | 6 | 7 | 8 | 9 | 1 | 2 | 3 | 4 |+-+-+-+-+-+-+-+-+-+| 8 | 9 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |+=+=+=+=+=+=+=+=+=+| 3 | 4 | 5 | 6 | 7 | 8 | 9 | 1 | 2 |+-+-+-+-+-+-+-+-+-+| 6 | 7 | 8 | 9 | 1 | 2 | 3 | 4 | 5 |+-+-+-+-+-+-+-+-+-+| 9 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |+=+=+=+=+=+=+=+=+=+Create a class Sudoku with a single eld variable private int array;. For a fullylled Sudoku the values are all between 1 and 9 inclusively. For a partially lled Sudokuthe un lled elds should be represented by 0.Write the class with a constructor and a getter. Furthermore write a public StringtoString() method that prints a Sudoku in the format provided. Un lled eld should beleft empty rather than being lled with 0.Write also a method public boolean isFilled(), which checks whether all elements arelled in a Sudoku.Exercise 2:(Basic, 20%) Write in a class SudokuRead a method to read in a potentiallyonly partially lled Sudoku (given as below) from a le. That is, write a public SudokureadSudoku(String fileName) throws IllegalArgumentException, IOException me-thod. Your method should throw exceptions: if the le is not accessible; and if there isan input that is not a number between 1 and 9 (inclusively) or an empty space, or if theinput is incomplete. Note that in each line the rst 9 characters must be correct, but thatthe line may contain trailing input of any kind (typically further empty spaces). Likewisein the whole le the rst 9 lines must be correct, but there may be trailing lines (typicallyfurther empty lines).234567 94567891278912345234 67891567891 348912 456734 6789126 891234512345678Exercise 3: (Medium, 20%) Write in a SudokuCheck class a method that checkswhether a given Sudoku of size 9 9 satis es the conditions. Concretely, write a methodpublic static boolean check(Sudoku sudoku) that returns a two-dimensional resultarray of boolean values such that result0 is a one-dimensional array of boolean valuesindicating for each of the rows 0 through 8 whether it satis es the condition that each ofthe values 1 through 9 occurs exactly once in it or not. Likewise result1 states thisfor the columns, and result2 for the nine bigger squares. List the rows top-down, thecolumns left-right, and the 3 3 squares as follows:0 1 23 4 56 7 8For the example from Exercise 1 all 27 values in the result array are true.If you changed the 8 in the lower right corner from an 8 to a 9, e.g., the values ofresult08, result18, and result28 would all be false, all the other entriesin the result array would be true.If, however you changed in the original Sudoku the lower left corner from a 9 to an 8, thevalues of result08, result10, and result26 would all be false, and all theother entries in the result array would be true.Exercise 4: (Medium, 20%) Write a sub-class SudokuInteractive of the Sudokuclass which allows users to play a Sudoku interactively. In particular write a methodpublic static void play(String file), which reads in a Sudoku represented in thefile in the form given in Exercise 2. The user should be able to enter from the commandline their input by something like d4:5 in order to indicate that in eld d4 should go a 5.If that eld is part of the originally given Sudoku the action should be ignored; if, however,the user wants this way to update a previously entered value, then the current value inthe Sudoku should be overwritten. Except for these types of input only two other inputsshould be accepted: rst, reset to clear all the elds that the user has lled in, that is,the game is reset to the start situation; second, exit to terminate the game.Make sure that your program does not allow for any other input and that all exceptionsare caught appropriately.Override the public String toString() method so that the user sees whether a eldis given in the original Sudoku, or lled in by them, e.g. by displaying the Sudoku bysomething such as the following, where originally given elds such as a2 are displayed bysomething like *2*, whereas user lled elds such as a1 by something like 1 .1 2 3 4 5 6 7 8 9+=+=+=+=+=+=+=+=+=+a | 1 |*2*|*3*|*4*|*5*|*6*|*7*| |*9*|+-+-+-+-+-+-+-+-+-+b |*4*|*5*|*6*|*7*|*8*|*9*|*1*|*2*| |+-+-+-+-+-+-+-+-+-+c |*7*|*8*|*9*|*1*|*2*|*3*|*4*|*5*| 6 |+=+=+=+=+=+=+=+=+=+d |*2*|*3*|*4*| |*6*|*7*|*8*|*9*|*1*|+-+-+-+-+-+-+-+-+-+e |*5*|*6*|*7*|*8*|*9*|*1*| |*3*|*4*|+-+-+-+-+-+-+-+-+-+f |*8*|*9*|*1*|*2*| |*4*|*5*|*6*|*7*|+=+=+=+=+=+=+=+=+=+g |*3*|*4*| |*6*|*7*|*8*|*9*|*1*|*2*|+-+-+-+-+-+-+-+-+-+h |*6*| |*8*|*9*|*1*|*2*|*3*|*4*|*5*|+-+-+-+-+-+-+-+-+-+i | |*1*|*2*|*3*|*4*|*5*|*6*|*7*|*8*|+=+=+=+=+=+=+=+=+=+Exercise 5: (Advanced, 20%) Write a class SudokuSolve with a method publicvoid solve() that can solve easy Sudokus. Essentially there are two steps that yoursolver should apply:The fact that every number may occur only once in each row, column, or big squarerestri
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 森林草原防灭火课件
- 梭织女装常用知识培训课件
- 电气质量安全试题及答案
- 2025主管护师考试知识认知扩展与试题及答案
- 2025年【道路运输企业主要负责人】考试题库及道路运输企业主要负责人复审考试(含答案)
- 2025年地理信息系统GIS高级面试模拟题及答案解析
- 2025年英语四六级考试技巧与范文集锦
- 桥梁基础知识培训总结
- 2025年检验检测行业授权签字人考核题库
- 2025年注册验船师考试(A级船舶检验专业基础安全)综合试题及答案一
- 2025年基孔肯雅热和登革热防控知识考试试题及参考答案
- 2025-2026学年第一学期安全主题教育
- 汽车美容承包合同(标准版)
- 管道设计培训课件
- 会务服务考试试题及答案
- 《心系国防 强国有我》 课件-2024-2025学年高一上学期开学第一课国防教育主题班会
- 《创伤失血性休克中国急诊专家共识(2023)》解读课件
- 精神活性物质所致精神障碍患者的护理
- 私募基金份额代持协议范文
- 资料管理方案5篇
- 《退役军人保障法》知识考试题库(含各题型)
评论
0/150
提交评论