Test Bank for Horstmann Java For Everyone

Page 1


JFE Chapter: Chapter01: Introduction Test Bank

Multiple Choice

1. The programs that computer executes are called

A) Programming languages

B) Software

C) Integrated development environment

D) Browsers

Ans: B

Section Ref: 1.1

Title: TB 1.1 The programs that computer executes are called...

Difficulty: Easy

2. The ENIAC computer was build from which components:

A) Integrated circuits

B) Flash memory

C) Transistors

D) Vacuum tubes

Ans: D

Section Ref: 1.1

Title: TB 1.2 The ENIAC computer was build from which components... Difficulty: Medium

3. The Java code on the Internet and that are run by Web browsers are called:

A) Scripts

B) Applets

C) Databases

D) Style sheets

Ans: B

Section Ref: 1.2

Title: TB 1.3 The Java code on the Internet and that are run by Web browsers are called.... Difficulty: Medium

4. The free Java modules that perform various specific tasks and that make Java a rich and portable language are called:

A) Library packages

B) Portlets

C) Servlets

D) Style sheets

Ans: A

Section Ref: 1.2

Title: TB 1.4 The free Java modules that perform various specific tasks are called...

Difficulty: Medium

5. Which one of the following allows computers to be interconnected?

A) CPU

B) Networks

C) RAM

D) Graphics card

Ans: B

Section Ref: 1.2

Title: TB 1.5 What allows computers to be interconnected?

Difficulty: Easy

6. Which one of the following processes and displays images and pictures on computer screen?

A) CPU

B) Networks

C) RAM

D) Graphics card

Ans: D

Section Ref: 1.2

Title: TB 1.6 What processes and displays images and pictures on computer screen?

Difficulty: Easy

7. Which one of the following connects external input / output devices such as mouse, keyboard to a computer?

A) CPU

B) Networks

C) Ports

D) Graphics card

Ans: C

Section Ref: 1.2

Title: TB 1.7 What connects external input / output devices to computer?

Difficulty: Medium

8. Which one of the following statements is true about a Java compiler?

A) It translates the object code into the source code.

B) It translates the library code into the virtual machine code.

C) It translates the source code into the virtual machine code.

D) It translates the virtual machine code into the source code.

Ans: C

Section Ref: 1.2

Title: TB 1.8 Which statement is true about a Java compiler?

Difficulty: Easy

9. Which one of the following programs can execute Java class files?

A) Assembler

B) Linker

C) Editor

D) Virtual machine

Ans: D

Section Ref: 1.2

Title: TB 1.9 Which program can execute Java class files?

Difficulty: Medium

10. A digital image scanner that is connected to a computer is a(n):

A) CPU

B) Memory device

C) Input device

D) Output device

Ans: C

Section Ref: 1.2

Title: TB 1.10 What type of device is image scanner?

Difficulty: Easy

11. A digital music synthesizer that is connected to a computer is a(n):

A) CPU

B) Input and output device

C) Input device

D) Output device

Ans: B

Section Ref: 1.2

Title: TB 1.11 What type of device is music synthesizer?

Difficulty: Medium

12. In order to access email on the Internet, a computer has to be connected to a:

A) CPU

B) Network

C) Input device

D) Output device

Ans: B

Section Ref: 1.2

Title: TB 1.12 What is required to access email on Internet?

Difficulty: Easy

13. Java virtual machines are available for:

I. PC running Windows

II. Macintosh

III. Linux andUnix servers

A) I and II

B) I and III

C) II and III

D) I, II, and III

Ans: D

Section Ref: 1.2

Title: TB 1.13 Java virtual machines are available for ___

Difficulty: Medium

14. Is there anything wrong with this code?

System.out.print("3 + 3 =")

System.out.println(3 + 3);

A) compile-time error

B) run-time error

C) programming error

D) no error

Ans: A

Section Ref: 1.2

Title: TB 1.14 What error, if any, is in the code?

