基础的Java数据结构-it课程留学作业代写范文精选

英国it课程留学作业代写范文精选:“基础的Java数据结构”,这篇论文主要介绍了基础的Java数据结构。文章以建立公路旅行计划为例子,为读者讲解了如何利用Java来写出一个主菜单,并以此来操作单链表。

 

Reminders

 

1.Be sure your code follows the coding style for CSE214.

2.You are not allowed to use LinkedList, ArrayList, Vector or any other Java API Data Structure classes to implement this assignment except where noted.

3.You may use Scanner, InputStreamReader, or any other class that you wish for keyboard input.

 

Requirement

 

In this homework assignment you will be building a trip planner for road trips. You will be modelling a road trip as a linked list of stops, with each stop having a distance to travel, a location, and an activity. There are two itineraries (so that you can plan two trips, or make two versions of the same trip), and they should be completely independent (ie: modifying one should not cause the other to change). This means that a deep copy must be made each time the itinerary is copied from one itinerary to the other.

 

NOTE: All exceptions explicitly thrown in Required Classes except for IllegalArgumentException are custom exceptions that need to be made by you.

 

Required Classes

 

TripPlanner (Driver Class)

1.public static void main(String[] args)

2.Runs the User interface menu as shown in Required Functions

3.Can be changed as necessary for GUI/Android App

4.This method will contain two Itinerary objects for cloning.

 

Itinerary

1.private TripStopNode head

2.private TripStopNode tail

3.private TripStopNode cursor

 

The above variables will hold links into a doubly linked list of TripStopNodes where each node links to the previous and next ones, or nulls if there are none.

 

1.public Itinerary()

Constructor: initializes an empty itinerary with no elements – head, tail, and cursor are set to null.

2.public int getStopsCount()

Returns the total number of TripStopNodes in the Itinerary.

This method must run in O(1) time.

3.public int getTotalDistance()

Returns the sum of distances over all TripStopNodes.

This method must run in O(1) time.

4.public TripStop getCursorStop()

Returns a reference to the TripStop wrapped by the TripStopNode that cursor points to.

If cursor is null, this returns null.

5.public void resetCursorToHead()

Returns the cursor to the start of the list.

Postconditions:

If head is not null, the cursor now references the first TripStopNode in this list.

If head is null, the cursor is set to null as well (there are no TripStop objects in this list).

6.public void cursorForward()

Moves the cursor to select the next TripStopNode in this list. If cursor == tail, throw an exception.

Throws:

EndOfItineraryException - Thrown if cursor is at the tail of the list.

7.public void cursorBackward()

Moves the cursor to select the previous TripStopNode in this list. If cursor == head, throw an exception (this includes the case where cursor and head are both null).

Throws:

EndOfItineraryException- Thrown if cursor is at the head of the list.

8.public void insertBeforeCursor(TripStop newStop)

Inserts the indicated TripStop before the cursor.

Parameters:

newStop

The TripStop object to be wrapped and inserted into the list before the cursor.

Preconditions:

newStop is not null.

Postconditions:

newStop has been wrapped in a new TripStopNode object

If cursor was previously not null, the newly created TripStopNode has been inserted into the list before the cursor.

If cursor was previously null, the newly created TripStopNode has been set as the new head of the list (as well as the tail).

The cursor now references the newly created TripStopNode .

Throws:

IllegalArgumentException

Thrown if newStop is null.

Warning

You should NOT move data references around between TripStopNodes to accomplish this method. Instead, you should wrap the TripStop object in a new TripStopNode object, and insert this object into the list before the cursor.

9.public void appendToTail(TripStop newStop)

Inserts the indicated TripStop after the tail of the list.

Parameters:

newStop

The TripStop object to be wrapped and inserted into the list after the tail of the list.

Preconditions:

newStop is not null.

Postconditions:

newStop has been wrapped in a new TripStopNode object

If tail was previously not null, the newly created TripStopNode has been inserted into the list after the tail.

If tail was previously null, the newly created TripStopNode has been set as the new head of the list (as well as the tail).

The tail now references the newly created TripStopNode.

Throws:

IllegalArgumentException

Thrown if newStop is null.

Note:

This insertion method does not affect the cursor, unless the list was previously empty. In that case, head, tail, and cursor should all reference the new TripStopNode.

10.public TripStop removeCursor()

Removes the TripStopNode referenced by cursor and returns the TripStop inside.

Preconditions

cursor != null

Postconditons

The TripStopNode referenced by cursor has been removed from the list.

All other TripStopNodes in the list exist in the same order as before.

The cursor now references the previous TripStopNode

Exceptions: If the cursor was originally the head, the cursor will now reference the current head.

Returns

The TripStop that was removed

Throws

