1. Homepage
  2. Programming
  3. COMP1721 Object-Oriented Programming Coursework 1: Creating & Using Classes

COMP1721 Object-Oriented Programming Coursework 1: Creating & Using Classes

Engage in a Conversation
LeedsCOMP1721Object-Oriented ProgrammingJavaClassesUML

COMP1721 Object-Oriented Programming Coursework 1: Creating & Using Classes CourseNana.COM

1 Introduction CourseNana.COM

This assignment assesses your ability to implement classes and use them in a small program. CourseNana.COM

Consider the GPS data generated by a device such as a mobile phone. Your current location is represented as a point, consisting of a timestamp, a longitude (in degrees), a latitude (in degrees) and an elevation above sea level (in metres). Movement while GPS is enabled generates a track: a sequence of points representing successive samples from the GPS sensor. CourseNana.COM

Your main task is to implement classes named Point and Trackthat can be used to represent points and tracks, along with a small program that demonstrates the use of these classes. Figure 1 is a UML class diagram showing the required features of, and relationship between, the two classes. CourseNana.COM

Figure 1: Classes used in Coursework 1 CourseNana.COM

2 Preparation 2.1 Files Needed CourseNana.COM

Download cwk1files.zip from Minerva and unzip it. The best way of doing this on a SoC Linux machine is in a terminal window, via the command CourseNana.COM

unzip cwk1files.zip
This will give you a directory named cwk1, containing all of the files you need. CourseNana.COM

Remove the Zip archive, then study the files in cwk1. In particular, examine the file README.,mads this provides guidance on how to run the tests on which your mark will be largely based. CourseNana.COM

Note: all code should be written in the .java files provided in the src/main/javasubdirectory. 2.2 Method Stubs CourseNana.COM

A suite of unit tests is provided with the files for this coursework. These tests are used to verify that the methods of the two classes have been implemented correctly. You will be awarded one mark for each test that passes. The starting point for the coursework is to make sure that the tests compile and runT. his means that it is necessary to begin by creating method stubs: dummy versions of each method that do just enough that the tests will compile successfully. CourseNana.COM

Refer to Figure 1 for details of the stubs that are required, and note the following:
• All stubs should have the parameter lists and return types shown in the UML diagram • Constructors should be implemented as empty methods (nothing inside the braces)
• Any method that returns a numeric value should just return a value of zero
• Any method that returns an object should just return the value
null CourseNana.COM

Note also that thePoint class references a class from the Java standard library namedZonedDateTim. Tehis is part of Java’s standard Date/Time API, defined in the package java.time—see the API documentation for further details. To use it, you will need to add animportstatement to the start of Point.java: CourseNana.COM

import java.time.ZonedDateTime; CourseNana.COM

When you have created stubs for all the methods shown in Figure 1, you can attempt to compile and run the tests using Gradle. See README.mfodr full details of how Gradle can be used.We simply note here that you can run the tests from a Linux or macOS command line with CourseNana.COM

./gradlew test
Omitthe./ fromthestartofthiscommandifyouareworkingfromtheWindowscommandprompt,oruse CourseNana.COM

.\gradlew.bat to invoke Gradle if you are using Windows Powershell. 3 Basic Solution CourseNana.COM

This is worth 18 marks. CourseNana.COM

Pleasereadallofthesubsectionsbelowbeforestartingwork. Wealsorecommendthatyougainsome experience of implementing classes by doing the relevant formative exercises before you start. CourseNana.COM

3.1 PointClass
To complete the implementation of thePoint class, make the following changes toPoint.java: CourseNana.COM

  • Add a field to represent the timestamp, of type ZonedDateTim(see below). CourseNana.COM

  • Add fields to represent longitude, latitude and elevation, all of typedouble. CourseNana.COM

  • Add code to the constructor that initialises the fields to the values supplied as method parameters, with validation done for longitude and latitude (see below). CourseNana.COM

  • Modify the ‘getter’ methods (getTime(,)getLongitude(,)etc) so that they return the relevant field values, instead of the defaults like 0 ornull that were returned by the stubs. CourseNana.COM

  • Change toString() so that it returns a string representation of a Point looking like this: (-1.54853, 53.80462), 72.5 m CourseNana.COM

    (The values here are longitude, then latitude, then elevation. The string should be formatted exactly as shown here. Note the specific number of decimal places being used for each number!) CourseNana.COM

Make sure that it is not possible to create a Point object with an invalid latitude or longitude. Use the constants provided in the class to help you with this, and throw an instance of the provided exception class, GPSExceptio,nif inappropriate coordinates are supplied. CourseNana.COM

As you replace each method stub with its correct implementation, rerun the tests.You should see a growing number of tests changing in status from FAILED to PASSED. CourseNana.COM