Difficulty: Medium

15. The first useful electrical computer is named:

A) Lisa

B) ENIAC

C) PDP

D) Atari

Ans: B

Section Ref: 1.2

Title: TB 1.15 The first useful electrical computer is named ___

Difficulty: Medium

16. Java can be used to develop rich applications for the Web that are called

A) Operating systems

B) Applets

C) Libraries

D) Cookies

Ans: B

Section Ref: 1.3

Title: TB 1.16 Java can be used to develop rich Web applications called ___

Difficulty: Medium

17. Java is a programming language that has the properties:

I. business-oriented

II. portable

III. high-level

A) I and II

B) I and III

C) II and III

D) II only

Ans: C

Section Ref: 1.3

Title: TB 1.17 Properties of Java are ___

Difficulty: Medium

18. Java can be used to develop:

I. business applications

II. consumer applications

III. Internet applications

A) I and II

B) I and III

C) II and III

D) I, II, and III

Ans: D

Section Ref: 1.3

Title: TB 1.18 Java can be used to develop ___

Difficulty: Medium

19. Java was originally designed to be used for:

A) Large business systems

B) Networks

C) Scientific devices

D) Consumer devices

Ans: D

Section Ref: 1.3

Title: TB 1.19 Java was originally designed to be used for?

Difficulty: Easy

20. Java can run on any machine with Windows, Macintosh, Linux because it is:

A) Deterministic

B) Modular

C) Complex

D) Portable

Ans: D

Section Ref: 1.3

Title: TB 1.20 Java runs on different machines because it is ______

Difficulty: Easy

21. Which Java version runs on some smart phones?

A) Micro edition

B) Enterprise edition

C) Gaming edition

D) Professional edition

Ans: A

Section Ref: 1.3

Title: TB 1.21 The Java version that runs on cell phones is ______

Difficulty: Medium

22. A major difference between C++ and Java is that:

A) C++ is a high-level, while Java is a low-level language

B) C++ is designed for consumers, while Java is designed for commerce

C) C++ is object-oriented, while Java is not

D) C++ is not portable, while Java is portable

Ans: D

Section Ref: 1.3

Title: TB 1.22 A major difference between C++ and Java is ______ Difficulty: Medium

23. An example of a Java integrated development environment is:

A) NetBeans

B) Turbo Pascal

C) Visual Studio .NET

D) PHP

Ans: A

Section Ref: 1.3

Title: TB 1.23 An example of Java integrated development environment is ______

Difficulty: Medium

24. Java is powerful because it is:

A) designed for students

B) designed for scientific and research applications

C) extended with a rich set of library packages for specific applications

D) used by the US Department of Defense

Ans: C

Section Ref: 1.3

Title: TB 1.24 Java is powerful because it is ______

Difficulty: Medium

25. Java can run on a smart phone because the smart phone has:

A) A Java virtual machine

B) An operating system

C) An Itune application

D) A digital camera

Ans: A

Section Ref: 1.3

Title: TB 1.25 Java can run on a smart phone because the smart phone has ______

Difficulty: Medium

26. Java and C++ has this similarity:

A) Both languages run in virtual machines

B) Both languages are case sensitive

C) Both languages are portable

D) Both languages are designed for consumer devices

Ans: B

Section Ref: 1.3

Title: TB 1.26 Java and C++ have this similarity _____

Difficulty: Medium

27. Who invented the Java programming language?

A) Albert Einstein

B) James Gosling

C) Bill Gates

D) Steve Job

Ans: B

Section Ref: 1.3

Title: TB 1.27 Who invented the Java programming language?

Difficulty: Easy

28. How much does it cost to have a Java integrated development environment?

A) $20

B) $50

C) Nothing

D) $100

Ans: C

Section Ref: 1.3

Title: TB 1.28 How much does it cost to have a Java integrated development environment?

Difficulty: Easy

29. Which company was Java created at?

