Test

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Java does not use "=" to test for equality? What does it use instead?

= =

What does the j++ mean?

The output of this program might cause a little confusion

What kind of loop is the while loop?

This is called conditional repetition. Java is well prepared for the task with two conditional loop structures: the precondition while loop and the post condition do...while loop

What Expo class method would you use to enter someone's name?

enterString

What does the j = 1 mean?

for (int j = 1; j <= 10; j++)

What is the simplest control structure?

one-way selection

What would be the output of program Java0513 if B was entered?

// Java0513.java // This program demonstrates multi-way selection with <switch> and <case>. // This program compiles, but displays illogical output. public class Java0513 { public static void main (String args[]) { System.out.println("\nJAVA0513.JAVA\n"); System.out.print("Enter Letter Grade ===>> "); char grade = Expo.enterChar(); System.out.println(); switch (grade) { case 'A' : System.out.println("90 .. 100 Average"); case 'B' : System.out.println("80 .. 89 Average"); case 'C' : System.out.println("70 .. 79 Average"); case 'D' : System.out.println("60 .. 69 Average"); case 'F' : System.out.println("Below 60 Average"); } System.out.println(); } }

List the 6 relational operators.

= = > < >= <= !=

Most conditional statements will require what?

A logical or Boolean operator

What kind of operator is required to make an expression evaluate to true or false?

A logical or Boolean operator

What is a conditional statement?

A statement that is true or false

Explain Repetition

Another common application occurs when repetition is required.

In what computer language do programs require control structures?

Any programming language

In computer science, what is a flag?

Computer Science is full of funny terms. Encapsulation, Polymorphism, Concatenation, just to mention a few. When dealing with conditional loops, it is important to understand what the flag is. The flag is the special value that makes the loop stop. Maybe this value is entered by the user. Maybe it is computed in the loop. Whatever special value makes the loop stop is the flag. A good way to remember that is to think of a race track. Cars go in a loop again and again. The race keeps going until the checkered flag is waved and the race is over.

Refer to your answer to the previous question. Give an example of where this command would be useful

Enter middle initial

What does GUI stand for?

GUI stands for Graphical User Interface

Look at this heading again. for( int j = 1; j <= 100; j++) Rewrite it so it counts from 100 backwards down to 1, by 1s.

However, this time the program uses a for loop control structure to assist with the repetition process. Program Java0516.java, in figure 5.16, is considerably shorter than the previous program example.

Write the Java statement that will do this action: If your grade is 70 or better, print "You passed!"

If (grade >= 70) System.out.println("You passed");

Write the Java statement that will do this action: If your grade is 70 or better, print "You passed!" otherwise print "You failed!"

If (grade >= 70) System.out.println("You passed"); else System.out.println("You failed");

In fixed repetition, what does fixed mean?

In this section we will explore fixed iteration with the for loop structure

Why should indentation be used with control structures?

It makes the program more readable

Look at program Java0504.java. How does this program cure the problem of the previous one?

It used enterInt to enter inteter values instead of strings

The for loop has 3 things between the parentheses in the heading. What is the only thing between the parentheses in the heading of a while loop.

Java is well prepared for the task with two conditional loop structures: the precondition while loop and the post condition do...while loop.

Look at program Java0510. How does this cure the problem of the previous program?

Java0510.java, in figure 5.10 and notice how the braces create a block that identifies the program statements that need to be "controlled" by the if condition

What does LCV stand for?

Loop Control Variable

All conditions must be placed inside what?

Parentheses

What does program flow follow?

Program Flow follows the exact sequence of listed program statements, unless directed otherwise by a Java control structure.

Look at program Java0503.java. This program gives the impression that it will find the sum of 2 entered numbers. Why does it not work?

Program Java0503.java, in figure 5.3, enters two integers and tries to display the sum of the two numbers.

What would be the output of program Java0512 if B was entered?

Program Java0512.java, in figure 5.12, demonstrates block structure with two-way selection

What would you need to change in program Java0515 if Joe wanted the message displayed 1000 times?

Program Java0515.java, in figure 5.15 demonstrates the inefficient repetition without using any loop structures. Please do not ever use this approach.

