Cardiff School of Computer Science and Informatics Coursework Assessment Pro-forma Module Code: CM1210 Module Title: Object Oriented Java Programming Lecturer: Dr Matt Morgan & Dr Yuhua Li Assessment...

How to do the java programming


Cardiff School of Computer Science and Informatics Coursework Assessment Pro-forma Module Code: CM1210 Module Title: Object Oriented Java Programming Lecturer: Dr Matt Morgan & Dr Yuhua Li Assessment Title: RESIT Coursework Assessment Number: 1 Date Set: Monday 3rd August 2020 Submission date and Time: Friday 21st August at 9:30am This coursework is worth 100% of the total marks available for this module. If coursework is submitted late (and where there are no extenuating circumstances): 1. If the assessment is submitted no later than 24 hours after the deadline, the mark for the assessment will be capped at the minimum pass mark; 2. If the assessment is submitted more than 24 hours after the deadline, a mark of 0 will be given for the assessment. Your submission must include the official Coursework Submission Cover sheet, which can be found here: https://docs.cs.cf.ac.uk/downloads/coursework/Coversheet.pdf Submission Instructions Email your final submission to [email protected] and [email protected]. Your submission should contain the following files: Description Type Name Cover sheet Compulsory One PDF (.pdf) file [Student number].pdf Q1 Compulsory One PDF (.pdf) containing screen shots showing an exam- ple of the output of each application in question 1. You should only provide ONE screen shot for each. Q1_[Student number].pdf Compulsory A zip archive containing one or more Java source file(s) (.java) containing your answers to questions 1 (a) and (b). Each source code file should contain your name and student number in a comment. Q1_[Student number].zip Q2 Compulsory One PDF (.pdf) containing your measures for 2 (b). Q2_[Student number].pdf Compulsory A zip archive containing one or more Java source file(s) (.java) containing your answers to questions 2 (a) and (b). Each source code file should contain your name and student number in a comment. Q2_[Student number].zip Any code submitted will be run on a system equivalent to those available in the Windows laboratory and must be submitted as stipulated in the instructions above. Any deviation from the submission instructions above (including the number and types of files submitted) will result in a reduction in marks for that assessment or question part of 10%. Staff reserve the right to invite students to a meeting to discuss coursework submissions 1 https://docs.cs.cf.ac.uk/downloads/coursework/Coversheet.pdf Assignment 1. Any n × n magic square (where n is an odd integer) consists of an n × n matrix whose elements contain the numbers 1, 2, 3, ..., n2 such that the sum of each row, column and diagonal is equal to n(n2+1) 2 . For example, the following magic square for n = 3, with the sum of each row, column and diagonal being 3(3 2+1) 2 = 15: 6 1 8 7 5 3 2 9 4 (a) An algorithm for generating an n× n magic square for odd n is as follows: NOTE: Assume the rows and columns wrap around (i.e., moving one column left from the first column gives the last column) Create a 2 dimensional array of size n by n and set all values to be 0 Set x = 1, y = n+12 (row 1 and column n+1 2 ). Insert 1 at x, y for i = 2 to n2 do if element x− 1,y − 1 is empty (i.e. = 0) then x = x− 1, y = y − 1 else x = x+ 1, y = y end if Insert i at x, y end for Write a command line application that prompts the user for an odd integer and displays a magic square of that size to standard output (i.e. the command line). [HINT: Recall that Java arrays start at the element 0, and it may help to define a class to store a square matrix]. (20 Marks) [Functionality: 8, Design: 8, Ease of use: 2, Presentation: 2] (b) Write a command line game with the following functionality: • The application should prompt the user for an odd integer and create a magic square of that size. • The magic square should then be shuffled by repeatedly (for n2 times) choosing a random element and swapping it with a random neighbour (not including diagonals). • The shuffled square should be displayed to the user, who must attempt to reconstruct a magic square. • The user makes moves by giving input of the form: i j direction 2 where i and j specify the row and column of an element to be swapped, and direction (either U , D ,L ,R representing up, down, left and right) specifies which direction it should be swapped with. For example, the move 2 1 D applied to the square above would give: 6 1 8 2 5 3 7 9 4 • On completion, the game should report the number of moves made. (30 Marks) [Functionality: 14, Design: 10, Ease of use: 4, Presentation: 2] HINT: MULTIDIMENSIONAL ARRAYS The code below gives an example of using a 2-dimensional array to store values: public class MultiArrayTest { public static void main( String[] args ) { int a[][] = {{1,2,3}, {4,5,6}}; System.out.println( "length of a is " + a.length ); for (int i = 0; i < a.length;="" i++)="" {="" for="" (int="" j="0;" j="">< a[i].length; j++) { system.out.print( a[i][j] + " " ); } system.out.println(); } } } 2. (a) extracting words from a text document is the first step for many text-based applications of artificial intelligence, e.g., detecting abusive tweets on twitter. this task asks you to extract all valid words from the document “an article.txt” based on a given vocabulary “google- 10000-english-no-swears.txt1” (both files provided). specifically, if a word token from “an article.txt” matches a word in “google-10000-english-no-swears.txt” (case insensi- tively), you keep that word, otherwise you discard it. you should use arraylist to store data within the java program, so the return of this task is an arraylist containing all valid words from “an article.txt”. note that these two text files are relatively big, you should consider how to make your program efficient. (30 marks) [functionality: 16, design: 10, ease of use: 2, presentation: 2] 1this vocabulary contains a list of the 10,000 most common english words in order of frequency of the google’s trillion word corpus. 3 (b) implement the merge sort in order to sort the words obtained from above in alphabetical order (the pseudocode for the method is available in the lecture notes), i.e., the output of your program will be the sorted words in alphabetical order. for the merge sort algorithm write a method e.g. mergesort(…), measure • time that is needed to sort 100 of the words, 200 of the words, 300 of the words, etc. up to all words by the algorithm. • count the moves/comparisons that occur while sorting elements. (before attempting this exercise you should work through the algorithms lab exercises, available on learning central. the techniques used there will help you to work out how to approach this part of the coursework, in particular there are examples of how to time algorithms and count the moves and swaps.) (20 marks) [functionality: 12, design: 4, ease of use: 2, presentation: 2] code reuse your solutions may make use of any classes in the core java api. you may also reproduce small pieces of code from: • the cm1210 course handouts and solutions • java.oracle.com • any textbooks provided: • the section reproduced does not form the entire solution to a single question • the source of the code is clearly referenced in your source code • your code is commented to demonstrate clearly that you understand how the reproduced code works (i.e., explain why types have been selected, why other language features have been used, etc.) you may not reproduce code written by any other student or code downloaded from any other website. if you are in any doubt about whether you may include a piece of code that you have not written yourself, ask the lecturer before submitting. learning outcomes assessed 1. develop a object-oriented program that has input and output functionality and that is event driven 2. show fluency in selecting and using basic components in the java language 3. show an understanding of the theoretical underpinnings of the java language 4. implement basic data structures and algorithms 5. analyse and describe the performance of data-structures and algorithms 4 criteria for assessment credit will be awarded against the following criteria: functionality • to what extent does the program perform the task(s) required by the question. design • how well designed is the code, particularly with respect to the ease with which it may be maintained or extended. in particular, consideration will be given to: • use of appropriate types, program control structures and classes from the core api. • definition of appropriate classes, interfaces and methods. ease of use • formatting of input/output. • interaction with the user. • how does the code deal with invalid user input? will the applications crash for certain data? documentation and presentation • clear and appropriate screenshots. • appropriate use of comments. • readability of code. feedback and suggestion for future learning feedback on your coursework will address the above criteria. feedback and marks will be returned via email after the examination board has taken place. 5 the of and to a in for is on that by this with i you it not or be are from at as your all have new more an was we will home can us about if page my has search free but our one other do no information time they site he up may what which their news out use any there see only so his when contact here business who web also now help get pm view online c e first am been would how were me s services some these click its like service x than find price date back top people had list name just over state year day into email two health n world re next used go b work last most products music buy data make them should product system post her city t add policy number such please available copyright support message after best software then jan good video well d where info rights public books high school through m each links she review years order very privacy book items company r read group need many user said de does set under general research university january mail full map reviews program life know games way days management p part could great united hotel real f item international center ebay must store travel comments made development report off member details line terms before hotels did send right type because local those using results office education national car design take posted internet address community within states area want phone dvd shipping reserved subject between forum family l long based w code show o even black check special prices website index being women much sign file link open today technology south case project a[i].length;="" j++)="" {="" system.out.print(="" a[i][j]="" +="" "="" "="" );="" }="" system.out.println();="" }="" }="" }="" 2.="" (a)="" extracting="" words="" from="" a="" text="" document="" is="" the="" first="" step="" for="" many="" text-based="" applications="" of="" artificial="" intelligence,="" e.g.,="" detecting="" abusive="" tweets="" on="" twitter.="" this="" task="" asks="" you="" to="" extract="" all="" valid="" words="" from="" the="" document="" “an="" article.txt”="" based="" on="" a="" given="" vocabulary="" “google-="" 10000-english-no-swears.txt1”="" (both="" files="" provided).="" specifically,="" if="" a="" word="" token="" from="" “an="" article.txt”="" matches="" a="" word="" in="" “google-10000-english-no-swears.txt”="" (case="" insensi-="" tively),="" you="" keep="" that="" word,="" otherwise="" you="" discard="" it.="" you="" should="" use="" arraylist="" to="" store="" data="" within="" the="" java="" program,="" so="" the="" return="" of="" this="" task="" is="" an="" arraylist="" containing="" all="" valid="" words="" from="" “an="" article.txt”.="" note="" that="" these="" two="" text="" files="" are="" relatively="" big,="" you="" should="" consider="" how="" to="" make="" your="" program="" efficient.="" (30="" marks)="" [functionality:="" 16,="" design:="" 10,="" ease="" of="" use:="" 2,="" presentation:="" 2]="" 1this="" vocabulary="" contains="" a="" list="" of="" the="" 10,000="" most="" common="" english="" words="" in="" order="" of="" frequency="" of="" the="" google’s="" trillion="" word="" corpus.="" 3="" (b)="" implement="" the="" merge="" sort="" in="" order="" to="" sort="" the="" words="" obtained="" from="" above="" in="" alphabetical="" order="" (the="" pseudocode="" for="" the="" method="" is="" available="" in="" the="" lecture="" notes),="" i.e.,="" the="" output="" of="" your="" program="" will="" be="" the="" sorted="" words="" in="" alphabetical="" order.="" for="" the="" merge="" sort="" algorithm="" write="" a="" method="" e.g.="" mergesort(…),="" measure="" •="" time="" that="" is="" needed="" to="" sort="" 100="" of="" the="" words,="" 200="" of="" the="" words,="" 300="" of="" the="" words,="" etc.="" up="" to="" all="" words="" by="" the="" algorithm.="" •="" count="" the="" moves/comparisons="" that="" occur="" while="" sorting="" elements.="" (before="" attempting="" this="" exercise="" you="" should="" work="" through="" the="" algorithms="" lab="" exercises,="" available="" on="" learning="" central.="" the="" techniques="" used="" there="" will="" help="" you="" to="" work="" out="" how="" to="" approach="" this="" part="" of="" the="" coursework,="" in="" particular="" there="" are="" examples="" of="" how="" to="" time="" algorithms="" and="" count="" the="" moves="" and="" swaps.)="" (20="" marks)="" [functionality:="" 12,="" design:="" 4,="" ease="" of="" use:="" 2,="" presentation:="" 2]="" code="" reuse="" your="" solutions="" may="" make="" use="" of="" any="" classes="" in="" the="" core="" java="" api.="" you="" may="" also="" reproduce="" small="" pieces="" of="" code="" from:="" •="" the="" cm1210="" course="" handouts="" and="" solutions="" •="" java.oracle.com="" •="" any="" textbooks="" provided:="" •="" the="" section="" reproduced="" does="" not="" form="" the="" entire="" solution="" to="" a="" single="" question="" •="" the="" source="" of="" the="" code="" is="" clearly="" referenced="" in="" your="" source="" code="" •="" your="" code="" is="" commented="" to="" demonstrate="" clearly="" that="" you="" understand="" how="" the="" reproduced="" code="" works="" (i.e.,="" explain="" why="" types="" have="" been="" selected,="" why="" other="" language="" features="" have="" been="" used,="" etc.)="" you="" may="" not="" reproduce="" code="" written="" by="" any="" other="" student="" or="" code="" downloaded="" from="" any="" other="" website.="" if="" you="" are="" in="" any="" doubt="" about="" whether="" you="" may="" include="" a="" piece="" of="" code="" that="" you="" have="" not="" written="" yourself,="" ask="" the="" lecturer="" before="" submitting.="" learning="" outcomes="" assessed="" 1.="" develop="" a="" object-oriented="" program="" that="" has="" input="" and="" output="" functionality="" and="" that="" is="" event="" driven="" 2.="" show="" fluency="" in="" selecting="" and="" using="" basic="" components="" in="" the="" java="" language="" 3.="" show="" an="" understanding="" of="" the="" theoretical="" underpinnings="" of="" the="" java="" language="" 4.="" implement="" basic="" data="" structures="" and="" algorithms="" 5.="" analyse="" and="" describe="" the="" performance="" of="" data-structures="" and="" algorithms="" 4="" criteria="" for="" assessment="" credit="" will="" be="" awarded="" against="" the="" following="" criteria:="" functionality="" •="" to="" what="" extent="" does="" the="" program="" perform="" the="" task(s)="" required="" by="" the="" question.="" design="" •="" how="" well="" designed="" is="" the="" code,="" particularly="" with="" respect="" to="" the="" ease="" with="" which="" it="" may="" be="" maintained="" or="" extended.="" in="" particular,="" consideration="" will="" be="" given="" to:="" •="" use="" of="" appropriate="" types,="" program="" control="" structures="" and="" classes="" from="" the="" core="" api.="" •="" definition="" of="" appropriate="" classes,="" interfaces="" and="" methods.="" ease="" of="" use="" •="" formatting="" of="" input/output.="" •="" interaction="" with="" the="" user.="" •="" how="" does="" the="" code="" deal="" with="" invalid="" user="" input?="" will="" the="" applications="" crash="" for="" certain="" data?="" documentation="" and="" presentation="" •="" clear="" and="" appropriate="" screenshots.="" •="" appropriate="" use="" of="" comments.="" •="" readability="" of="" code.="" feedback="" and="" suggestion="" for="" future="" learning="" feedback="" on="" your="" coursework="" will="" address="" the="" above="" criteria.="" feedback="" and="" marks="" will="" be="" returned="" via="" email="" after="" the="" examination="" board="" has="" taken="" place.="" 5="" the="" of="" and="" to="" a="" in="" for="" is="" on="" that="" by="" this="" with="" i="" you="" it="" not="" or="" be="" are="" from="" at="" as="" your="" all="" have="" new="" more="" an="" was="" we="" will="" home="" can="" us="" about="" if="" page="" my="" has="" search="" free="" but="" our="" one="" other="" do="" no="" information="" time="" they="" site="" he="" up="" may="" what="" which="" their="" news="" out="" use="" any="" there="" see="" only="" so="" his="" when="" contact="" here="" business="" who="" web="" also="" now="" help="" get="" pm="" view="" online="" c="" e="" first="" am="" been="" would="" how="" were="" me="" s="" services="" some="" these="" click="" its="" like="" service="" x="" than="" find="" price="" date="" back="" top="" people="" had="" list="" name="" just="" over="" state="" year="" day="" into="" email="" two="" health="" n="" world="" re="" next="" used="" go="" b="" work="" last="" most="" products="" music="" buy="" data="" make="" them="" should="" product="" system="" post="" her="" city="" t="" add="" policy="" number="" such="" please="" available="" copyright="" support="" message="" after="" best="" software="" then="" jan="" good="" video="" well="" d="" where="" info="" rights="" public="" books="" high="" school="" through="" m="" each="" links="" she="" review="" years="" order="" very="" privacy="" book="" items="" company="" r="" read="" group="" need="" many="" user="" said="" de="" does="" set="" under="" general="" research="" university="" january="" mail="" full="" map="" reviews="" program="" life="" know="" games="" way="" days="" management="" p="" part="" could="" great="" united="" hotel="" real="" f="" item="" international="" center="" ebay="" must="" store="" travel="" comments="" made="" development="" report="" off="" member="" details="" line="" terms="" before="" hotels="" did="" send="" right="" type="" because="" local="" those="" using="" results="" office="" education="" national="" car="" design="" take="" posted="" internet="" address="" community="" within="" states="" area="" want="" phone="" dvd="" shipping="" reserved="" subject="" between="" forum="" family="" l="" long="" based="" w="" code="" show="" o="" even="" black="" check="" special="" prices="" website="" index="" being="" women="" much="" sign="" file="" link="" open="" today="" technology="" south="" case="">
Aug 03, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here