A) Apple

B) Intel

C) Sun Microsystems

D) Microsoft

Ans: C

Section Ref: 1.3

Title: TB 1.29 Which company was Java created at?

Difficulty: Easy

30. To develop a complex Java program, we need to: I. Design an algorithm II. Write the program code III. Test run the program

A) I and II only B) II and III only C) I and III only D) I, II and III

Ans: D

Section Ref: 1.3

Title: TB 1.30 To develop a complex Java program, we need to ___

Difficulty: Medium

31. Java is a popular programming language because: I. It is designed for new programmers II. It is portable III. It has many useful library packages

A) I and II only B) II and III only C) I and III only D) I, II and III

Ans: B

Section Ref: 1.3

Title: TB 1.31 Java is a popular programming language because ___ Difficulty: Easy

32. What year was Java introduced to the public?

A) 1990 B) 1993 C) 1995 D) 1998

Ans: C

Section Ref: 1.3

Title: TB 1.32 What year was Java introduced to the public?

Difficulty: Medium

33. A Java class with the name Printer has to be saved using the source file name:

A) printer.java

B) Printer.java

C) Printer.txt

D) printer.java

Ans: B

Section Ref: 1.3

Title: TB 1.33 Java source file name

Difficulty: Medium

34. This statement starts the declaration of a class in Java:

A) public static void main(String[] args)

B) public class Classname

C) System.out.println("Hello, World!");

D) Java class

Ans: B

Section Ref: 1.3

Title: TB 1.34 This statement starts declaring a class in Java

Difficulty: Medium

35. This Java statement prints a blank line:

A) public static void main(String[] args)

B) System.out.print();

C) System.out.println();

D) System.out.Println();

Ans: C

Section Ref: 1.3

Title: TB 1.35 This statement prints a blank line

Difficulty: Medium

36. Which Java statement does not contain an error?

A) System.out.print(; B) System.out.print()

C) System.out.printl();

D) System.out.println();

Ans: D

Section Ref: 1.3

Title: TB 1.36 Which statement does not contain an error

Difficulty: Medium

37. In order to run Java programs on a computer, the computer needs to have software called a(n):

A) Assembler

B) Virtual machine

C) Windows

D) Debugger

Ans: B

Section Ref: 1.3

Title: TB 1.37 Software needed to run Java on a computer

Difficulty: Medium

38. In order to translate a Java program to a class file, the computer needs to have software called a(n):

A) Assembler

B) Virtual machine

C) Compiler

D) Debugger

Ans: C

Section Ref: 1.3

Title: TB 1.38 Software needed to translate Java source code

Difficulty: Medium

39. The Java statement "public static void main(String[] args)" declares a :

A) class

B) variable

C) constant

D) method

Ans: D

Section Ref: 1.3

Title: TB 1.39 The statement "public static void main(String[] args)" declares what?

Difficulty: Medium

40. A Java virtual machine is a:

A) Software

B) Hardware

C) Firmware

D) Applet

Ans: A

Section Ref: 1.3

Title: TB 1.40 A Java virtual machine is a ___ Difficulty: Medium

41. The latest Java Development Kit from Sun Micro Systems contains: I. Compiler II. Virtual machine III. Library packages

A) I and II only B) II and III only

C) I and III only

D) I, II and III

Ans: D

Section Ref: 1.3

Title: TB 1.41 The latest Java Development Kit from Sun Micro Systems contains ___ Difficulty: Medium

42. Some of the Java integrated development environments are: I. Eclipse II. NetBeans III. JBuilder

A) I and II only B) II and III only C) I and III only D) I, II and III

Ans: D

Section Ref: 1.4

Title: TB 1.42 Some of the Java integrated development environment are ___ Difficulty: Hard

43. Which of the following statements must you include in a Java class that can be executed by the virtual machine?

A) System.out.println(); B) // Hello

C) public static void main(String[] args)

D) return 0;

