Java

TOPIC 13 – TEST I REVIEW

 

 

DETAILS & REVIEW

 

 

DETAILS

 

The test covers both Units 0 and 1.  All notes.  All work.  All class discussion is fair game.

NOTE: In February 2021, we have excluded graphics from the test.  So no NOOPDraw and no Processing.  Your teacher will confirm if this will be the case moving forward.

Your test will be fully written.  You will not have a computer.

 

Minor programming errors will not count against you.

 

The Java template will be provided for you.  So you do not have to memorize the method prototype for the main function.

Function prototypes for Math and Graphics functions will be provided.  So you do not need to memorize these functions.  You do need to have a good idea how they work though.

 

REVIEW

 

QUESTION 1

Go over the following terms and make sure that you can define each one.  Some will appear as part of multiple choice questions on the test.

 

Programming language

Computer program

Syntax

Statement

Machine language

High level language

Source code

Compiler

Interpreter

Java compiler

String concatenation

Java virtual machine

Execute

Java Run-time Environment

Java Development Kit

IDE

Output statement

Indenting

Variable

Boolean

Double

Integer

Data type

Declaring a variable Initializing a variable

Assignment statement

Literals

Arithmetic expression

String

Function argument/parameter

Function return-type

Function call

 

QUESTION 2

Which variable names follow the correct convention?

 

          2daysDate

          Length

          plentyOfFun
          senatorsrule
          time left

          fun

          IWILLFAIL


QUESTION 3

Solve the following arithmetic expressions.

 

a)    int a = 7 + 18 - 4;

b)    int b = 43 % 6;

c)     int c = 2 + 4 * 3;

d)    int d = 6 - 3 * 2;

e)    int e = 7 / 2;

f)      double f = 9 / 2;

g)    double g = 8 % 3 + 2;

h)    double h = 3 * 6 % 5;

i)       double i = (int)6.5 * 2;

j)       double j = Math.sqrt(81);

k)     double k = Math.pow(3,2);

l)       double l = Math.pow(1+1, 3);

m)   double m = Math.ceil(2.2 * 2);

n)    double n = Math.round(4.3);

o)    double o = Math.max(2*4,6+3);

p)    double p = Math.min(Math.floor(4.2), Math.ceil(4.2));

q)    double q = 1.0 / (1.5 + 0.5);

r)      double r = Math.pow(Math.max(4,3), Math.min(2,3));

s)     double s = Math.cbrt(27);


QUESTION 4 – PROGRAMMING QUESTIONS

 

Answer the following:

a)    Consider a Point class that has two data fields (instance variables) called x and y.  Write the statements required to create a Point object name p and give it the coordinates (6,2).

b)    Write the Sword class.  It has a String data field for its name and two int data fields for it's accuracy and damage.

c)     Consider the Sword class from b.  Write the statements needed to create the sword object called Excalibur that has an accuracy of 9 and a damage of 12.

d)    Consider the following function from NOOPDraw:

public static void drawRectangle(double x, double y, double w, double h)


The function call NOOPDraw.drawRectangle(100,100,50,50) draws a

a) circle
b) square
c) triangle
d) a line
e) a pancake

e)    The function call NOOPDraw.drawRectangle(0,0,100,50) is creating a rectangle that actually needs to be moved to the right by 40 pixels.  Which of the following would be the corrected statement:

a) NOOPDraw.drawRectangle(40,0,100,50);
b) NOOPDraw.drawRectangle(0,40,100,50);
c) NOOPDraw.drawRectangle(0,0,140,50);
d) NOOPDraw.drawRectangle(0,0,100,90);
e) NOOPDraw.drawRectangle(0,-40,100,50);

f)      The function call NOOPDraw.drawEllipse(200,240,100,100) is creating a circle that actually needs to be moved up by 10 pixels.  Which of the following would be the corrected statement:

a) NOOPDraw.drawEllipse(210,240,100,100);
b) NOOPDraw.drawEllipse(200,250,100,100);
c) NOOPDraw.drawEllipse(200,240,110,100);
d) NOOPDraw.drawEllipse(200,240,100,110);
e) NOOPDraw.drawEllipse(200,230,100,100);



QUESTION 5 – SMALL PROGRAMS

 

Write the following programs.

 

a)    Write the program that asks the user for their first, middle and last names.  It then greets the user by saying "Hello name".  Make sure you have appropriate spacing.  You want to review using the Scanner object for this.

b)    Ask the user for their age.  Output the user’s year of birth.  The output should look like this:


          How old are you?

          35

          If your birthday passed this year, you were born in 1978.
          If your birthday has not passed this year, you were born

          in 1977.

c)     Ask the user for the name of an item, its price and the tax rate (3 inputs in total).  The program should output a sentence with the items name and it’s full price after taxes.

Here is some sample output:

     Enter your item’s name:
     Socks
     Enter the price:
     4.00
     Enter the tax rate (whole number):
     13
     Socks cost 4.52 in total.

 

Good luck!

 

You’ll need it!

 

Just kidding!

 

No I’m not.

 

J