代写SENG2200 – Programming Languages & Paradigms Assignment 1代做Java编程

- 首页 >> C/C++编程

SENG2200 – Programming Languages & Paradigms

Assignment 1 (10%)

Due Date: 11:59 pm on 29 Mar (Week 5)

1 Objectives

This assignment aims to build the understanding of Java programming in topics of class, inheritance, interface and circular doubly-linked data structure. A successful outcome should be able  to demonstrate a solution of the assignment tasks with correct Java implementation and report.

2 Design Problem

You are to write a Java program for a Stock and Station Agent based in Denman, NSW. The program will be used to compare different land parcels for their value and how appropriate they are for particular types of agriculture as well as soil conservation and possible pasture improvement. The firm also hopes to cutdown the reliance on standard libraries throughout part of the design.

3  Design Specifications

The Java program built should contain the components and conform to the specifications stated from Sections 3.1 to 3.4.

3.1 Point Class

Design and write a Point class. The Point class simply has two double-precision floating point values for the x andy coordinate values. It has a method that will calculate the distance of the point from the origin. Your Point class should also contain a toString( ) method which will allow the conversion of a Point object into a String of the form. (x , y) – include the open and close parentheses and the comma in the String. Note that the toString() method (throughout this assignment) should return a string rather than print it out. The x and y values will appear in the string formatted according to the 4.2f specification. The string returned will be used for the output of your results.

Note:

You may use the Java Standard java.lang.Math library for sqrt().

3.2 Polygon Class

Design and write a Polygon class which contains a sequence of Point objects representing the ordered vertices of the polygon. Your Polygon class should contain a toString( )method which will allow the conversion of a Polygon object into a String of the form.

[point0 point1 ... pointn-2]: area

For the area values, the format to be used is 6.2f. This will be used as the output of your results. The Polygon class has a method that will calculate the area of a polygon using the Shoelace Formula given as:

You will also need a method to return the shortest distance between the origin and the vertex of the polygon. Lastly, Polygon will implement the ComparePoly interface specified in Section 3.3.

Note:

For a seven-sided figure, such as the one shown above, n = 8 because the last point describing the polygon is equal to the first, i.e., it is always the same Cartesian point. You may verify your polygon formula implementation using the link:http://omnicalculator.com/math/irregular-polygon-area.

3.3 ComparePoly Interface

You need to write and implement your own non-generic version of the Comparable interface, using the following:

