Java…….Class Is In Session

advertisement

STUDENT TEST BOOKLET

Open Response Scoring Breakdown: 4 = 50/50, 3 = 45/40, 2 = 30/50, 1 = 20/50

This test section contains TWELVE multiple-choice and ONE open-response (short-answer) questions. Please mark your answers for the multiple-choice questions in the spaces provided on your Student Response Booklet. Mark only one answer for each question. If you do not know the answer, make your best guess. DO NOT WRITE ANY ANSWERS IN THIS TEST BOOKLET.

WHEN YOU FINISH, DO NOT WORK ON ANY OTHER TEST SECTION.

1.

Jason encountered the following code while reviewing a sample Java applet online. if (page.getColor() == Color.black)

page.setColor (Color.white);

else

page.setColor (Color.black);

Which of the following correctly showcases the meaning of the Java code segment listed above?

A.

The code segment will ask the user to enter a color and if the user enters the color black the program will set the page color to white if black is not entered by the user it will be set as the color currently being used.

B.

C.

D.

The code segment is designed to alternate color print outs from line to line. The program will first print out a black line and the next line will then be printed in white.

The code segment is structured so that only two colors can be used within the program. White and black have been established as the only colors to be used within the Java applet.

The code segment will change the current color being used to white if the active color is black. Otherwise the current color will be set to white within the program.

2.

The relationship between a class and an object is best described as

A. classes are instances of objects

B. objects are instances of classes

C. objects and classes are the same thing

D. classes are programs while objects are variables

PLEASE GO ON TO THE NEXT PAGE 

3.

Which of the sets of statements below will add 1 to x if x is positive and subtract 1 from x if x is negative but leave x alone if x is 0?

A. if (x > 0) x++;

else

x--;

B. if (x > 0) x++;

else if (x < 0) x--;

C.

D. if (x > 0) x++; if (x < 0) x--;

else x = 0; if (x == 0) x = 0;

else x++; x--;

4. Denise has encountered the following section of code in an older program she is analyzing. int weight, total = 0;

Which of the following best summarizes this section of Java code?

A.

The code will produce a syntax error due to the two variables being placed on one line.

B. The code will create a single integer variable within the program

C.

The code will create two variables that will be added together within the program.

D. The code will create two integer variables within the program

5. Carl just received a letter from the president of Computer & Things that indicated that Carl was going to receive a 7.5% raise with his promotion to head programmer.

Carl’s current salary is $33,500 per year. What will Carl’s new salary be with the indicated raise?

A. $36,010.5

B.

C.

D.

$38,010.5

$36,012.5

$34,018.5

PLEASE GO ON TO THE NEXT PAGE 

6.

Kyle is working on a loop that will execute several lines of code multiple times within a program. Each time the code executes the program should prompt the user to enter in a test grade. He is debating between the following two program statement setups

A.

for (index = 0; grade < index; index++)

System.out.print (“Please enter another grade);

grade= keyboard.readDouble();

B.

for (index = 0; grade < index; index++)

{

System.

out.print (“Please enter another grade);

grade= keyboard.readDouble();

}

Which statement below best outlines the choice (A or B) Kyle should make concerning his code?

A.

The code within section A or B would allow the person to enter the grade multiple times.

B.

The code within section A would be the best selection because the {} brackets indicate a decision must be made within a program.

C.

The for loop is structured incorrectly in both A and B meaning Kyle should rewrite the code statement

D.

The code within section B is the best selection because the {} brackets allow both lines of code to be executed each time the loop occurs.

7.

To define a class that will represent a car, which of the following definitions is most appropriate if someone is following Java naming and programming standards?

A. private class car

B. public void main class car

C. public class Car

D. return CAR

PLEASE GO ON TO THE NEXT PAGE

8.

Compare the following two if statements and select, which answer best, summarizes each line of code. string name1, name2; int guess, answer; if (name1.equals(name2)) if (guess == answer)

A.

B.

C.

D.

The first if statement will compare the numerical value of the two names entered to see if they are equal and the second if statement will also compare the numerical values to see if they are equal

The first if statement will not work correctly due to string values being used, the second if statement will correctly compare the variables guess and answer

The first if statement will compare the two string values to see if they are equal and the second will compare the two integer values to see if they are equal.

The first if statement should read if (name1 == name2) in order to properly compare the values and the second if statement will compare the numerical values to see if they are equal.

9.

Which of the following reserved words in Java is used to create an instance of a class?

A. public

