|
To earn money on java go to upwork.com
Req 2 : You have to create a program that simulates the NASDAQ Stock Quotations chart. The chart should maintain those 100 top companies whose stock prices are the highest. The chart displays the name of the company followed by its stock price in dollars, in the descending order of the stock price.
Req 3 : Req 2 + make sure that the companies that are added in the chart are all listed companies.
To earn money on java go to upwork.com
I see that you sort your elements inside list. If elements are sorted then much better search performance you get by searching with Collections.binarySearch(List<T> list,T key,Comparator c). Because it searches for element dividing collection by two. Look at that method at line 370 in java.util.Collections class to understand it.
I noticed that you use LinkedList whereas you exactly know how many elements will be kept there.
In your case maximum possible number of elements is 15
Chan Ag wrote:Thanks for your response, Volodymyr.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
I should have coded more than 1000 enum elements possibly
To earn money on java go to upwork.com
Chan Ag wrote:For req 2, I can't use a TreeMap because a company can have at most one entry so the company name should become the key.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
A List<Stock> whose contents are maintained via a HashMap<Company, Integer>?
where the "Integer" is the index of the Stock for that company in the List?
Then you can use that to maintain a third structure, which is a TreeMap<Price, List<Integer>>, which is the basis for your "top 100" list.
Then you can use that to maintain a third structure, which is a TreeMap<Price, List<Integer>>, which is the basis for your "top 100" list.
To earn money on java go to upwork.com
Volodymyr Levytskyi wrote:All @Winston suggestions make my head ache.
But this one in qoutes means that two or more different companies can have the same price. You can't have the same keys, but your price can be the same for different companies. That's why List<Integer> indicates indices of Stocks which have the same Price in List<Stock>.
I do not see why TreeSet<Company> with custom Comparator proposed by me in first reply is bad idea.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
I do not see why TreeSet<Company> with custom Comparator proposed by me in first reply is bad idea.
If you send is by car it's a shipment, but if by ship it's cargo. This tiny ad told me:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|