Ans: C

Section Ref: 1.5

Title: TB 1.43 Which statements should you include in executable class?

Difficulty: Easy

44. What is the output of the following code snippet? System.out.print("Hello"); System.out.println("Good Day!");

A) Hello Good Day!

B) Hello Good Day!

C) HelloGood Day!

D) No output due to compilation errors

Ans: C

Section Ref: 1.5

Title: TB 1.44 What is output of snippet ?

Difficulty: Medium

45. Which one of the following code snippets compiles without errors and displays the output "Hello Good Day!" on the screen?

A) System.out.print("Hello "); System.out.println("Good Day!");

B) System.out.print("Hello ); System.out.println("Good Day!");

C) System.out.print("Hello "); System.out.println("Good Day!")

D) System.out.print("Hello "); System.out.println(Good Day!");

Ans: A

Section Ref: 1.5

Title: TB 1.45 Which snippet compiles without errors and displays “Hello Good Day!”?

Difficulty: Easy

46. Which one of the following code snippets represents the correct way to print the following output? GOOD MORNING "AMERICA"

A) System.out.println("GOOD MORNING"); System.out.println("AMERICA");

B) System.out.println("GOOD MORNING");

System.out.println("\"AMERICA\"");

C) System.out.println("GOOD MORNING"); System.out.println(""AMERICA"");

D) System.out.print("GOOD MORNING"); System.out.println("AMERICA");

Ans: B

Section Ref: 1.5

Title: TB 1.46 Which snippet correctly prints (double quotes)? Difficulty: Hard

47. What is the output of the following code snippet? public class PrintIt

{ public static void main(String[] args) { System.out.println("4 * 4" + 12); }

A) 4 * 412

B) 4412

C) 1612

D) 28

Ans: A

Section Ref: 1.5

Title: TB 1.47 What is output of snippet (with expressions)? Difficulty: Hard

48. What is the output of the following code snippet? public class PrintIt { public static void main(String[] args) { System.out.println( "\"System.out.println()\" prints out a new line to"); System.out.println("the standard output stream"); }

}

A) The code snippet gives a compilation error

B) prints out a new line to the standard output stream

C) System.out.println() prints out a new line to the standard output stream

D) "System.out.println()" prints out a new line to the standard output stream

Ans: D

Section Ref: 1.5

Title: TB 1.48 What is the output of snippet (with complex string)?

Difficulty: Medium

49. The following code snippet is written to calculate the mileage (miles per gallon) of two cars and print out both values.

public class PrintMileage { public static void main(String[] args) { int distance1 = 600; int distance2 = 800; int gallon1 = 15; int gallon2 = 20;

System.out.println(gallon1 / distance1); System.out.println(distance2 / gallon2); }

}

Based on the given code snippet, identify the correct statement:

A) The output is correct, and there are no errors.

B) The mileage of the first car is calculated correctly, but the mileage of the second car is incorrect due to a run-time error.

C) The mileage of the second car is calculated correctly, but the mileage of the first car is incorrect due to a run-time error.

D) The mileage of both cars is incorrect due to a run-time error.

Ans: C

Section Ref: 1.6

Title: TB 1.49 Which is true about this snippet that calculates and prints mileage?

Difficulty: Hard

50. Is there anything wrong with this code?

System.out.println(6/3 – 2);

A) compile-time error

B) run-time error

C) programming error

D) no error

Ans: D

Section Ref: 1.6

Title: TB 1.50 What error, if any, is in the code?

Difficulty: Medium

51. Is there anything wrong with this code?

system.out.println(6/3 – 2);

A) compile-time error

B) run-time error

C) programming error

D) no error

Ans: A

Section Ref: 1.6

Title: TB 1.51 What error, if any, is in the code?

Difficulty: Medium

52. Is there anything wrong with this code?

System.out.print("3 + 3 =");

System.out.println(3 * 3);

A) compile-time error

B) run-time error

