首页 > > 详细

讲解留学生Java、Java设计辅导、辅导留学生Java语言、Java编程辅导

Introduction
This is Coursework asignment 2 (of two coursework assignments) for 2017–18.
Part A asks that you demonstrate an understanding of constructors, the StringBuilder class,
parsing with String.split(), writing to and reading from a file, and serialisation.
Part B looks at a client/server system utilising a GUI for user interaction, and how choice of the
right data structure can improve performance.
Electronic files you should have:
Part A
• Admisions.java
• AdmisionsFileManager.java
• FeeType.java
• Gender.java
• OfferStatus.java
• ProspectiveStudent.java
• QualificationsType.java
• student_admissions_file.ser
• student_admissions_file.txt


Part B
• Anagram.java
• AnagramClient.java
• AnagramClientGUI.java
• AnagramFactory.java
• AnagramServer.java
• AnagramServerEngine.java
• Dictionary.java
• History.java
• Permutation.java
• PermutationFactory.java
• ServerUtils.java
• words.smal

What you should hand in: very important
There is one mark alocated for handing in uncompresed files – that is, students who hand in
ziped or .tar files or any other form. of compressed files can only score 49/50 marks.

There is one mark alocated for handing in just the .java files asked for, without putting them in a
directory; students who upload their files in directories can only achieve 49/50 marks.

Page 2 of 10
At the end of each section there is a list of files to be handed in – please note the hand-in
requirements supersede the generic University of London instructions. Please make sure
that you give in electronic versions of your .java files since you cannot gain any marks without
handing in the .java files asked for. Clas files are not needed, and any student giving in only a
class file wil not receive any marks for that part of the coursework assignment, so please be
careful about what you upload as you could fail if you submit incorectly.

Programs that do not compile wil not receive any marks.

The examiners wil compile and run your Java programs; students who hand in files
containing Java classes that cannot be compiled (e.g. PDFs) wil not be given any marks for
that part of the asignment.

Please put your name and student number as a coment at the top of each .java file that you hand
in.

You are asked to amend some of the clases given, and hand in your amended files. Please do not
change the names of the files you submit; in particular, make sure there is no conflict betwen your
file name and class names. Remember that if you give a file a name that is diferent from the name
of a public class that it contains (e.g. cwk2-partA.java file name versus AdmisionsFileManager
class name) your program wil not compile because of the conflict betwen the file name and the
class name, and you wil lose marks.


Page 3 of 10
Instructions

1.0 What version of Java to use
This coursework assignment uses some features introduced in Java 7, and a method introduced in
Java 8. Please use the most recent version of Java, Java 8.

1.1 Java 7 new features

1.1.1 The diamond operator
The programs you have ben given for parts A and B use the diamond operator, meaning that
the type of an ArrayList can be infered by the JVM. For example, this declaration:

ArrayList details = new ArrayList();

can be rewriten as:

ArrayList details = new ArrayList subscribers = new ArrayList();

rather than this:

// Bad - uses class as type!
ArrayList subscribers = new ArrayList();

If you get into the habit of using interfaces as types, your program wil be much more flexible. If
you decide that you want to switch implementations, al you have to do is change the class name
in the constructor.

For example, the first declaration could be changed to read:

List subscribers = new LinkedList();

and then all of the surrounding code would continue to work. The surrounding code was unaware
of the old implementation type, so it would be oblivious to the change.

1.2.3 The enum type
The ProspectiveStudent class uses the enum type for some of its fields. These fields (FeeType,
Gender, OfferStatus, QualificationsType) could have ben Strings, in which case anything could be
entered. Using the enum type alows us to restrict the user to only a few very specific entries that
are appropriate for the field. For example, Gender types wil only acept FEMALE, MALE and
OTHER. For more information se:
https:/docs.oracle.com/javase/tutorial/java/javaOO/enum.html
Page 5 of 10
Part A

Consider the clases that you have ben given. Curently the Admisions class wil not compile as
it tries to use methods in the AdmisionsFileManager class that do not exist, and a 10-argument
constructor for the ProspectiveStudent class that has not ben writen. Once you have successfuly
answered the questions below, the Admisions class should compile and run. You may test the
methods of the AdmisionsFileManager class by runing the class, since the class has a main
method with test statements. This wil also test that you have answered Question 1 correctly. Do
not change the main method, and also do not change any of the four test methods that the main
method runs.

