|
Learning objectives:After completing this project, you should be able to:
Items in red are learning objectives for this part of the project. |
Individual work
| UsingSystemClasses report
| Time limit
|
UsingSystemClasses2
. UsingSystemClassesReport2.txt
,
placing it in the docs
subfolder of your UsingSystemClasses2
project.
UsingSystemClassesReport2.txt
file. Use it to record your answers to the questions in this exercise UsingSystemClasses2
project, calling the module UsingSystemClasses2
, spelled just like that. UsingSystemClasses2
project to your new CVS module. int i = 3, j = 4, k = 5; float x = 34.5f, y = 12.25f;
f
in 34.5f
mean? What happens if you remove it? JOptionPane
to display the value for each of the expressions below, preceded by the String
literal "The value of expression (a) is"
, replacing the letter in parentheses with the appropriate letter in each case. Note: Remember to import
the package that includes JOptionPane
.
( j / 8 ) * y
( (float) j / 8 ) * y
( j / 8.0 ) * y
-x * -y
( i + j ) / k
-x * -y * ( i + j ) / k
x + 1.5 / 250.0 * i / j
( x + 1.5 ) / ( 250.0 * ( i / j ) )
( 3 * k - j ) % i
x % y
0.0
? (float)
operator is an explicit type casting operator. Explain its role in expression (b). 1
instead of 1.4
?-x * -y
is 422.625
, and the value of ( i + j ) / k
is 1
due to the truncation that occurs during integer division, why is the value of expression (f) 591.675
?34.5045
. Explain why the following statement displays the incorrect output 34.50.0045000000000000005
?JOptionPane.showMessageDialog( null, "The value is " + x + 1.5 / 250.0 * i / j );
Infinity
?%
) to find the fractional part of a float
variable? JOptionPane
to Input Numerical Data String
variable called in
. double a = Double.parseDouble( in );
Double.parseDouble()
method? We will learn later how to deal with input errors like this. a
in a dialog window like this one:b
and c
, which should also be of type double
. Use one dialog to display the values of a
, b
, and c
once they have all been input, but display them on separate lines. D
of type double
and assign it the value of the expression b * b - 4 * a * c
. Modify your output dialog so that it also displays the value of D
. D
given the inputs a = 1.5
, b = -12
, and c = 22.5
? Math
Class Math.sqrt( D )
. Math.sqrt( D )
given the inputs a = 1.5
, b = -12
, and c = 22.5
? root1
and root2
of type double
and assign them the values of the expressions (-b + Math.sqrt( D ) ) / ( -2 * a )
and (-b - Math.sqrt( D ) ) / ( -2 * a )
.Modify the dialog window that you just added so that it also displays the values root1
and root2
.root1
and root2
given the inputs a = 1.5
, b = -12
, and c = 22.5
?Math.PI
. DecimalFormat df = new DecimalFormat( "0.000000" );
DecimalFormat
object, and what do you need to do to fix the problem? df.format( Math.E )
.df.format
method to display all of the numbers in your output dialog windows to six digits of precision.df.format
method truncate or round? System.out.println ( "What is the value of coefficient a?" ); BufferedReader streami = new BufferedReader( new InputStreamReader(System.in));
BufferedReader
object, and what do you need to do to fix the problem? String inA = streami.readLine();
readLine
method of your fancy new BufferedReader
object?public static void main(String args[]) {with the line
public static void main(String args[]) throws IOException {In other words, add the
throws IOException
clause to the declaration of the main
method. You'll need to do this for any method that uses standard input. \n
character. UsingSystemClasses2
.String
object to a double
value? double
value from the standard input.