Lab Test For Tuesday September 19, 2006
This lab test consists of three problems of increasing complexity. You should probably
start at the top and work your way through. Keep an eye on the time as the test ends
in 90 minutes. When submitted your assignment you must follow the instructions
provided exactly.
- (2 marks)
Create a file called
LabTest1A.java that contains exactly the following
lines of test
import java.lang.*;
public class LabTest1A
{
public static void main(String[] args)
{
System.out.println("Mares eat oats and does eat oats and little lambs eat ivy");
}
}
Once you
have completed the application and have tested to ensure it works
correctly as specified, you can submit it using the submit command
(described below in greater detail). You must submit this file using
submit 1020 lab1-tuesday LabTest1A.java
(e.g., LabTest1A.java ) as many times as you like and in
fact, you are encouraged to do so throughout the duration of the test.
(You can learn more about the submit command by typing
man submit ).
You can verify that your submission has been accepted using
submit -l 1020 lab1-tuesday
- (3 marks)
The following code is supposed to output the area of a circle as a
float (not double) given the value in
radius . (The area of a circle is
approximately 3.1415 * r * r.) Radius should have the value 3.0f.
Correct the errors in the
following. Note: The lines marked "keep" must not be changed.) You
can obtain a copy of this file by clicking on this
link and saving the file to disk.
import java.lang.*
public class LabTest1B
{
public static void main(Strings[] args)
{
float radius;
System.out.println("<<<<<<<<>>>>>>>>>>"); //keep
radius = 3.0L;
System.out.println("<<<<<<<<>>>>>>>>>>"); //keep
float Radius;
System.out.println("<<<<<<<<>>>>>>>>>>"); //keep
int area = 3.1415 * Radius + Radius;
System.out.println("<<<<<<<<>>>>>>>>>>"); //keep
System.out.println(radius);
System.out.println("<<<<<<<<>>>>>>>>>>"); //keep
}
}
Submit your solution using
submit 1020 lab1-tuesday LabTest1B.java
- (3 marks)
Write a program that prints out the following two floating point
computations, each on its own line.
Each computation should be
done as a float (not as a double).
These two sums should be computed exactly as shown below
sum1 = 100000001 + 0.1 - 100000001 - 0.1;
sum2 = 0.1 - 0.1 + 100000001 - 100000001;
If the values of sum1 and sum2 were
1 and -1 respectively, then your program should output
1
-1
Submit your solution using
submit 1020 lab1-tuesday LabTest1C.java
Once you have successfully submitted all three parts of the labtest,
and checked that they have been submitted successfully, feel free to leave the
test. Remember, once you log out any temporary work that you may have generated
will be lost.
|