Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is suppose to be written in java language 1. create a Stock class containing two data fields: stockName (a string), and stockPrice (a double).

This is suppose to be written in java language

image text in transcribed

1. create a Stock class containing two data fields: stockName (a string), and stockPrice (a double). and implementing the Comparable interface (check Java API). Write the appropriate accessor and mutator methods, as well as the toString, equals, and compareTo methods. The equals methods returns true if two Stock objects have the same name and price, otherwise false. The compareTo method takes a Stock object as argument and returns an positive integer if the calling object's price is greater than the argument object's stock price, 0 if the two stocks have the same price, otherwise a negative integer. 2. Demonstrate the Stock class in a program to: create an array of 20 elements. Each element is a Stock object sort the array in ascending order based on the stock price using any sorting algorithm. You need to rewrite the sorting algorithm to make it work on object sorting. ask the user to enter a stock name and price. search the array (using sequential search or binary search) for that stock 3. Analyze the worst-case time complexity for sorting an array of Stock objects and searching a stock in the array. Suppose the problem size (the array size is n)

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

Building Database Driven Catalogs

Authors: Sherif Danish

1st Edition

0070153078, 978-0070153073

More Books

Students also viewed these Databases questions

Question

Q.1. Taxonomic classification of peafowl, Tiger and cow ?

Answered: 1 week ago

Question

Q .1. Different ways of testing the present adulterants ?

Answered: 1 week ago

Question

Q.1. Health issues caused by adulteration data ?

Answered: 1 week ago

Question

1. Traditional and modern methods of preserving food Articles ?

Answered: 1 week ago

Question

=+ f. instituting laws against driving while intoxicated

Answered: 1 week ago