Q9. You are tasked with the responsibility of writing a
tool for generating Java code from UML. The class diagram
provides partial information on the attributes of a trading
position. Missing from the diagram are the operations.
A state diagram is also shown of some possible states for the
trading position. The state diagram shows that a position is
held if its price is initially less than a certain value or is made
available to sell or buy otherwise. Once available to
buy/sell the position can be increased or decreased. State
transitions can terminate by way of a market crash.
The following outline code has been generated from the tool:
In the following, choose all statements which are true.
a.
S1==Available, S2==State (where State is an abstract class),
S3==Accumulate, S4==Reduce.
b.
Y==Position.
c.
Operations of the Position class should include crash, inc, buy
and sell.
d.
Since the state machine contains loops, the number of states is
infinite.
e.
S1==Reduce, S2==Holding, S3==Available.
f.
Y==Available.
g.
The Position class should have operations ret_op1 which returns
the amount invested in a position and setop1 which increases the
investment by a specified amount.
h.
Operations of the Position class should include inc, available,
accumulate, reduce, and crash.
crash inc() [price>=v1]/price++ Holding inc() [price<v1]/price++ crash() Trading Position Available crash crash() buy() sell() Accumulate buy0 sell() Reduce sell() buy()
Position + id: String [1] + price: Real [1]
public class S1 extends S2 { } public void buy (Int Amount, Z _this) { _this.setState(new S3()); _this.setop1(_this.ret_op1()+Amount); } public void sell(Int Amount, Z_this) { _this.setState(new S4()); _this.setop1(_this.ret_op1()-Amount); } public void crash (Z _this) { this.setState(null); }
Q9. You are tasked with the responsibility of writing a tool for generating Java code from UML. The class diagram provi
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am