3.2 TrackClass
For the basic solution, make the following changes toTrack.java: CourseNana.COM

  • Add a field suitable for storing a sequence ofPoint objects. CourseNana.COM

  • Modify the constructor that take a string as its parameter, so that it initialises the field used to store CourseNana.COM

    the Point objects and then calls the readFile() method. CourseNana.COM

  • Add to readFile() some code that will read data from the file with the given filename, createPoint CourseNana.COM

    objects from this data and then store those Point objects as a sequence (see below). CourseNana.COM

  • Modify the size() method so that it returns the number of points currently stored in the track. CourseNana.COM

  • Modift the get() method so that it returns thePoint object stored at a given position in the sequence. Position is specified as an int parameter and should be validated (see below). CourseNana.COM

  • Modify the add()method so that it adds a new point, supplied as a method parameter, to the end of the track. CourseNana.COM

The readFile() method will need to read CSV files, examples of which can be found in thde atadirectory. It should use a Scannerto do this. A good approach here would be to read the file line-by-line, split up the line on commas, then parse each item separately.The lectures discuss how a file can be read in this manner. You can use the static method parse() of the ZonedDateTimcleass to parse the timestamp. CourseNana.COM

readFile() should NOT catch any exceptions that might occur during reading of the file. It will need an exception specification, declaring that anIOExceptioncould happen if the named file cannot be accessed. Your implementation should also explicitly throw a GPSExceptionif any record within the file doesn’t contain the exact number of values needed to create a Point object. Note that you do not need to include GPSExceptionaspartofthemethod’sexceptionspecification, becausethisexceptionclassisnotoneof Java’s ‘checked exception’ types. CourseNana.COM

The get() method should use the int value passed to it as an index into the sequence ofPoint objects, but before doing that the method should check this int value and throw an instance of GPSExceptioinf it is not within the allowed range. Once again, note that there is no need to include an exception specification for this. CourseNana.COM

As you replace each method stub with its correct implementation, rerun the tests.You should see a growing number of tests changing in status from FAILED to PASSED. CourseNana.COM

4 Full Solution CourseNana.COM

This is worth a further 12 marks. It involves completing the implementation of the Trackclass and then writing a small program that uses the two classes. CourseNana.COM

4.1 TrackClass
If you’ve completed the basic solution, there should be four remaining method stubs inTrack.java, which CourseNana.COM

should be modified as indicated below. CourseNana.COM

  • Modify lowestPoint() and highestPoint() so that they return thePoint objects having the lowest and highest elevations, respectively. CourseNana.COM

  • Modify totalDistance() so that it returns the total distance travelled in metres when moving from point to point along the entire length of the track (see below). CourseNana.COM

  • Modify averageSpeed(s)o that it returns the average speed along the track, in metres per second (see below) CourseNana.COM

    All four of these methods should throw aGPSExceptioinf the track doesn’t contain enough points to do the necessary computation. CourseNana.COM

    To implementtotalDistance(), you will need to compute ‘great-circle distance’ between adjacent points on the track. A method to do this already exists in the Point class. Given two Point objects, p and q, the great-circle distance in metres between them (ignoring elevation) will be given by CourseNana.COM

    double distance = Point.greatCircleDistance(p, q); CourseNana.COM

    To implement averageSpeed(y)ou will need to compute the amount of time that has passed between measurements for the first and last points on the trackY. ou can use theChronoUnitype for this: specifically, the between()method, which can be called on the object ChronoUnit.SECONtDo Syield the time interval in seconds between two ZonedDateTimobejects. CourseNana.COM

    Note: the ChronoUnitclass is part of Java’s standard Date/Time API. To use it, you will need to add an importstatement to Track.java: CourseNana.COM

    import java.time.temporal.ChronoUnit; CourseNana.COM

    As you replace each method stub with its correct implementation, rerun the tests. Your goal here is to end up with all 26 tests passing. If you achieve this, you can be assured of getting at least 26 marks for the coursework. CourseNana.COM

    4.2 TrackInfoProgram CourseNana.COM

    Edit the file TrackInfo.java. In this file, create a small program that creates a Trackobject from data in a file whose name is provided as a command line argument. You program should display: the number of points in the track; its lowest and highest points; the total distance travelled; and the average speed. CourseNana.COM

Requiring the filename as a command line argument means that it has to be supplied as part of the command that runs the program; the program should not be prompting for input of the filename once it has started running! CourseNana.COM

For example, if running the program directly within a terminal window, you would need to enter CourseNana.COM

java TrackInfo walk.csv CourseNana.COM

Note that you can run the program with a suitable command line argument via Gradle: CourseNana.COM

./gradlew run
This will run the program on the file data/walk.csv. CourseNana.COM

You can also check whether your program behaves correctly when no filename has been supplied on the command line, by doing CourseNana.COM

./gradlew runNoFile
When your program is run on walk.csv, it should generate output very similar to this: CourseNana.COM

194 points in track
Lowest point is (-1.53637, 53.79680), 35.0 m Highest point is (-1.54835, 53.80438), 73.6 m Total distance = 1.904 km
Average speed = 1.441 m/s
CourseNana.COM

Your output doesn’t need to be identical in layout, but it should provide all the data shown here, and numbers should be formatted with the number of decimal places shown in this example. CourseNana.COM

If no filename is supplied on the command line, your program should print a helpful error message and then use System.exit()to terminate, with a value of zero for exit status. CourseNana.COM