C) programming error

D) no error

Ans: B

Section Ref: 1.6

Title: TB 1.52 What error, if any, is in the code?

Difficulty: Medium

53. Is there any error in the following code snippet, which is used for calculating the average age for a group of three students?

public class PrintAverage { public static void main(String[] args) { int age1 = 15; int age2 = 18; int age3 = 24;

int average = age1 + (age2 + age3) / 3;

System.out.print("The average is ");

System.out.println(average); } }

A) Yes, the code snippet has a syntax error.

B) Yes, the code snippet has a programming error.

C) Yes, the code snippet has a run-time error.

D) No error; the code snippet is completely accurate.

Ans: C

Section Ref: 1.6

Title: TB 1.53 Is there an error in snippet that calculates average age?

Difficulty: Hard

54. Does this code contain error? If yes, which type? System.out.printl("Hello");

A) compile-time error

B) run-time error

C) programming error

D) no error

Ans: A

Section Ref: 1.6

Title: TB 1.54 What error, if any, is in the code?

Difficulty: Medium

55. What type of error can you identify in the following code snippet? public class Division { public static void main(String[] args) { int a = 10; int b = 0; int c = a / b; } }

A) A logical error.

B) A compile-time error.

C) A run-time error.

D) No errors; the code snippet is completely accurate.

Ans: C

Section Ref: 1.6

Title: TB 1.55 What type of error is in this snippet?

Difficulty: Medium

56. What is the purpose of the following algorithm? num = 0

Repeat the following steps for 100 times input var1 if var1 > num num = var1

print num

A) To find the highest among 100 numbers

B) To print out the 100 numbers

C) To find the smallest among 100 numbers

D) To search for a particular number among 100 numbers

Ans: A

Section Ref: 1.7

Title: TB 1.56 What is the purpose of this algorithm?

Difficulty: Medium

57. Consider a situation where you are buying books online. The bookseller charges $19.95 as the price per book and $4.95 as the handling cost for up to three books. For every book purchased in addition to three books, there is a handling charge of $1.50. In addition, there is a 7% tax on the cost of the books but not on the handling charges. Assuming that num_books represents the number of books you are purchasing, which of the following is the correct algorithm for calculating the total cost of the books that you are purchasing?

A) Total charge for the books = 19.95 * num_books

Tax on the books = num_books * .7 if books <= 3

Handling charges = 4.95 else

Handling charges = 1.50 * num_books

Total cost of order = total charge for books + tax + handling charges

B) Total charge for the books = 19.95 * num_books

Tax on the books = num_books * .07 if books <= 3

Handling charges = 4.95 else

Handling charges = 1.50 * num_books

Total cost of order = total charge for books + tax + handling charges

C) Total charge for the books = 19.95 * num_books

Tax on the books = num_books * .07 if books < 3

Handling charges = 4.95 else

Handling charges = 4.95 + 1.50 * (num_books – 3)

Total cost of order = total charge for books + tax + handling charges

D) Total charge for the books = 19.95 * num_books

Tax on the books = num_books * .07 if books <= 3

Handling charges = 4.95 else

Handling charges = 4.95 + 1.50 * (num_books – 3)

Total cost of order = total charge for books + tax + handling charges

Ans: D

Section Ref: 1.7

Title: TB 1.57 Which is the correct algorithm for calculating total cost with tax/shipping?

Difficulty: Hard

58. Consider a situation where you are planning on purchasing a new cell phone. You are considering two cell phones. These cell phones have different purchase prices. Each mobile service provider charges a different rate for each minute that the cell phone is used. To determine which cell phone is a better buy, you need to develop an algorithm to can calculate the total cost of purchasing and using each cell phone. What are all the inputs needed for this algorithm?

A) The cost of each cell phone and the rate for each minute for each cell phone

B) The cost of each cell phone and the number of minutes provided with each cell phone

