1351-calc.php 4.41 KiB
<?php include("../../header2.php") ?>
<h2>Basic Graphics: The Calculator</h2>
<p>This lab will make you familiar with the basic
   graphics programming environment. It is a necessary
   preparation for your final project. This lab should
   also help you become familiar with anonymous inner
   classes.
   </p>
<p>The basic graphics package is distributed as
  <a href="https://www.cct.lsu.edu/~sbrandt/csc1351/BasicGraphics.zip">
  a Netbeans package,</a> and Calculator.java is one of the
  applications it comes with (look in the basicgraphics.calculator package). By default, the Calculator looks
  like this:</p> <img src="CalcPic.jpg" />
<p>All the buttons work. For example, if you type the sequence "3.2+1.1=" you
  will see the result "4.3". The "Clr" button clears the screen so you
  can type a new expression for evaluation.</p>
<p>Obviously, on Mars we will need a more advanced calculator.
   Our survival will depend upon it.
   Your assignment is to modify the Calculator.java file so that the
  calculator looks like this:</p>
  <img src="CalcPicAssignment.png" width="500"/>
<p>The first thing you will need to get working are the various functions
   to fetch data about Mars. This is available to you from the
   <a href="MarsData.java">MarsData class,</a>
   which will fetch live information about the Red Planet from the
   internet. To use this class, simply instantiate it and read its fields.
   (Note: You do not need to download this file or the tester if you have the latest <a href="https://www.cct.lsu.edu/~sbrandt/csc1351/BasicGraphics.zip">BasicGraphics.zip</a> installed, since they are already present inside it)
   <pre>
   MarsData md = new MarsData();
   setValue(md.declination); // sets the current value of the calculator
   update(); // updates the calculator display
   </pre>
   The next thing you should work on is the sin() function. You
   can find this as a static method on the java.lang.Math package. You call
   it like this:
   <pre>
   double val1 = ...;
   double val2 = Math.sin(val1);
   </pre>
   All the other functions, i.e. cos(), log(), exp() are also in the java.lang.Math
   package and must be called in the same manner.
   </p>
   <p>When you update the layout in Calculator.java,
   use the name "Sin" for the "Sin" button, "Exp" for
   the "Exp" button and so on. Use the name "M" for the "M+" button,
   "R" for the "MR" button, and "?" for the "+/-" button.</p>
   <p>The tester requires you to let go of the mouse button quickly after
   you start your application. Java will take over and move the mouse as
   well as press the buttons to test your app. The first thing it will test
   is sin(), then cos(), etc.</p>
   <p>The tester consists of two files. <a href='CalcTester.java'>CalcTester.java</a>
   and <a href='Auto.java'>Auto.java</a>. (If you get the latest
   version of BasicGraphics, they will already be included)
   <p>The "M+" button saves a value into the memory. The "MR" button recalls
   the last value saved to memory with "M+".</p>
   <p>The "+/-" button will negate the current value. It can be pressed at
   any time. So the sequence "3" "+/-" "." "4" should enter the value "-3.4".</p>
   <table border='1' cellpadding='5' cellspacing='0'>
   <tr><th>Layout Key</th><th>Button Text</th><th>Function</th></tr>
   <tr><td>RA</td><td>Right Ascension</td><td>Get the right ascension of Mars from the MarsData class.</td></tr>
   <tr><td>DECL</td><td>Declination</td><td>Get the declination of Mars from the MarsData class.</td></tr>
   <tr><td>ED</td><td>Earth Distance</td><td>Get the distance between Mars and the Earth from the MarsData class.</td></tr>
   <tr><td>SD</td><td>Sun Distance</td><td>Get the distance between Mars and the Sun from the MarsData class.</td></tr>
   <tr><td>Sin</td><td>Sin</td><td>Take the sin of the current value</td></tr>
   <tr><td>Cos</td><td>Cos</td><td>Take the cos of the current value</td></tr>
   <tr><td>Exp</td><td>Exp</td><td>Take the exponential of the current value</td></tr>
   <tr><td>Log</td><td>Log</td><td>Take the log of the current value</td></tr>
   <tr><td>M</td><td>M+</td><td>Store the current value to memory</td></tr>
717273747576777879
<tr><td>R</td><td>MR</td><td>Retrieve the value in memory</td></tr> <tr><td>?</td><td>+/-</td><td>Negate the current value</td></tr> </table> <?php showFile("Calculator.java"); ?> <?php showFile("MarsData.java"); ?> <?php showFile("CalcTester.java"); ?> <?php showFile("Auto.java"); ?> <?php include("../../footer.php") ?>