Difference between revisions of "CISC181 S2017 Lab1"

From class_wiki
Jump to: navigation, search
Line 11: Line 11:
 
** Add your name and section number as a ''multi-line comment''
 
** Add your name and section number as a ''multi-line comment''
 
** Using a ''single-line comment'', disable the "Hello, world" print statement in <tt>main()</tt>
 
** Using a ''single-line comment'', disable the "Hello, world" print statement in <tt>main()</tt>
** You will use <tt>main()</tt> to compute several geometric identities involving a general triangle with sidelengths ''a'', ''b'', and ''c'' as shown below.  Declare these variables as <tt>double</tt>, prompt the user to enter them, and read each in using the [http://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html <tt>Scanner</tt>] class.<br>[[Image:Triangle_med.png|center|300px]]<br>
+
** You will use <tt>main()</tt> to compute several geometric identities involving a general triangle with sidelengths ''a'', ''b'', and ''c'' as shown below.  Declare these variables as <tt>double</tt>, prompt the user to enter them, and read each in using the [http://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html <tt>Scanner</tt>] class.<br>[[Image:Triangle_with_notations_2.svg.png|center|300px]]<br>
 
*** [http://en.wikipedia.org/wiki/Heron%27s_formula Heron's Formula] gives a method to compute the area ''A'' of the triangle.  Follow the [http://en.wikipedia.org/wiki/Heron%27s_formula link] and use the first formula to derive the ''semi-perimeter'' ''s'' and ''A'' from ''a'', ''b'', and ''c''; implement it using [http://docs.oracle.com/javase/7/docs/api/java/lang/Math.html Java math] expressions and/or functions; and report both ''s'' and ''A'' with <tt>System.out.println()</tt>.
 
*** [http://en.wikipedia.org/wiki/Heron%27s_formula Heron's Formula] gives a method to compute the area ''A'' of the triangle.  Follow the [http://en.wikipedia.org/wiki/Heron%27s_formula link] and use the first formula to derive the ''semi-perimeter'' ''s'' and ''A'' from ''a'', ''b'', and ''c''; implement it using [http://docs.oracle.com/javase/7/docs/api/java/lang/Math.html Java math] expressions and/or functions; and report both ''s'' and ''A'' with <tt>System.out.println()</tt>.
 
*** The [http://en.wikipedia.org/wiki/Law_of_cosines Law of Cosines] can be used to calculate the angle ''γ'' (gamma) between ''a'' and ''b'' (second formula in Applications section of [http://en.wikipedia.org/wiki/Law_of_cosines#Applications link]).  <tt>Math.acos()</tt> will give the angle in radians; please convert it to degrees and report it with <tt>System.out.println()</tt>
 
*** The [http://en.wikipedia.org/wiki/Law_of_cosines Law of Cosines] can be used to calculate the angle ''γ'' (gamma) between ''a'' and ''b'' (second formula in Applications section of [http://en.wikipedia.org/wiki/Law_of_cosines#Applications link]).  <tt>Math.acos()</tt> will give the angle in radians; please convert it to degrees and report it with <tt>System.out.println()</tt>

Revision as of 10:12, 13 February 2017

  • Download Android Studio and install it on your machine
  • Either on your machine or on an eCalc machine in lab:
    • Make a new project following these instructions
    • If you haven't already, paste the following into MyClass: public static void main(String[] args) { System.out.println("Hello, world!"); }
    • Confirm that you can build and run it (by pressing the green triangle button or choosing "Run" from the Run menu)
  • Modify MyClass.java as follows:
    • Add your name and section number as a multi-line comment
    • Using a single-line comment, disable the "Hello, world" print statement in main()
    • You will use main() to compute several geometric identities involving a general triangle with sidelengths a, b, and c as shown below. Declare these variables as double, prompt the user to enter them, and read each in using the Scanner class.
      Triangle with notations 2.svg.png

      • Heron's Formula gives a method to compute the area A of the triangle. Follow the link and use the first formula to derive the semi-perimeter s and A from a, b, and c; implement it using Java math expressions and/or functions; and report both s and A with System.out.println().
      • The Law of Cosines can be used to calculate the angle γ (gamma) between a and b (second formula in Applications section of link). Math.acos() will give the angle in radians; please convert it to degrees and report it with System.out.println()
      • You might notice a lot of decimal places printed in your answers. Change your println() to format as necessary to only print 2 digits after the decimal for s, A, and γ.
      • Use proper naming and formatting style throughout your code.

Submit your MyClass.java on Sakai by Friday, February 17