COSC 135 A Exam 1 Practice Problems , Tom Linton Spring 2003
The problems on this practice exam are similar in difficulty level to those
that will appear on the first exam. This is NOT intended to be a laundry
list of the things you should study for exam 1. I have attempted to include
most of the important concepts from chapters 0 to 3 on this practice sheet,
but certain topics not included here may show up on the exam. Note,
we skipped sections 2.6 (Applets) and 3.8 (Numerical Representation), they
will NOT be on the exam.
-
What are comments used for in a Java program? Give two ways to include
comments in a source code file.
-
Write a single Java statement that assigns to the variable r, the
remainder when the variable total is divided by 25 (assume that
r and total are already declared and are of type int).
-
State the order of evaluation of the operators in each of the following
Java statements and show the value of x after each statement is performed.
Assume that n is a properly declared variable of type int.
-
n = 7 + 3 * 6 / 5 - 1; b. n = 2 % 2 + 2 * 2
- 2 / 2;
-
Write Java statements (or one statement) to declare and create a variable
of the class MainWindow.
-
Assume that x is a double variable that has been properly declared. What
value is strored in x by the commands below (be sure to use things like
5.0 instead of 5 here)?
-
x = (double) 10 / 4 + 5.0; c) x
= Math.ceil(-14.3) / 10;
-
x = (double) (16 / 10);
d) x = Math.pow(5, 2);
-
Give brief definitions or explanations of the following terms:
-
CPU
d. high level language
-
bytecode
e. compiler
-
bit
f. double
-
What is the main difference between an object of some class and a primitive
data type (variable)?
-
Which of the following are valid Java identifiers (circle them)? Which
valid identifiers below (cross them out) violate standard programming conventions
for naming objects?
| myTurtle |
3dGlasses |
noodleMania4 |
| my Turtle |
x8 |
MrMagoo |
| SNapPY |
ok?samIam |
double |
-
You have a Circle object named wilma and want to move
wilma
50
pixels to the right. Give the syntax for invoking wilma's moveHorizontal
method with the parameter (input) of 50.
-
Show the change in variables as the statements below are executed:
int num = 398, total;
total = num % 10;
num = num / 10;
total = total + num % 10;
num = num / 10;
total = total + num;
-
If you have a MessageBox named talky (already declared and instantiated),
write a Java statement that prints the value of the int variable weight
(already declared and holding a value) followed by the String ounces
(with
a space in between them).
-
As accurately as possible, write the source code for a program named Greeting
that
asks the user for their name and their age and then prints (using an OutputBox)
a message similar to:
Hello there Tom,
in ten years you will
be 51 years old.
The bold expressions should change with the user's input. In the example
above, the user entered Tom for their name and 41 for their
age.
-
If you created the program in the last question on the computer, what must
be the full name (filename and extension) of the file?
-
Convert (a) and (b) below from binary to decimal (base 10), and (c) and
(d) from decimal to binary (base 2).
-
1011
-
111000
-
32
-
50
-
Consider the program below:
/* A silly program for an exam
* by Tom Linton, working alone
* COSC 135 A, February 12, 2003 */
import javabook.*;
public class Silly
{
public static void main(String args[])
{
MainWindow glassy = new MainWindow();
OutputBox gabby = new OutputBox(glassy);
InputBox asky = new InputBox(glassy);
Clock ticky = new Clock();
glassy.show();
gabby.show();
int score1, score2, score3;
score1 = score2 = score3 = 0;
double avg;
final double LOWESTA = 90.0;
gabby.printLine("This may take a while, please be patient!");
ticky.pause(15);
score1 = asky.getInteger("Enter score on exam 1");
score2 = asky.getInteger("Enter score on exam 2");
score3 = asky.getInteger("Enter score on exam 3");
avg = (score1 + score2 + score3) / 3.0;
gabby.printLine("Your average for the three exams is " + avg);
gabby.skipLine(2);
gabby.printLine("All scores above " + LOWESTA + " earn an A!");
}
}
-
What is the name of the class defined in the program above?
-
List all of the classes (other than the one being defined) used in this
program.
-
List all of the object names used in this program.
-
List all of the methods invoked in this program.
-
List all of the variables used in this program. One is a constant, which
one?
-
What does this program do?