C) The cost of each cell phone, the rate of using each cell phone, and the number of minutes provided with each cell phone

D) The cost of each cell phone, the rate of using each cell phone, and the number of minutes you would use the cell phone

Ans: D

Section Ref: 1.7

Title: TB 1.58 Which inputs do you need to calculate cost of purchasing/using cell phone?

Difficulty: Medium

59. Which one of the following methodologies is an informal description of a sequence of steps for solving a problem?

A) Flowcharts

B) Pseudocode

C) Algorithms

D) Terminations

Ans: B

Section Ref: 1.7

Title: TB 1.59 Which methodology is an informal description of steps for solving a problem?

Difficulty: Easy

60. Consider a situation where you are assigned to develop an algorithm to calculate the total cost of a purchase order that contains several items. The cost of each item and the tax rate is known. The standard shipping charge for the entire order is $4.95, and the special delivery charge is $19.95. In addition, there is no tax on the shipping cost. Which of the following is the correct pseudocode for the required algorithm?

A) For each item on the purchase order

Order cost = order cost + item cost

Total purchase order cost = order cost + tax rate + 4.95

B) For each item on the purchase order

Order cost = order cost + item cost

If standard shipping

Shipping cost = 4.95

Else

Shipping cost = 19.95

Total purchase order cost = order cost * tax rate + shipping cost

C) If standard shipping

Shipping cost = 4.95

Else

Shipping cost = 19.95

For each item on the purchase order

Order cost = order cost + item cost + shipping cost

Total purchase order cost = order cost * tax rate

D) If special delivery

Shipping cost = 4.95

Else

Shipping cost = 19.95

For each item on the purchase order

Order cost = order cost + item cost

Total purchase order cost = order cost * tax rate + shipping cost

Ans: B

Section Ref: 1.7

Title: TB 1.60 Which is the correct pseudocode for algorithm to calculate total cost? Difficulty: Medium

61. Consider the given scenario for describing an algorithm using pseudocode. UML Supermarket has different ways of awarding discounts to its customers for each purchase they make. A 10% discount is given on the total value of the purchase. In addition, a standard loyalty discount is given if customers have a permanent customer card. Your program should indicate the amount payable by the customer after the discounts. Identify the inputs that the program requires from the given set of options.

I. The discount percentage

II. The total value of the purchase

III. The loyalty-discount amount

IV. The amount payable after discount

A) I, II, and III

B) I and III

C) II, III, and IV

D) II and III

Ans: D

Section Ref: 1.7

Title: TB 1.61 What are the inputs required to solve this problem?

Difficulty: Hard

62. Evaluate the given pseudocode to calculate the payment (pmt) with the following test values: The total number of hours worked (working_hours) = 50

The rate paid for hourly work (rate) = 10 input working_hours

input rate

pmt = working_hours * rate if working_hours > 45 extra_hours = working_hours – 45

extra_pmt = extra_hours * rate * 2

pmt = pmt + extra_pmt output pmt

A) 400

B) 500

C) 600

D) 1,000

Ans: C

Section Ref: 1.7

Title: TB 1.62 Evaluate this pseudocode with these test values. Difficulty: Hard

63. What is the purpose of the following algorithm? somenum = 0

Repeat the following steps for 50 times input variable1 if variable1 > somenum then somenum = variable1 print somenum

A) To find the highest among 50 numbers

B) To print out the 50 numbers

C) To find the smallest among 50 numbers

D) To search for a particular number among 50 numbers

Ans: A

Section Ref: 1.7

Title: TB 1.63 What is the purpose of this algorithm?

Difficulty: Medium

64. Consider a situation where you are buying videos online. The videoseller charges $21.50 as the price per video and $6.75 as the handling cost for up to three videos. For every video purchased in addition to three videos, there is a handling charge of $1.50. In addition, there is a 9% tax on the cost of the videos but not on the handling charges. Assuming that num_videos represents the number of videos you are purchasing, which of the following is the correct algorithm for calculating the total cost of the videos that you are purchasing?

