Question: 2. Write ML expressions that do the following: 1. Defines a NegativeValue exception 2. Defines a function printValue that takes an investment as an argument
2. Write ML expressions that do the following:
1. Defines a NegativeValue exception
2. Defines a function printValue that takes an investment as an argument and:
if the investment is a Stock, and price x shares is less than zero, raises a NegativeValue exception
otherwise, if the investment is a Stock, prints out the stock symbol and the value of price x shares
if the investment is Cash, prints out Cash = and the amount of money in cash
3. Calls the function printValue with the variable appleStock
4. Calls the function printValue with the variable myCash
5. Binds a Stock investment with values ("AAPL", -100, 5) to the variable badStock
6. Calls the function printValue with the variable badStock
3. Write ML expressions that do the following:
1. Defines a function compareValue that takes two investments as arguments and returns true if the first argument is greater than the second, and false otherwise. 2. Calls the function compareValue with appleStock and myCash as arguments
3. Calls the function compareValue with myCash and appleStock as arguments
4. Write ML expressions that do the following:
1. Defines a function findMaxValue that takes a list of investments and returns the investment with the greatest value. 2. Binds the value ("GOOG", 70, 15) to googleStock 3. Binds the value ("FB", 20, 8) to facebookStock
4. Binds the value (IBM, 30, 10) to ibmStock 4. Creates a list of all five investments (appleStock, ibmStock, googleStock, facebookStock and myCash) bound to investmentList 5. Calls findMaxValue with investmentList as its argument
5. Write ML expressions that do the following:
1. Defines findMaxValueTwo, which uses compareValue as a nested function
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