1. The ProspectiveStudent class has one constructor that sets the fields of the
class to default values for testing purposes. It does not have a constructor
that alows the user to set the value of its fields. Write a second constructor
that wil alow the user to set every field (i.e. instance variable) of the clas. [6 marks]
2. In the AdmisionsFileManager class, the read() method is intended to return
an ArrayList, containing ProspectiveStudent objects
made from the data in the student_admissions_file.txt file.

The method reads in 10 lines at a time from the text file, then cals another
method, parseProspectiveStudent(ArayList) in order to parse those
10 lines to a ProspectiveStudent object. However, the
parseProspectiveStudent(ArayList) is not complete, so the read()
method does not work as intended.

Complete the parseProspectiveStudent(ArayList) so that the read()
method works as intended. [6 marks]
3. You are given the heading of the
write(ArayList, String) method.
Complete the method. In your answer make sure that the method does what
the coment written above the heading says it wil do. [6 marks]
4. You are given the heading of the
deserialize(String) method.
Complete the method. In your answer make sure that the method does what
the coment written above the heading says it wil do. [6 marks]
5. You are given the heading of the serialize(ArayList,
String) method. Complete the method. In your answer make sure that the
method does what the comment written above the heading says it wil do. [6 marks]
6. Write an apropriate constructor for the AdmisionsFileManager class. [6 marks]


Reading for part A
Note that in the list below, the ‘subject guide’ refers to Volume 2, and HFJ refers to Head
First Java.

• HFJ pages 240–49 (constructors)
• HFJ pages 301–06 (working with dates)
• Subject guide Chapter 2, Sections 2.2, 2.11 and HFJ pp.275–78 (static utility classes)
• Subject guide Chapter 3, Sections 3.2, 3.3, 3.5, 3.6 and HFJ pp.319–26; and 329–33
(handling exceptions)
Page 6 of 10
• Subject guide Chapter 5, Sections 5.3 and HFJ 447, 452–54 and 458–9 (files, parsing with
String.split(), streams including BuferedReader and BuferedWriter)
• Subject guide Chapter 6, Sections 6.2, 6.3, 6.4 and HFJ 429–38; 441–3 (serialization)


Deliverable for Part A
An electronic copy of your revised clases:

• AdmisionsFileManager.java
• ProspectiveStudent.java

Reminder:
Please put your name and student number as a coment at the top of your Java files.
Page 7 of 10
PART B

Testing the ClientGUI
You should compile and run the AnagramClientGUI.java file. To do this you wil first need to
compile and start AnagramServer.java. You can run both programs from the shel (cmd.exe) but
will ned to open the shell twice; once to get the AnagramServer started; and once to run the
AnagramClientGUI. Note that the AnagramClientGUI has been hard-coded to conect to a local
host.

When you start the AnagramClientGUI class you should see a simple GUI with a JButon, a
scrolable JTextArea and a JTextField. When you click on the 'Conect' buton, if you see the
mesage 'EROR: Conection refused: conect', and you have the AnagramServer class runing,
it may be that you ned to tell your firewall to allow Java through it. If this is the case you will have
to restart the AnagramServer and the AnagramClientGUI once you have adjusted your firewall.
Whenever you disconect from the AnagramClientGUI you wil have to restart the AnagramServer
from the shel (cmd.exe) as the server is single-threaded and dies once the client has
disconnected.

What you should se when you run the AnagramClientGUI is the following, on the JTextArea:

Welcome IP address '127.0.0.1' to the Anagram Server. Available
commands:
ANAGRAM show all anagrams of the word
PERMUTE show all permutations of the word
SHOW HELP show this help


The PERMUTE comand cals the permutation method, which wil make al posible permutations
of a word. A permutation is a rearrangement of all the objects in a collection. Suppose we have the
word MAT, al posible permutations are:

MAT
MTA
ATM
AMT
TAM
TMA

If you try the comand ‘permute mat’ on the GUI, you wil get five permutations, as the GUI wil not
count ‘mat’ as a permutation of itself.

