# Your first Java lab

Λογισμικό & κατασκευή λογ/κού

3 Νοε 2013 (πριν από 4 χρόνια και 7 μήνες)

92 εμφανίσεις

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.

(5 points)

2. Open TextPad, type the following:

import javax.swing.*;

public class SimpleTrig {

public static void main (String [] args) {

}

}

-

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

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
)

(5 points)

7.
Open TextPad, type the following:

import javax.swing.*;

public class SecondsConvert {

public static void main (String [] args) {

}

}

-

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

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.