辅导开发fortravelmaps、讲解Java编程、Java程序辅导讲解、辅导Java设计留学生

- 首页 >> Java编程

Assignment 2

The due date:11:00pm,Monday,1st of October 2018.

1 Objective

The goal of the next two assignments is to develop an editing and simulation

environment fortravelmaps.This assignmentis thefirst of two parts.At this stage,

you are asked to develop a basic infrastructure for reading, writing, and representing

a map as well as some facilities you will need to simulate travel in the map.Specifically,

you need to create a Java class to store place sand route sofa travel network.Later,

this should allow a trip to be simulated.In addition,you need to write a class that can

read/write a map from/to a text file. The external behaviour is prescribed by interfaces

we provide.

Althougheachpart isof equal value, the qualityof your submission forthis partwill

significantly affect your marks in the subsequent practical.

2 Java Files Provided

We provide the following java files for you.

Map.java contains an interface specification for a class thatrepresents a map.

Place.java contains an interface specification for a class thatrepresents a

place.

Road.java contain san interface specification for a class that represents a road.

MapIo.java contains an interface specification for a class that supports

reading and writing of a map from a text file.

MapFormatException.javaspecifiesanexceptionthatisthrownwhenanerror

is detected while reading a map file.

PlaceListener.java containsaninterface whichisusedtonotify listenerswhen

a change has been made to a place.

RoadListener.java contains aninterface which is used to notify listeners when

a change has been made to a road.

MapListener.java contains an interface which is used to notify listeners when

a change has been made to the map.

3 Specification

You must write two java classes:

MapImpl.java that implements the Map interface and contains a default

constructor: MapImpl();

? MapReaderWriter.java that implements the MapIo interface and contains a

default constructor MapReaderWriter().

We suggest you the following order for building the required code.

1. Buildthebasic codeforMapImpl.Thecompilerwill insist that youprovideall

the methods from the Map interface. You can keep the compiler happy by

arranging that each method’s body does something trivial, but correct. For

example, make Boolean methods return false, and methods that return an object

returnnull.Whenyouhavecompletedthis,yourMapImplclassshouldcompile

withouterrors.Next,startbuildingthebodiesoftheMapImplmethods,oneata

time.

2. If you need additional classes (for example, to implement a place), you can use

the same dummy-body technique that was used with map to allowthe class to

compile, even though its methods are not yet complete.

3. Test the methods as you build them, and only move on when you know the

code is correct. You will end up making your tester program bigger and bigger, as

development proceeds.

4. To simplify things, do not bother to implement the addListener and

deleteListener methods in any of the classes until we cover the concept of

listeners;theycanbedonelater.Theamountofcoderequiredisquitesmalland

is easy todebug.

5. Keep working on MapImpl until it is complete.

6. Now, write the code for MapReaderWriter. You will find that the write method

ismuchsimplerthanread,sodoitfirst.Onceyouknowitworks,youcanuseitto

help you to debug the code for reading a map.

7. You now have most of the code working. And, if yourtesting has been thorough,

it should becorrect.

8. Finally,addcodefortheaddListeneranddeleteListenermethodsintheclasses.

Arrange to call the listeners whenever a change occurs in the class. For example,

when a new place is added to the map, you must call the placesChanged() method

of anyof the registered listeners.You’llneed toextend yourtesterto verify that

this code worksproperly.

4 Map file format

Thefiledescribingamapis aseriesofrecords structuredas linesof text.Thereare

five differenttypes of lines to specifyplaces,roads, startingandendingpoints fora

trip, and comments. The parts of each line are separated by one or more space

characters.

Place record: place placeName xpos ypos

place is the character string “place” (all lower case).

placeName is the name of the place, a string of characters beginning with a letter

followed by zero or moreletter, digit, or underscore characters.(This is essentially

the definition of identifier in Java.)

xposandyposareintegervaluesthatgivethex-andy-positionoftheplaceon

thecomputer’sdisplayscreen.Althoughyou willnotneedthesevalues forthis

stage of the project, you must store and reproduce them correctly.

Road record: road firstPlace roadName length secondPlace

road stands for the character string “road” (all lower case);

firstPlace is the name of the place at one end of the road;

secondPlace is the name of the place at the other end of the road;

roadNameisthenameoftheroad.AroadNameischaracterstringthatstarts

with a letterfollowed by letters or digits. The special roadName “-” means that

the road does not have a name.

lengthisthelengthoftheroad,inkilometres.Notethataroadissymmetric–it

is possible to travel from a to b, and from b to a.

Start record: start placeName

start stands for the character string “start” (all lower case);

placeName specifies the starting place for a trip on the map.

End record: endplaceName

end stands for the character string “end” (all lower case);

placeName specifies the ending place for a trip on the map.

Comment record: A line that begins with the character “#” is a comment, therefore is

ignored by thesystem.

Blank record: A line containing no data is ignored by the system.

Records can appearin any orderin the file subject to one restriction: a place name

must already have been previously defined via a place record before its name can be

usedinaroad, start,orendrecord.Whenwritingafile,itis conventionaltowritethe

records in canonical order, that is: places, then roads, then start, then end. File

exampleMap.map is provided for testing purpose and contains an instance of a map.

5 Submission instructions for programming code

First, type the following command, all on one line (replacing aXXXXXXX with your

username):

svn mkdir --parents -m "EDC"

https://version-control.adelaide.edu.au/svn/aXXXXXXX/2018/s2/edc/assignment2

Then, check out this directory and add your files:

svn co https://versioncontrol.adelaide.edu.au/svn/aXXXXXXX/2018/s2/edc/assignment2


cd assignment2

svn add MapImpl.java

svn add MapReaderWriter.java

svn commit -m "assignment2 solution"

Next, go to the web submission system at:

https://cs.adelaide.edu.au/services/websubmission/

Navigateto2018,Semester 2,Adelaide,EventDrivenComputing, thenAssignment 2.

ClickMakeaNewSubmissionforThisAssignmentandindicatethatyouagreetothe

declaration. The script will then check whether your code compiles. You can make as

many resubmissions as you like.


站长地图