B. public or private, either could be used

C. import

D. new

PLEASE GO ON TO THE NEXT PAGE 

10.

Kendra has implemented a While loop within her Java program. Assess the code statement below and select which answer best summarizes the output Kendra will experience once the while statement is executed. int count = 1; while (count <=25)

{

A.

System.out.println (count);

Count = count

–1;

}

System.out.println (“Done”);

B.

C.

D. the while loop will execute 25 times and print the numbers 1 thru 25 and finish with the printing of Done the while loop will execute 25 times and print the numbers 25 down to 1 and finish with the printing of Done the while statement will not function correctly due to a missing semicolon(;) after the statement while (count <=25) the while statement will execute by counting down from 1 until infinity and result in an infinite loop.

Fortran

The First Successful High Level Programming Language

By Mary Bellis , About.com Guide

What was Fortran or Speedcoding?

FORTRAN or formula translation was the first high level programming language (software1) invented by John Backus for IBM in 1954, and released commercially in 1957. Fortran is still used today for programming scientific and mathematical applications. Fortran began as a digital code interpreter for the IBM 7012 and was originally named Speedcoding. John

Backus wanted a programming language that was closer in appearance to human language, which is the definition of a high level language, other high language programs include Ada, Algol, BASIC3, COBOL, C, C++, LISP, Pascal, and Prolog.

Generations of Codes

1.

The first generation of codes used to program the functions of a computer was called machine language or machine code. Machine code is the language a computer really understands on a machine level, being a sequence of 0s and 1s that the computer's controls interprets as instructions electrically.

2.

The second generation of code was called assembly language. Assembly language turns the sequences of 0s and 1s into human words like 'add'. Assembly language is always translated back into machine code by programs called assemblers.

3.

The third generation of code, was called high level language or HLL, which has human sounding words and syntax

(like words in a sentence). In order for the computer to understand any HLL, a compiler translates the high level language into either assembly language or machine code. All programming languages need to be eventually translated into machine code for a computer to use the instructions they contain.

John Backus & IBM

John Backus headed the IBM team of researchers, at the Watson Scientific Laboratory, that invented Fortran. On the IBM team were the notable names of scientists like; Sheldon F. Best, Harlan Herrick (Harlan Herrick ran the first successful fortran program), Peter Sheridan, Roy Nutt, Robert Nelson, Irving Ziller, Richard Goldberg, Lois Haibt and David Sayre.

The IBM team didn't invent HLL or the idea of compiling programming language into machine code, but Fortran was the first successful HLL and the Fortran I compiler holds the record for translating code for over 20 years. The first computer to run the first compiler was the IBM 704, which John Backus helped design.

Fortran Today

Fortran is now over forty years old and remains the top language in scientific and industrial programming, of course it has constantly been updated.

The invention of Fortran began a $24 million dollar computer software industry and began the development of other high level programming languages.

Fortran has been used for programming video games, air traffic control systems, payroll calculations, numerous scientific and military applications and parallel computer research.

John Backus won the 1993 National Academy of Engineering's Charles Stark Draper Prize, the highest national prize awarded in engineering, for the invention of Fortran.

Utilize the article above to answer questions 11-12

11. Which section of the article does not help answer the question, “What is a high level programming language?”

A. What was Fortran or Speedcoding?

B.

C.

Generations of Codes

John Backus & IBM

D. Fortran Today

12. Based on the material in the passage, you can infer that Fortran______________.

A. is outdated and has been replaced by other high level programming languages such as C++ or Java

B. is a machine language by conversing with a computer using only 1’s and 0’s

C.

D. is still used to help design scientific programs due to its ease of operation and human like statements. was a fluke development that was discovered when other computer technologies failed to operate correctly.

PLEASE GO ON TO THE NEXT PAGE 

OPEN-RESPONSE QUESTION

Read all parts of the open-response question before you begin. Write your answers to the openresponse question in the space provided on your Student Response Booklet. DO NOT WRITE ANY

ANSWERS IN THIS TEST BOOKLET.

Java…….Class Is In Session

When working in a Java programming shop it is essential for the programmer to understand classes and their role within the programming world. When a programmer neglects to learn the purpose of classes he or she is stating that they wish to perform more work and write more code doe to the overall absence of classes within their program development process.

13.

A. Explain the purpose a class performs within a Java program.

B.

Describe the process one would take to develop a class that represents a coin with two sides and a driver program that would allow the user to flip the coins a set number of times.

Download