AP Computer Science I

advertisement
Computer Science
lab4calculations
Arithmetic With Real Numbers
90 and 100 Point Versions
Assignment Purpose:
The purpose of this program is to get practice writing mathematical expressions that involve the double data type.
This assignment will again use the System.out.println command repeatedly, but now you will be displaying
the values of various double variables. Four variables have been defined and initialized for you. Five more
variables, sum, diff, prod, quot, and pow are defined and will be used in the calculation.
public class lab4calculations
{
public static void main(String args[])
{
double a = 10.0;
double b = 5.0;
double c = 77.77;
double d = 1.21;
double
double
double
double
double
sum;
diff;
prod;
quot;
pow;
//
//
//
//
//
Use
Use
Use
Use
Use
this
this
this
this
this
variable
variable
variable
variable
variable
for
for
for
for
for
all
all
all
all
all
addition problems.
subtraction problems.
multiplication problems.
division problems.
exponent problems.
// In this section, you need to display the values of the variables a through f.
// Variable "a" has been done for you. .
System.out.println("The value of a is
" + a);
// Write the rest of the statements to display variables b through f, using the same technique so they
// look like the output provided
// In this section, you need to use the variable "sum" to process several addition problems.
// The first problem "a plus 1.5" is demonstrated for you. See the sample output for the rest.
//IMPORTANT – you do not need to do any of the problems in the sample output that refer to PI or E
sum = a + 1.5;
System.out.println("a plus 1.5 equals
" + sum);
//Write the rest of the statements here so your program does the calculations to match the output
// In this section, you need to use the variable "diff" to process several subtraction problems.
// The first problem "a minus 1.5" is demonstrated for you.
diff = a - 1.5;
System.out.println("a minus 1.5 equals
" + diff);
//Write the rest of the statements here so your program does the calculations to match the output
// In this section, you need to use the variable "prod" to process several multiplication problems.
// The first problem "a times 1.5" is demonstrated for you.
prod = a * 1.5;
System.out.println("a times 1.5 equals
" + prod);
//Write the rest of the statements here so your program does the calculations to match the output
// In this section, you need to use the variable "quot" to process several division problems.
// The first problem "a divided by 1.5" is demonstrated for you.
quot = a / 1.5;
System.out.println("a divided by 1.5 equals
" + quot);
//Write the rest of the statements here so your program does the calculations to match the output
// In this section, you need to use the variable "pow" to process several exponent problems.
// The first problem "a squared" is demonstrated for you.
// Remember that "a squared" means the same thing as "a to the 2nd power" and "a times a".
pow = a * a;
System.out.println("a squared equals
" + pow);
//For the 100 point version write the rest of the statements here so your program does the
//calculations to match the output
}
}
90 Point Output
The 90 point version needs to do all addition, subtraction, multiplication, and division calculations.
Remember: MAKE SURE YOUR PROGRAM DOES ALL OF THE CALCULATIONS!
ALSO: Do not be surprised if some answers seem like they are off by 0.00000001
That is normal when you work with real numbers.
100 Point Output
The 100 point version adds the remaining exponent calculations.
Download