Now supose our word is TAT, al posible permutations are:

TAT
TA
ATT
AT
TAT
TTA

In the above, the second ‘t’ is in bold. As far as theory is concerned, a 3 letter word has 6
permutations (incuding itself).

If you try ‘permute tat’ you wil only se att tta as output, as the system wil not return
duplicate permutations.
Page 8 of 10

An anagram is defined to be ‘a word, phrase, or name formed by rearranging the letters of
another’. In the system you have ben given, we are only considering words and names, not
phrases, as anagrams of a word.

Try ‘permutation mitre’ folowed by ‘anagram itre’. You may have to scrol acros to se al of the
permutations. You should find that from the list of unique permutations, the anagram command
returns only those that are words in their own right.

When testing the GUI you should note that the History clas alows you to use the arow keys to
retrieve your old comands to save typing.


Please complete the folowing tasks:

1. Explain why the Dictionary, PermutationFactory and AnagramFactory
classes al implement the Singleton design patern.

Give your answer by writing a coment at the top of each of the above thre
classes, identifying: (1) how the pattern is being implemented by the clas;
and (2) why the pattern is being implemented in that particular clas. [5 marks]
2. Anagrams and permutations are listed as one continuous line on the GUI,
such that the user ay have to scrol across to see them all. Can you alter
the system so that they are listed one to a line? For example, instead of
att tta output as the permutations of ‘tat’, the output would be:

att
tta

After you have implemented your change, the user may now have to scroll
down to see all permutations/anagrams.

Make sure to use platform. independent line separators, as described in
section 1.2.1 above. [2 marks]
3. On the machine used to test the GUI, loking for anagrams of the 10 leter
word ‘manchester’ tok 4 minutes and 15 seconds. Longer words were not
tested as they were expected to be even slower. Your system may be faster
or slower but you should still find that it takes minutes to find the anagrams
of a 10 character String.

It is posible to use a different Java data structure in one of the clases
Dictionary, PermutationFactory or AnagramFactory such that finding
anagrams is much faster. On the computer used to test the GUI, finding
anagrams of ‘manchester’ (or more exactly, finding that there are not any
anagrams of ‘manchester’) took 11 seconds after the improvement was
made.


Page 9 of 10
Make the improvement and, in a comment at the top of the class you have
made it in, explain why the data structure you have chosen is an
improvement in terms of sped over the original data structure. In a second
coment, quantify the improvement you have made in terms of time taken
to return anagrams of a particular word. You may use ‘manchester’, some
other 10 letter word, or a longer word as your test data.

The data structure used to make the improvement is one already defined by
Java, so you should be loking in the API for potential solutions. [5 marks]


Reading for Part B
• Chapter 7 of Volume 2 of the CO2220 subject guide, pages 63–66 (clients and servers).
• Head First Java pages 473–85 (clients and servers)
• https:/en.wikipedia.org/wiki/Singleton_pattern
• Head First Java pages 294–300 (formatting output)
• https:/docs.oracle.com/javase/7/docs/api/java/util/Formatter.html (documentation of the
Formatter class including lists of arguments for formatting output)
• The Java API


Deliverables for Part B

Please submit an electronic copy of the folowing:
• The .java file where you have implemented your answer to Question 2. (Note this should be
one of the files that you were given with the coursework assignment).
• AnagramFactory.java
• PermutationFactory.java
• Dictionary.java

Reminder:
Please put your name and student number as a coment at the top of your Java files.
Page 10 of 10
MARKS FOR CO220 COURSEWORK ASIGNMENT 2

The marks for each section of Coursework assignment 2 are clearly displayed against each
question and add up to 48. There are another two marks available for: giving in uncompressed
.java files; and giving in files that are not contained in a directory. This amounts to 50 marks
altogether. There are another 50 marks available from CO220 Coursework asignment 1.

Total marks for Part A [36 marks]
Total marks for Part B [12 marks]
Mark for giving in uncompresed files [1 mark]
Mark for giving in standalone files; namely, files not enclosed in a directory [1 mark]

Total marks for Coursework asignment 2 [50 marks]
[END OF COURSEWORK ASIGNMENT 2]
 

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

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