首页 > > 详细

辅导software留学生、讲解Python,c++编程设计、辅导Java解析C/C++编程|讲解留学生Processing

Homework #2
In this homework we will also go through multiple small tasks which we will use during the next class to talk about design patterns, software, etc. The solutions for this homework should be in the following form. All answers should be in a packages edu.nyu.compfin19.homework2.Question1, edu.nyu.compfin19.homework2.Question2, … . Each package should be self-contained and not reference any classes from other packages. All classes needs to be unit tested.

1.You should write a class called Exchange that implement a method public double price() which returns a random number. You should write a class called Trader that accepts a DoubleSupplier on the constructor and have one method public void run(). The run method prints the first 10 numbers provided by the supplier. Write a main class named Question one that creates an Exchange and a Trader that accepts the exchange as an input and calls the Trader run method.
2.We want to have ten traders, and they all want to see the same numbers in the same order. Essentially, the output needs to be
Trader 1: 345
Trader 2: 345

Trader 10: 345
Trader 1: 897
….
You will now need to change the Trader constructor, what the run method does and how to use it, and the Exchange.

3.Now repeat question 2 without but now with 7 Traders.

Do we really want to Hardcode the Exchange all the time?

4.Write an Exchange class. The Exchange class now have a method called consumer(DoubleConsumer doubleConsumer) that accepts consumer. Every time that the method is called, the consumer given is added to a set. The Exchange have another method called removeConsumer(DoubleConsumer doubleConsumer) that whenever called remove the consumer from the set. (Keep in mind edge cases like null input and guard from them)
5.Write a class called Trader that now has a method called price(double price). The method prices the price to standard out.
6.Write a class named Questions6 that has a main class that use the classes from Question 4 and 5 to print the ten numbers to the screen as we did if the first question.
7.Write a class named Question7 with a main class that starts ten new Traders and print output similar to question 2 but with the classes we wrote in questions 4 and 5.
8.Write a class named Question7 with a main class that starts ten new Traders and print output similar to question 2 but now Trader number ten prints ONLY the first five numbers.

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!