A)

Total charge for the videos = 21.50 * num_videos

Tax on the videos = num_videos * .9 if (num_videos <= 3)

Handling charges = 6.75 else

Handling charges = 1.50 * num_videos

Total cost of order = total charge for videos + tax + handling charges

B)

Total charge for the videos = 21.50 * num_videos

Tax on the videos = num_videos * .09 if (num_videos <= 3)

Handling charges = 6.75 else

Handling charges = 1.50 * num_videos

Total cost of order = total charge for videos + tax + handling charges

C)

Total charge for the videos = 21.50 * num_videos

Tax on the videos = num_videos * .09 if (num_videos < 3)

Handling charges = 6.75 else

Handling charges = 6.75 + 1.50 * (num_videos – 3)

Total cost of order = total charge for videos + tax + handling charges

D)

Total charge for the videos = 21.50 * num_videos

Tax on the videos = total charge for videos * .09 if (num_videos <= 3)

Handling charges = 6.75 else

Handling charges = 6.75 + 1.50 * (num_videos – 3)

Total cost of order = total charge for videos + tax + handling charges

Ans: D

Section Ref: 1.7

Title: TB 1.64 Which is the correct algorithm for calculating total cost with tax/shipping?

Difficulty: Hard

65. Consider a situation where you are planning on purchasing a new cable TV dish. You are considering two cable TV dishes. These cable TV dishes have different purchase prices. Each channel service provider charges a different rate for each month that the cable TV dish is used. To determine which cable TV dish is a better buy, you need to develop an algorithm to calculate the total cost of purchasing and using each cable TV dish. What are all of the inputs that you need for this algorithm?

A) The cost of each cable TV dish and the rate for each month for each cable TV dish

B) The cost of each cable TV dish and the number of months provided with each cable TV dish

C) The cost of each cable TV dish, the rate of using each cable TV dish, and the number of months provided with each cable TV dish

D) The cost of each cable TV dish, the rate of using each cable TV dish, and the number of months you would use the cable TV dish

Ans: D

Section Ref: 1.7

Title: TB 1.65 Which inputs do you need to calculate cost of purchasing/using cable dish?

Difficulty: Medium

66. Consider a situation where you are assigned to develop an algorithm to calculate the total cost of a purchase order that contains several T shirts. The cost of each T shirt and the tax rate is known. The standard shipping charge for the entire order is $5.75, and the special delivery charge is $23.65. In addition, there is no tax on the shipping cost. Which of the following is the correct pseudocode for the required algorithm?

A)

B)

C)

For each T shirt on the purchase order

Order cost = order cost + T shirt cost

Total purchase order cost = order cost + tax rate + 5.75

For each T shirt on the purchase order

Order cost = order cost + T shirt cost

If standard shipping

Shipping cost = 5.75

Else

Shipping cost = 23.65

Total purchase order cost = order cost * tax rate + shipping cost

If standard shipping

Shipping cost = 5.75

Else

Shipping cost = 23.65

For each T shirt on the purchase order

Order cost = order cost + T shirt cost + shipping cost

Total purchase order cost = order cost * tax rate

If special delivery

Shipping cost = 5.75

Else

Shipping cost = 23.65

For each T shirt on the purchase order

Order cost = order cost + T shirt cost

Total purchase order cost = order cost * tax rate + shipping cost

Ans: B

Section Ref: 1.7

Title: TB 1.66 Which is the correct pseudocode for algorithm to calculate total cost?

Difficulty: Medium

67. Consider the given scenario for describing an algorithm using pseudocode. WALMART Supermarket has different ways of awarding discounts to its customer IDs for each purchase they make. A 8% discount is given on the total value of the purchase. In addition, a standard loyalty discount is given if customers have a permanent customer ID card. Your program should indicate the amount payable by the customer after the discounts. Identify the inputs that the program requires from the given set of options.

