Math Helper

Look at your calculator.  It has lots of buttons.  Each button does a different calculation.  But those are simple, single step calculations.

Real scientists, economists and mathematicians do longer calculations, with many steps.  They'd prefer to have a computer program that can carry out longer calculations, like solving a quadratic equation or printing a series of numbers.

The following sample program has two buttons for two separate calculations :


import java.awt.*;

public class MathHelper extends EasyApp
{
   public static void main(String[] args)
   {
      new MathHelper();
   }
   
   Button usTip = addButton("US Tip",50,50,100,50,this);
   Button gpSeries = addButton("GP Series",150,50,100,50,this);
   
   public void actions(Object source, String command)
   {
      if (source == usTip)
      {  double price = inputDouble("Type price of meal");
         calcUsTip(price);
      }
      if (source == gpSeries)
      {  double a = inputDouble("First term");
         double b = inputDouble("Second term");
         calcGpSeries(a,b);
      }   
   }
   
   public void calcUsTip(double price)
   {
      System.out.println("Price = " + price);
      System.out.println("10% = " + price*0.10);
      System.out.println(" 5% = half of 10% = " + price*0.05);
      System.out.println("Total tip = " + price*0.15);
      System.out.println("Total price + tip = " + price + " = " +  price*0.15);
      System.out.println(" = " + price * 1.15);
   }
   
   public void calcGpSeries(double a, double b)
   {
      double r = b / a;
      double infSum = a / (1-r);
      System.out.println("Geometric Progression");
      System.out.println("First term (a) = " + a);
      System.out.println("Second term = " + b);
      System.out.println("First 5 terms = " );
      System.out.println(a + "\t" + b + "\t" +
                         b*r + "\t" + b*r*r + "\t" + b*r*r*r);
      System.out.println("Infinite sum = " + infSum);
   }
}


Each student has written a program that solves a math problem, printing all the steps in the solution.  Your assignment is to gather all 7 programs together and add them as 7 new buttons in the program above.

After putting the all these pieces together, add 2 more pieces for 2 other math calculations.  You can take any sample problem from your math textbook.

You might want to take a look at the following program that demonstrates a very large and sophisticated math helper program:  http://www.matheass.de/matheass_de/download.htm