What would you need to change in program Java0516 if Joe wanted the message displayed 1000 times?

Program Java0516.java, in figure 5.16, is considerably shorter than the previous program example.

What does the j <= 100 mean?

Program Java0521.java, in figure 5.21, introduces the while loop. This loop is called a precondition loop

Look at program How does this program cure the problem of the previous program?

Program Java0521.java, in figure 5.21, introduces the while loop. This loop is called a precondition loop.

Why is the do...while loop called a post condition loop?

Program Java0521.java, in figure 5.21, introduces the while loop. This loop is called a precondition loop. The while statement is at the beginning of the loop and it check the condition before the loop starts

How does Simple Sequence work?

Selection control structures use a special conditional statement. If the condition is true, some action is performed, such as branching off to another sequence

What are 2 synonyms for Selection?

Selection is also called conditional branching or decision making.

What do Selection and Repetition control structures have in common?

The title of this section is repetition. That is not the only word. You can also say looping, and the formal computer science word is iteration

What are 2 synonyms for Repetition?

The title of this section is repetition. That is not the only word. You can also say looping, and the formal computer science word is iteration. The name does not matter, as long as you realize that this is a control structure that executes certain program segments repeatedly.

How do you control multiple statements with two-way selection?

There is one-way selection with if, two-way selection with if..else and multiple-way selection with case..break

Why is a prompt necessary for program input?

This line is technically called a prompt. It asks or "prompts" the user for information.

Give a real-life example of Two-Way Selection. (Not the one that is in the book.)

Toss a coin "heads" means we go to a movie and "tails" means we go dancing

In one-way selection, when does the program flow branch off?

True

What is the essence of understanding, and using, control structures?

Use the correct control structure for the correct purpose.

What loop structure is used with fixed repetition?

We now make a major jump in the control structure department. We have just looked at three control structures. All three control structures were different but they each were some type of selection control. Now you will learn how to repeat program segments

When is the default statement executed?

When no match found

Look at program Java0520. The program's output is very strange. What caused this?

When the program is compiled and executed, you should notice the output is... a little strange.

What company invented the GUI?

Xerox

What does the nextLine method do?

You do need to realize that method nextLine enters strings, method nextInt enters integers and method nextDouble enters double data types.

What kind of operator is "="?

assignment operator

Selection control structures use a special _____________ statement

condition

Look at program Java0509. Why does this program have strange output?

demonstrates that the program statement following the completed if statement is executed regardless of the conditional statement.

What Expo class methods will let display output in a GUI window?

displayGUI

What statement is used with if for two-way selection?

else

What Expo class method is used to enter a single letter or character?

enterChar

What Expo class method is used to enter real number information?

enterDouble

What Expo class methods will let you use GUI windows to enter strings, integers, characters, and real numbers?

enterStringGUI,enterIntGUI,enterCharGUI,enterDoubleGUI

While program Java0511 compiles and executes, its output is strange. How does program Java0512 fix the problem?

it uses the break keyword

How do you repeat multiple statements with the for loop structure?

loop structures: the precondition while loop and the post condition do...while loop.

Explain Multiple-Way Selection.

multiple-way selection with case..break.

Refer to your answers to the previous question. What parameter do all of these methods need?

prompt which is a String

What are the 3 general types of control structures?

simple sequence, selection, and repetition

In one-way selection, what happens if the condition is false?

the program flow continues without change in program sequence.

What are the 3 types of Selection?

the second diagram shows two-way selection, and the third one shows multiple-way selection.


Ensembles d'études connexes

Management of Information Security CYBR 3300 - Chapter 10 Planning for Contingencies

View Set

Beyond basic Java -- Java Implementations/Servlets/JSPs/JDBC/JavaDocs

View Set

Ch 29 Management of Patients with Nonmalignant Hematologic Disorders

View Set

Psych Nursing Anxiety Disorders PrepU

View Set

Contracts - GA Salesperson Exam Prep Edge: National & State Portions

View Set

Section 5.1 Pure Substances and MIxtures

View Set

Psych Videbeck Chapter 20: Eating Disorders

View Set