Banner
Assignment 2


Agent-Based Modeling


Due Date: April 24, 2012

Spring 2012

Psychology 120


The aim of assignment 2 is to build a Java program from scratch again so that you will become more familiar with Java. When you are done, you will show it to us for approval and credit.

Problem

You will build from scratch, an agent that can do various calculations.  When it does a calculation, it will print out the form of the calculation.  For example, if you ask it to add 20 to 33, it should print out “20 + 33 = 53″.  You will then add “demo” methods that illustrate all of the kinds of calculations it can do.

Step 1

As before, create a project and a package in the “src” folder of your project.

Step 2

Create your Classes within the package of your project. One will be your agent that can do mathematical calculations, call it “Calculator”. The other object is the environment object for running your simulation and remember it must have a “main” function. You can use the lecture notes or your last lab for help.

Step 3

Define your calculator agent class in detail. It will contain methods for performing various mathematical operations and functions.

Hint #1: Here is a method for addition that solves the problem above:

     public void add(double n, double m) {
              System.out.println(n+" + "+m+" = "+(n+m));
          }

Hint #2: To demonstrate these mathematical methods, write at least two methods that demonstrate their use. For mathematical methods that take two arguments, you could write a method like this:

         public void demonstrate(double n, double m){
             add(n,m);
             subtract(n,m);
             multiply(n,m);
             divide(n,m);
         }

For one argument, you could write:

         public void demonstrate(double n){
             square(n);
             squareRoot(n);
             sin(n);
             cos(n);
         }

The number of mathematical methods you write can be more than this or you can write different ones.

Step 4

Define your environment.  Create an instances of “Calculator” and run both demonstration methods.

Step 5

Run your program and debug it.

Step 6

Show us your program, that it demonstrates all the mathematical methods you have written, and you are done!