Fri, Oct 9: In class midterm test on Java
Covered lectures/labs; all up to Oct 2.
Thus GUI not covered on exam.
Covered reading:
Chapters 2, 3, 4, 5 (pages 171-179), 7 (pages 251-276)
Appendices: L, N, O
Key Concept Logical operators are a natural choice to implement a condition for a selection or repetition statement because they return a boolean value.
/** MonteCarloPi estimates Pi by choosing count points at random in a square and returning 4*(number in inscribed circle)/count. */ public double MonteCarloPi(int count) { ... }You may assume the same class contains this method:
private boolean inCircle( double x, double y, double radius ) { return x*x + y*y <= radius*radius; }This is a test of knowing how to organize the planned sequence of calculations, so will be graded primarily with respect to proper logical organization to achieve the goal. Less emphasis will be placed on syntax and proper declaration of variables used. Nonetheless, the syntax has to be good enough that we can discern your meaning.
setXORMode
method
of the Graphics
class?
double X = 1.0; int N = 1; long L = 1;Which of the following is not a legitimate (compilable) assignment statement in java? (a little tricky)
L = (int) X ;
N = L ;
L = N + (int) X ;
N = ( (byte) L + (short) X ) ;
/** degSine returns the sin of an angle given in degrees. */ public double degSine( int angle_in_degrees ) { ... }
primaryColors
containing initially the three colors red, green, blue.
sleep
method call in another one, the one we
called snooze
?
g.drawRect(0,0,10,10);
fillRect(0,0,10,10);
g.setColor( Color.black ); g.drawOval( 10, 20, 30, 40 );
double
value be converted to long
?
ExclusiveOrExpression: AndExpression ( "^" AndExpression )*Assuming A, B, and C are valid AndExpressions, which of these is a valid ExclusiveOrExpression?
To answer such questions you should know how the regular expression
works. If A B C are grammatical categories,
A B refers to an instance of A followed by an instance of B
(A | B) refers to an instance of A or an instance of B
(A)* refers to zero or more instances of A in a row.
[A] refers to an optional instance of A
Thus the answer to the question is "All of the above"
ExclusiveOrExpression: AndExpression ( "^" | AndExpression )*
ExclusiveOrExpression: AndExpression [ "^" | AndExpression ]*
main
method.
Suppose I have a class file MyClass.class, compiled from MyClass.java, and designed to be an applet.
import
statement will be necessary in MyClass.java
(because it is an applet class)?