Exercise 1

1 Question

Can you really put an algorithm section inside an equation section?


1.1

Yes, you didn't think so, did you?


2 Writing an Algorithm Section

Create the class, Average, which calculates the average between two named integer parameters, using an algorithm section.



Create another class and declare an instance of the Average class using modifiers to change the parameter values.



Simulate and then test the result of the instance class by using the val function to look at the values:



2.1

2.1.1 Average class


2.1.2 The instance


2.1.3 Simulation of AverageInst



3 A harder exercise

Write a class, AverageExtended, that calculates the average of 4 variables (a, b, c and d).



Create another class and declare an instance of the AverageExtended class using modifiers to change the parameter values.



Simulate and then test the result of the instance by using the val function to look at the values at time=0..



3.1

3.1.1 AverageExtended

Note that the sum is calculated in an equation section to show that it is possible to mix algorithm and equation sections in a class.



3.1.2 The instance


3.1.3 Simulate of AverageExtended


Then you can look at the values of the variables at a specific point in time by using the val function. We choose time = 0 below.