public interface ComparePoly {

boolean ComesBefore(Object o); // true if this < param }

The ComparePoly interface has the Polygon comparison specification given as follows:

For any two polygons, if their area difference is within 0.1% of the smaller polygon, then they are assumed to have equal area. In these cases of equal areas, the polygon with the shortest vertex distance from the origin, takes precedence (comes first in your list Section 3.4).

3.4 MyPolygons Class (Data Structure)

You are required to implement a circular doubly-linked list data structure (covered in SENG1120) with the class name of MyPolygons, using a single sentinel node to mark the start/finish of what will become a container for Polygon objects. The MyPolygons class must provide distinct methods to:

.  prepend items into the start of the list (current item will be the new first in list),

.   append items into the end of the list (current item will be the new last in list),

.   insert before a specified (current) item,

.   step to the next item (making it the current item),

.   reset the current item variable to the start of your list, and,

.  take (then remove) an item from the head of the list.

Note:

.  All Linked-List structures to be used are to be designed and coded from scratch and may not use Generics or libraries.

.  While you will implement all these methods, you may not have to use all the above methods in this assignment.

3.5 Programming Language

Your program should be coded in Java. It is preferred to target the long term support version of Java currently installed on the University labs, i.e., Java 17.0 (LTS).

4 Test Case Generation

Upon completing the Java program, you will be generating test cases to make sure that your program is implemented correctly.

4.1 Input

All input (coming from standard input) of polygons will be from a user-defined text file. That is, your program should be able to read polygons from a text file. A sample test file is as follows (you should create one for self-testing before submission):

P 6 4 0 4 8 7 8 7 3 9 0 7 1

P 3 4.1 0.0 4.0 8.2 7.3 8.4

P 5 4.0 0 4 8.1 7.2 8 7 3 9 0

Note:

.  Polygons may be spread across multiple lines or there may be multiple Polygons per line.

.  You may use the Java Standard java.util.Scanner library (and associated) for input.

. Do not hard code your input paths! If you hard code these paths or put constraints on the path, the marker may not be able to properly mark your assignment.

4.2 Required Processing

.  Read polygon specifications (until end of file,from standard input) and place them into an instance of your container, in input order.

.  Parse and store each polygon specification. Referring to the input sample in Section 4.1, a polygon will be specified in the input  by the letter P, followed by the number of sides/vertices the polygon has (i.e., n- 1 from the formula in Section 3.2), and then pairs of numbers which represent the respective coordinates of each and every vertex on the Cartesian plane (x-value then y-value). You do not have to worry about any of the data being missing, or out of order. [Hint: store your polygon objects in an array containing all n-points, and explicitly include the last vertex as a copy of the first; this will allow the easiest implementation of the area formula.]

.   Then, you are to produce a second distinct list, which will contain a second copy the same set of Polygon objects, but this time, sorted in increasing area order. Implement an insert in order add method to sort the polygon objects as they are added to the list. Do not read the input a second time

– this is not just inelegant, but also a waste of time and resources.

.   Output for your assignment is a complete print of both your lists, i.e.,  the polygons in input order, and then the polygons in sorted order, listing the area of each polygon in each case, as per the Polygon specification of toString() given above.

4.3 Output

All output is to the standard output. A sample output of the input in Section 4.1 is as follows:


Unsorted list

[(4.00 , 0.00)(4.00  , 8.00)(7.00

,

8.00)(7.00 , 3.00)(9.00 , 0.00)(7.00 , 1.00)]: 24.50

[(4.10 , 0.00)(4.00  , 8.20)(7.30

,

8.40)]: 13.54

[(4.00 , 0.00)(4.00  , 8.10)(7.20

Sorted list

,

8.00)(7.00 , 3.00)(9.00 , 0.00)]: 27.66

[(4.10 , 0.00)(4.00  , 8.20)(7.30

,

8.40)]: 13.54

[(4.00 , 0.00)(4.00  , 8.00)(7.00

,

8.00)(7.00 , 3.00)(9.00 , 0.00)(7.00 , 1.00)]: 24.50

[(4.00 , 0.00)(4.00  , 8.10)(7.20

,

8.00)(7.00 , 3.00)(9.00 , 0.00)]: 27.66

Note:

Do not deviate from the output form! The output should be presented as above.

5  Submission of Deliverables

You are required to submit a zip file containing the executable code and report. The submission should be named according to the convention cXXXXXXX.zip, where cXXXXXXX is your student ID. If you submit more than once then only the latest will be graded.

5.1 Executable Code

Classes are to be implemented and submitted in separate files, i.e., do not save all your classes into one source file, or write classes within classes.

Name your start-up/entry-point class A1.java (capital-A number- 1). This allows the marker to compile your program with the command:

javac A1.java

and to run your program with the command:

java A1 test.dat

within a Command Prompt window.

Note:

. test.dat is a placeholder; your program will have to handle different names and extensions for testing.

.   If your program cannot be compiled and executed (incl. run-time errors) by using  the  above commands, marks will be deducted.

5.2 Report

In conjunction with your program, present a 2 to 3 page report which contains the following:

.   Introduction

.  Brief walkthrough of your code design and how specification are met.

.  Discussion of how Rectangles and Squares can be treated as special cases of this assignment using Inheritance (Lecture 3).

.   Conclusion

6 Marking Criteria

You will be graded according to the following marking criteria:

Program Correctness

. Point Class (including required methods) [10%]

. Polygon Class (including required methods) [15%]

. ComparePoly Interface [5%]

. MyPolygons Class

o Correct circular doubly-linked data structure [20%]

o Sorted Insertion [5%]

o Other methods (e.g., prepend and append) [15%]

.   Test Case Generation [10%]

Report [10%]

Miscellaneous

.   Code Format & Comments [10%]

Other Deductions

.  Errors with input, filenames, submission, execution, and mathematical results will attract penalties.

Note:

.  Assignments submitted after the deadline, without approved extension, will be penalized by 10% per day late (including weekend).

.   The assignment (code and report) will be checked for plagiarism. A plagiarized assignment will receive a zero score and be reported to SACO.

.  As per the Student Conduct Rule , any work submitted for assessment must be your own original work, and as such, the use of AI LLMs such as ChatGPT and other similar tools cannot be used in the writing or drafting of any work (which includes both code and report) submitted for assessment. By breaching this rule, you will be at risk of being reported to SACO and receive a zero score.





站长地图