Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please use JAVA. Program Description: You will be writing a program to track the outcome of a competition or sporting event where individuals or teams

Please use JAVA.

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.

1.1 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.

1.2 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.

1.3 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.

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

Beyond Greed And Fear Understanding Behavioral Finance And The Psychology Of Investing

Authors: Hersh Shefrin

1st Edition

0195161211, 978-0195161212