联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp

您当前位置:首页 >> Java编程Java编程

日期:2019-04-17 10:28

SE-555 A4: GPS Position Observer

In this assignment, you will implement the Observer pattern in a multi-threaded

application that receives notifications of position updates from a (simulated) GPS

device.

Assignment Overview

When you start your application, it should prompt the user for the name of a file

containing GPS data (see the Resources section below for sample files). After the

prompt, your application must create some Observers that attach to the GPS

data server - the Subject. The specific function of the Observers - and the format

of the data they display - will be specified by your instructor. In any case, when

the Observers attach to the GPS data server, they change their displays

whenever the Subject performs an update().

In the observers illustrated above, the latitude/longitude and elevation

Observers are capable of subscribing and de-subscribing from the Subject via

the button UI. The plotter Observer attaches to the Subject on startup in this

example, but you may add the ability to subscribe and de-subscribe if you wish.

Assignment Details

The following class diagram illustrates the classes and interfaces that implement

this application. Consider it as a general guideline for the structure of the

application. You may depart from it in the details of the implementation of the

concrete observer classes and GPSCoordinate class, but you must define and

implement the Subject and Observer interfaces shown. If you feel you

need to make major changes to this design, consult your instructor first.

As a Subject, your implementation of GPSServer must be capable of accepting

subscriptions from multiple Observers.

The following sequence diagram illustrates the GPSClient creating a GPSServer

(the Subject) and three Observers: ElevationObserver, PositionObserver, and

PositionPlotter. After creating GPSServer, the GPSClient starts the GPServer.

Internally, the GPSServer starts a secondary thread that periodically generates

GPS data (simulated by reading it from a specified file). At the beginning, the

PositionPlotter observer immediately subscribes to the GPSServer. At some later

point, the user of the GPSClient application directs (via GUI interaction) the

ElevationObserver and PositionObserver to subscribe (attach) to the GPSServer.

Subsequent GPS data that is generated is propagated back to all subscribed

Observers when the GPSServer internally calls notifyObservers(), which in turn

iterates through the collection of Observers, calling each Observers's update()

method (on the secondary thread). In response, each Observer updates it's

current specific display of GPS data. Because UI updates cannot be invoked

on any thread except the UI thread, the Observers have to use the

SwingUtilities.invokeLater() method to invoke Swing methods.

You may also want to browse through the javadoc (javadoc.zip click on

index.html) corresponding to the methods in the classes above.

Files and resources

The GPS data files and GPSCoordinate.java can be downloaded from canvas (A4

folder).

To read data from the file, you might want to use some of the following code:

doubleReader = new Scanner(gpsFile);

// one or more occurrences of commas, semicolons or whitespace

doubleReader.useDelimiter("[,;\\s]+");

while( doubleReader.hasNextDouble() ) {// read each double

recordNo++;

Thread.sleep( DELAY ); //simulate delays between generation of coordinates

double longitude = doubleReader.nextDouble();

double latitude = doubleReader.nextDouble();

double elev = doubleReader.nextDouble();

GPSCoordinate c = new GPSCoordinate(longitude, latitude, elev );

System.out.printf("%4d Lat: %10.6f, Long: %10.6f, El: %8.3f\n", recordNo, latitude,

longitude, elev );

}

Submission (DUE Thursday 5 pm)

(Note that you do NOT need to actually plot the positions --- a simple

print message with coordinates values is enough)

In addition to code, you are also required to create (using Enterprise Architect),

a reverse-engineered UML Class diagram of your individual solution. Save the

class diagram in a .pdf file and include it in your submission along with your

.java files.

When submitting your work, submit one zip folder per group containing ONLY:

the “src” folder of your eclipse project, and the .pdf file on your reverseengineered

UML class diagram.


版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp