Your first Java lab

northcarolinawrySoftware and s/w Development

Nov 3, 2013 (3 years and 9 months ago)

75 views

Your second

Java lab

(10 bonus points for this lab)

Read all of these instructions
before

beginning the exercises.

1. Make sure you have a browser running in one of your desktops. Open your browser, and go to the web page
http://java.sun.com/j2se/1.4.1/docs/api/index.html
. This is a link to documentation for the standard Java classes.

TASK 1

(5 points)

2. Open TextPad, type the following:


import javax.swing.*;

public class SimpleTrig {



public static void main (String [] args) {


// Please insert your code here



}

}

-

Save it as “SimpleTrig
.java” in your c:
\
Document & Setting
\
<your account>


3. Modify this class by inserting codes which:

-

P
rompt the user for a value
of an ang
le (in degrees).
E.g:

Please enter angle (in degree). Please use JOptionPane for this
.

-

Compute sin and cosine of this angle.

-

Print out the results of this angle’s sin and cosine on the screen
.

Hint
. Use Math.cos and Math.sin for computing cosine and
sin, respectively. Please look these two methods over in the
documentation of Math class.


4. Compile your modified code by choosing Tools
-
> Compile Java in Textpad

5. Run your code by choosing Tools
-
> Run Java Application

6. Test

your code with angle =
0, a= 90 (degrees) and a=180 (degree
s
)


TASK 2

(5 points)


7.
Open TextPad, type the following:


import javax.swing.*;

public class SecondsConvert {


public static void main (String [] args) {


// Please insert your code here



}

}


-

Save it
as “SecondsConvert.java” in your c:
\
Document & Setting
\
<your account>

8
. Modify this class by inserting codes which:

-

Prompt the user for a value of seconds. Please use JOptionPane for this task.

-

Converts this value into the equivalent minutes and secon
ds.

For example: the user enters 120 (seconds), the output would be:

120 seconds = 2 minutes and 0 seconds

-

Print out the result on the screen.

9
. Compile your modified code by choosing Tools
-
> Compile Java in Textpad

10
. Run your code by choosing Tools

-
> Run Java Application

11
. Test your code with seconds = 120, seconds= 150 and seconds=0


SUBMISSION

12. Email to:
nguyenh@uww.edu

both SimpleTrig.java and SecondsConvert.java by Sunday 11:59pm at the latest.