EndOfListException if cursor is null.

 

TripStopNode

1.private TripStop data

2.private TripStopNode next

3.private TripStopNode prev

4.public TripStopNode(TripStop initData)

Default constructor.

Parameters:

initData - The data to be wrapped by this TripStopNode. This parameter should not be null, since we should never have a TripStopNode with null data (remember, this class serves only as a wrapper for the TripStop class).

Preconditions:

initData is not null.

Postconditions:

This TripStopNode has been initialized to wrap the indicated TripStop, and prev and next have been set to null.

Throws:

IllegalArgumentException

Thrown if initData is null.

5.public TripStop getData()

Returns the reference to the data member variable of the list node.

6.public void setData(TripStop newData)

Sets the data private field to the one passed as a parameter.

Parameters:

newData - Reference to a new TripStop object to update the data member variable. This parameter must not be null, since we should never have a TripStopNode with null data (remember, this class serves only as a wrapper for the TripStop class).

Preconditions:

newData is not null.

Throws:

IllegalArgumentException - Thrown if newData is null.

7.public TripStopNode getNext()

Returns the reference to the next member variable of the list node. Can be null, means there’s no next TripStopNode.

8.public void setNext(TripStopNode newNext)

Updates the next member variable with a new TripStopNode reference.

Parameters:

newNext - Reference to a new TripStopNode object to update the next member variable. This parameter may be null, since it is okay to have no next TripStopNode (this means we’ve reached the tail of the list!).

9.public TripStopNode getPrev()

Gets the reference to the prev member variable of the list node.

Returns:

The reference of the prev member variable. Note that this return value can be null, meaning that there is no previous TripStopNode in the list. (this means we’ve reached the head of the list!).

10.public void setPrev(TripStopNode newPrev)

Updates the prev member variable with a new TripStopNode reference.

Parameters:

newPrev - Reference to a new TripStopNode object to update the prev member variable. This parameter may be null, since it is okay to have no previousTripStopNode (this means we’ve reached the head of the list!).

 

TripStop

 

This class contains private data fields for Location (String), Distance (int), and Activity (String). This class is mutable, so there are getters and setters for all private data fields.

 

If distance is less than 0, throw an IllegalArgumentException

While you must have a default constructor, you are encouraged to make an overloaded constructor taking all 3 fields as parameters (this is not required).

 

General Recommendations

 

You might want to implement a toString() method for TripStop, TripStopNode, and Itinerary to make debugging and printing easier. You do not have to do this, but it will help you.

 

You can feel free to add extra private methods if you need, but if you want to add a public method, check on the discussion board first.

 

UI Required Functions

 

The menu should have options similar to these, and NOT be case sensitive.

 

F-Cursor forward

B-Cursor backward

I-Insert before cursor

Secondary menu asking for Location, Distance, Activity (in that order)

A-Append to tail

Secondary menu asking for Location, Distance, Activity (in that order)

D-Delete and move cursor forward

H-Cursor to Head

T-Cursor to Tail

E-Edit cursor

Secondary menu asking for edits to Location, Distance, Activity (in that order, see sample)

S-Switch itinerary

O-Insert cursor from other itinerary before cursor from this itinerary (via cloning)

R-Replace this itinerary with a copy of the other itinerary

P-Print current itinerary, including summary (see sample)

C-Clear current itinerary

Q-Quit

 

Output Format

 

All lists must be printed in a nice and tabular form as shown in the sample output. You may use Java style formatting as shown in the following example. The example below shows two different ways of displaying the name and address at pre-specified positions 21, 26, 19, and 6 spaces wide. If the ‘-’ flag is given, then it will be left-justified (padding will be on the right), else the region is right-justified. The ‘s’ identifier is for strings, the ‘d’ identifier is for integers. Giving the additional ‘0’ flag pads an integer with additional zeroes in front. See here for more details.

 

1
 
2
 
3
 
4
 
5
 
6
 
7

String name = "Doe Jane";
 
String address   = "32   Bayview Dr.";
 
String city = "Fishers Island,   NY";
 
int zip = 6390;
 
 
System.out.println(String.format("%-21s%-26s%19s%06d", name, address, city, zip));
 
System.out.printf("%-21s%-26s%19s%06d", name, address, city,   zip);

想要了解更多留学作业代写或者需要留学文书辅导,请关注51Due英国论文代写平台,51Due是一家专业的论文代写机构,专业辅导海外留学生的英文论文写作,主要业务有英文report 代写 、argument essay代写、paper代写、assignment代写。在这里,51Due致力于为留学生朋友提供高效优质的留学教育辅导服务,为广大留学生提升写作水平,帮助他们达成学业目标。如果您有毕业论文代写需求,可以咨询我们的客服。