I. The discount percentage

II. The total value of the purchase

III. The loyalty-discount amount

IV. The amount payable after discount

A) I, II, and III

B) I and III

C) I, II, and IV

D) II and III

Ans: D

Section Ref: 1.7

Title: TB 1.67 What are the inputs required to solve this problem?

Difficulty: Hard

68. Evaluate the given pseudocode to calculate the payment (pmt) with the following test values:

The total number of hours worked (working_hours) = 60

The rate paid for hourly work (rate) = 15 input working_hours input rate

pmt = working_hours * rate if working_hours > 40

extra_hours = working_hours – 40 xtra_pmt = extra_hours * rate * 2

pmt = pmt + extra_pmt

output pmt

A) 900

B) 1,200

C) 1,500

D) 1,800

Ans: C

Section Ref: 1.7

Title: TB 1.68 Evaluate this pseudocode with these test values.

Difficulty: Hard

69. Consider the following pseudocode. What does it produce?

Create a list of consecutive integers from two to n: (2, 3, 4, ..., n).

Initially, let p equal 2.

Repeat following steps until p2 is greater than n

Strike from the list all multiples of p less than or equal to n.

Find the first number remaining on the list greater than p; replace p with this number.

A) All even numbers up to n

B) All Fibonacci numbers up to n

C) All prime numbers up to n

D) All factorial numbers up to n

Ans: C

Section Ref: 1.7

Title: TB 1.69 What does the algorithm produce?

Difficulty: Hard

70. Consider the following pseudocode, what does it produce?

Set n = 1

Set p = 1

Repeat until n equals 20

Multiply p by 2 and store result in p

Add 1 to n

Print p

A) The product of first 20 even numbers

B) Two raised to the power 20

C) The product of first 20 numbers

D) Factorial of 20

Ans: B

Section Ref: 1.7

Title: TB 1.70 What does the algorithm produce?

Difficulty: Medium

71. Consider the following pseudocode, what does it produce?

Set n = 1

Set p = 0

Set s = 0

Repeat until n equals 10

Calculate the square of n and store in s

Add s to p

Add 1 to n

Print p

A) The product of first 10 even numbers

B) Two raised to the power 10

C) The product of first 10 numbers

D) Sum of square of numbers between 1 and 10

Ans: D

Section Ref: 1.7

Title: TB 1.71 What does the algorithm produce?

Difficulty: Medium

72. Consider the following pseudocode, what does it produce?

Set n = 0

Set a = 0

Set b = 1

Set p = 1

Print p

Repeat until n equals 10

Set p = a + b

Set a = b

Set b = p

Add 1 to n

Print p

A) 1 3 5 7 9 11 13 15 17 19 21 B) 1 1 2 3 5 8 13 21 34 55 89

C) 1 2 3 4 5 6 7 8 9 10 11

D) 1 3 6 9 12 15 18 21 24 27 30

Ans: B

Section Ref: 1.7

Title: TB 1.72 What does the algorithm produce?

Difficulty: Hard

73. Consider the following pseudocode, what does it produce?

Set n = 1

Set p = 1

Repeat until n equals 6

Multiply p by n and store result in p

Add 1 to n Print p

Ans: A

Section Ref: 1.7

Title: TB 1.73 What does the algorithm produce?

Difficulty: Medium

74. Evaluate the given pseudocode to calculate the payment (pmt) with the following test values: The total number of hours worked (working_hours) = 70

The rate paid for hourly work (rate) = 20

input working_hours

input rate

pmt = working_hours * rate if working_hours > 40

extra_hours = working_hours – 40

xtra_pmt = extra_hours * rate * 2

pmt = pmt + extra_pmt

output pmt

A) 2,200

B) 2,400

C) 2,600

D) 2,800

Ans: C

Section Ref: 1.7

Title: TB 1.74 Evaluate this pseudocode with these test values.

Difficulty: Hard

Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.