Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program Description You will be writing a program to track the outcome of a competition or sporting event where individuals or teams receive a score

Program Description

You will be writing a program to track the outcome of a competition or sporting event where individuals or teams receive a score and the winner is the highest score. For example, a pair of figure skaters receive a score for their performance and the pair with the highest score wins. Start by choosing the sporting event you will track and then implement the classes listed below.

Contestant class

Your contestant class must have the following characteristics:

  • A meaningful name (i.e. not Contestant)

  • At least 3 fields such that

    • one field must be id and be of type int.

    • one field must be name and be of type String. This will be your search key.

    • one field must be score and be of type float or double.

    • all fields must be private.

  • Implement a setter for score.

  • Implement getters for id, name, and score.

  • Implement toString() which returns a one line string with all the instance variables.

  • Implement an equals() method which returns true when the search key is the same regardless of case and the ids are the same.

  • Implement the Comparable interface. compareTo() returns

    • a negative number when the invoking objects score is less than the arguments score.

    • 0 when the invoking objects score is the same as the arguments score.

    • a positive number when the invoking objects score is greater than the arguments score.

  • Implement a constructor which has as its arguments the value for the id, the name, and the score.

Collection class

  • Implement a collection class of your Contestant using an array. You may not use any classes from the

Collection package.

  • The name of your collection class should make sense based on the type of your contestant.

  • Implement a constructor with no arguments which sets a default initial size for the underlying array.

  • Implement a constructor with one argument which represents the initial size of the underlying array.

  • Implement an insert() method which takes as an argument an instance of your Contestant class and inserts it into the underlying array in DESCENDING order according to the score. If the array is full, create a new larger array, copy the values from the old array to the new array, delete the old array, and then insert the new object.

  • Implement a size() method which returns an integer representing the number of items in the collection.

  • Implement a toString() method which returns a string representation of all the items in the collection. It should be formatted as a table with a header row and one item per line.

  • Implement a find() method which takes as an argument a string and returns the first object in the collection that has a search key which matches.

  • Implement a countOccurences() method which takes as an argument an instance of your Contestant

class and returns the number of objects in the collection which match.

  • Implement a countRange() method which takes two arguments representing a range of scores of the same type as your score field. It should return the number of objects in your class which fall within the range including the values at the end of the range. If the first argument is greater than the second parameter return 0.

  • Implement a delete() method which takes an instance of your Contestant class, removes the matching instance if it exists. It should return the deleted object if found, null if not found. The order of the collection should be maintained after the delete.

  • Write an iterator for your collection.

Runner class

Implement a runner class which includes a test program to:

  • Create a collection class with default value of 5

  • Use insert() to insert 6-10 items into your collection.

  • The runner class tests all methods on the collection class.

  • Do not use Scanner to read inputs from the user. Hard code all values.

Other requirements

  • Draw a UML class and structure diagram which shows the relationship among the classes in your solution. It must be submitted as an image file (e.g. jpg, png).

  • Use Javadoc style comments for ALL public methods and constructors in your Contestant and

Collection classes.

  • Use good coding style and formatting throughout. Note that Eclipse has a feature to automatically format your code. Use this.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Current Trends In Database Technology Edbt 2006 Edbt 2006 Workshops Phd Datax Iidb Iiha Icsnw Qlqp Pim Parma And Reactivity On The Web Munich Germany March 2006 Revised Selected Papers Lncs 4254

Authors: Torsten Grust ,Hagen Hopfner ,Arantza Illarramendi ,Stefan Jablonski ,Marco Mesiti ,Sascha Muller ,Paula-Lavinia Patranjan ,Kai-Uwe Sattler ,Myra Spiliopoulou ,Jef Wijsen

2006th Edition

3540467882, 978-3540467885

More Books

Students also viewed these Databases questions