The program should intercept any exceptions that occur when reading from the file or performing computa- tion. The program should print the error message associated with the exception and then use System.exit() to terminate, with a non-zero value for exit status. CourseNana.COM

5 Advanced Tasks CourseNana.COM

For a few extra marks, implement ONE of two options suggested below. CourseNana.COM

Thesetasksaremorechallengingandwillrequireadditionalreading/research. Theyarealsoworth relatively few marks. Attempt them only if you manage to complete the previous work fairly quickly and easily. CourseNana.COM

5.1 Option 1: KML Files CourseNana.COM

This is worth an additional 2 marks. CourseNana.COM

  1. Add to theTrackclass a new method namedwriteKM.LThis should have a singleString parameter, representing a filename. It should write track data to the given file, using Google’s Keyhole Markup Language format. CourseNana.COM

  2. Edit ConvertToKML.javaand add to it a program that converts a CSV file of track data into a KML file. The program should expect filenames for these two files as command line arguments, with the CSV file as the first argument and the KML file as the second argument. It should deal with missing arguments and exceptions in the same way asTrackInfo. CourseNana.COM

  3. Generate a KML file for the track represented bywalk.csv. You can do this with Gradle, using ./gradlew runKML CourseNana.COM

    This will generate its output in a file walk.km,lin the build subdirectory. CourseNana.COM

    Visualise the file by uploading it to Google Maps (see Figure 2) or by importing it into Google Earth. Grab a screenshot of the result and place it in the cwk1directory so that it will be included in your submission. CourseNana.COM

5.2 Option 2: Elevation Plot CourseNana.COM

This is worth an additional 4 marks. CourseNana.COM

  1. Investigate JavaFX by reading David Eck’s online Java Notes and other online sources.In particular, you will need to research how charts can be drawn in JavaFX. CourseNana.COM

  2. Edit build.gradle and uncomment the various commented-out parts relating to JavaFX. CourseNana.COM

  3. Edit the file PlotApplication.java and implement in this file a JavaFX application that plots elevation as a function of distance along a track. As with TrackInfo, the file of track data should be specified as a command line argument. CourseNana.COM

    You can run your application onwalk.csvvia Gradle, with this command: ./gradlew runPlot CourseNana.COM

    Figure 3 shows an example of what the plot could look like. CourseNana.COM

6 Submission CourseNana.COM

Use Gradle to generate a Zip archive containing all the files that need to be submitted: CourseNana.COM

./gradlew submission
This produces a file named cwk1.zip. Submit this file to Minerva, via link provided for this purpose. You CourseNana.COM

can find this link in the ‘Assessment and Feedback’ section, under ‘Submit My Work’. CourseNana.COM

Note: be careful to submit the correct Zip archive here! Make sure you do not accidentally submit the Zip archive of provided files . . . CourseNana.COM

The deadline for submissions is 14.00 Wednesday 6th March 2024. The standard university penalty of 5% ofavailablemarksperdaywillapplytolatework, unlessanextensionhasbeenarrangedduetogenuine extenuating circumstances. CourseNana.COM

Note that all submissions will be subject to automated plagiarism checking. 7 Marking CourseNana.COM

40 marks are available for this assignment.
A basic solution can earn up to 24 marks (60% of those available); a full solution can earn up to 36 marks
CourseNana.COM

(90% of those available). CourseNana.COM

Mark allocation breaks down as follows: CourseNana.COM

18 Tests for basic solution 8 Tests for full solution 4 TrackInfo program
4 Advanced task
CourseNana.COM

6 Sensible use of Java and coding style CourseNana.COM

40 CourseNana.COM

CourseNana.COM

Figure 2: A track rendered by Google Maps CourseNana.COM

Figure 3: Elevation plot produced using Java FX CourseNana.COM

Get in Touch with Our Experts

WeChat WeChat
Whatsapp WhatsApp
Leeds代写,COMP1721代写,Object-Oriented Programming代写,Java代写,Classes代写,UML代写,Leeds代编,COMP1721代编,Object-Oriented Programming代编,Java代编,Classes代编,UML代编,Leeds代考,COMP1721代考,Object-Oriented Programming代考,Java代考,Classes代考,UML代考,Leedshelp,COMP1721help,Object-Oriented Programminghelp,Javahelp,Classeshelp,UMLhelp,Leeds作业代写,COMP1721作业代写,Object-Oriented Programming作业代写,Java作业代写,Classes作业代写,UML作业代写,Leeds编程代写,COMP1721编程代写,Object-Oriented Programming编程代写,Java编程代写,Classes编程代写,UML编程代写,Leedsprogramming help,COMP1721programming help,Object-Oriented Programmingprogramming help,Javaprogramming help,Classesprogramming help,UMLprogramming help,Leedsassignment help,COMP1721assignment help,Object-Oriented Programmingassignment help,Javaassignment help,Classesassignment help,UMLassignment help,Leedssolution,COMP1721solution,Object-Oriented Programmingsolution,Javasolution,Classessolution,UMLsolution,