1. Trang chủ
  2. » Kinh Doanh - Tiếp Thị

Introduction to java programming comprehensive version 10th edition by liang test bank

32 430 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 32
Dung lượng 442,93 KB

Nội dung

Java program public class Test1 { public static void mainString[] args { Scanner input = new ScannerSystem.in; System.out.print"Enter three numbers: ";... public class Test { public stat

Trang 1

Introduction to Java Programming Comprehensive Version 10th edition by Y Daniel Liang Test Bank

Link full download test bank: comprehensive-version-10th-edition-by-liang-test-bank/

https://findtestbanks.com/download/introduction-to-java-programming-Link full download solution manual: comprehensive-version-10th-edition-by-liang-solution-manual/

https://findtestbanks.com/download/introduction-to-java-programming-Chapter 2 Elementary Programming

Section 2.3 Reading Input from the Console

1 Suppose a Scanner object is created as follows:

Scanner input = new Scanner(System.in);

What method do you use to read an int value?

2 The following code fragment reads in two numbers:

Scanner input = new Scanner(System.in);

int i = input.nextInt();

double d = input.nextDouble();

What are the correct ways to enter these two numbers?

a Enter an integer, a space, a double value, and then the Enter key

b Enter an integer, two spaces, a double value, and then the Enter key

c Enter an integer, an Enter key, a double value, and then the Enter key

d Enter a numeric value with a decimal point, a space, an integer, and then the Enter key

Key:abc

6 _ is the code with natural language mixed with Java

code a Java program

public class Test1 {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

System.out.print("Enter three numbers: ");

Trang 2

chapter2.txt double number1 = input.nextDouble();

double number2 = input.nextDouble();

double number3 = input.nextDouble();

Trang 3

chapter2.txt Section 2.5 Variables

6 Which of the following are correct names for variables according to

Java naming conventions?

7 Which of the following are correct ways to declare variables?

a int length; int width;

b int length, width;

c int length; width;

d int length, int width;

Key:ab

#

Section 2.6 Assignment Statements and Assignment Expressions

8 is the Java assignment operator

Section 2.7 Named Constants

11 To declare a constant MAX_LENGTH inside a method with value 99.98, you write

a final MAX_LENGTH = 99.98;

Trang 4

Section 2.8 Naming Conventions

60 According to Java naming convention, which of the following names can

Section 2.9 Numeric Data Types and Operations

14 Which of these data types requires the most amount of memory?

Trang 5

15 Analyze the following code:

public class Test {

public static void main(String[] args) {

int n = 10000 * 10000 * 10000;

System.out.println("n is " + n);

}

}

a The program displays n is 1000000000000

b The result of 10000 * 10000 * 10000 is too large to be stored in an int variable n This causes an overflow and the program is aborted

c The result of 10000 * 10000 * 10000 is too large to be stored in an int variable n This causes an overflow and the program continues to execute

because Java does not report errors on overflow

d The result of 10000 * 10000 * 10000 is too large to be stored in an int variable n This causes an underflow and the program is aborted

e The result of 10000 * 10000 * 10000 is too large to be stored in an int variable

n This causes an underflow and the program continues to execute because Java does not report errors on underflow

Trang 7

Section 2.10 Numeric Literals

15 To declare an int variable number with initial value 2, you write

32 Analyze the following code

public class Test {

public static void main(String[] args) {

int month = 09;

System.out.println("month is " + month);

}

}

a The program displays month is 09

b The program displays month is 9

c The program displays month is 9.0

d The program has a syntax error, because 09 is an incorrect literal value

Key:d Any numeric literal with the prefix 0 is an octal value But 9 is not an octal

Trang 8

chapter2.txt digit An octal digit is 0, 1, 2, 3, 4, 5, 6, or 7

Section 2.11 Evaluating Expressions and Operator Precedence

24 The expression 4 + 20 / (3 - 1) * 2 is evaluated to

Section 2.12 Case Study: Displaying the Current Time

58 The System.currentTimeMillis() returns

a the current time

b the current time in milliseconds

c the current time in milliseconds since midnight

d the current time in milliseconds since midnight, January 1, 1970

e the current time in milliseconds since midnight, January 1, 1970 GMT (the Unix time)

Trang 9

Section 2.13 Augmented Assignment Operators

24 To add a value 1 to variable x, you write

b number = sum + number;

c sum = Number + sum;

Trang 10

a (A) and (B) are the same

b (A) and (C) are the same

c (B) and (C) are the same

d (A), (B), and (C) are the same

Key:a

#

Section 2.14 Increment and Decrement Operators

21 Are the following four statements equivalent?

Trang 11

chapter2.txt

#

34 What is i printed?

public class Test {

public static void main(String[] args)

35 What is i printed in the following code?

public class Test {

public static void main(String[] args) {

36 What is y displayed in the following code?

public class Test {

public static void main(String[] args) {

Trang 12

public class Test {

public static void main(String[] args) {

Section 2.15 Numeric Type Conversions

38 To assign a double variable d to a float variable x, you write

Trang 14

Section 2.16 Software Life Cycle

1 _ is a formal process that seeks to understand the problem

and document in detail what the software system needs to do

Trang 16

chapter2.txt Key:b

Trang 17

chapter2.txt Key:b

Trang 18

chapter2.txt Key:b

Trang 22

Sample Final Exam for CSCI 1302

FINAL EXAM AND COURSE OUTCOMES MATCHING

C OURSE O UTCOMES

Upon successful completion of this course, students should be able to

1 understand OO concepts: encapsulation, inheritance, polymorphism,

interfaces, abstract classes

2 use Unified Modeling Language for design, analysis, and documentation

3 develop graphical user interfaces

4 develop event-driven programs

5 use file I/O and handle exceptions

6 design and implement OO programs

Here is a mapping of the final comprehensive exam against the course outcomes:

Trang 23

Name: _ CSCI 1302 Introduction to Programming

Please note that the university policy prohibits giving the exam score by email If you need to know your final exam score, come to see me during my office hours next semester

I pledge by honor that I will not discuss the contents of this exam with anyone

Signed by _ Date _

1 Design and implement classes (10 pts)

Design a class named Person and its two subclasses named Student and Employee Make Faculty and Staff subclasses of Employee A person has

a name, address, phone number, and email address A student has a

class status (freshman, sophomore, junior, or senior) Define the

status as a constant An employee has an office, salary, and date

hired Define a class named MyDate that contains the fields year,

month, and day A faculty member has office hours and a rank A staff member has a title Override the toString method in each class to

display the class name and the person's name

Draw the UML diagram for the classes Write the code for the

Student class only

Trang 24

2 Design and use interfaces (10 pts)

Write a class named Octagon that extends GeometricObject and implements the Comparable and Cloneable interfaces Assume that all eight sides of the octagon are of equal size The area can be computed using the following formula:

area (2 4 / 2) * side * side

Draw the UML diagram that involves Octagon,

GeometricObject, Comparable, and Cloneable

Trang 25

3 Design and create GUI applications (10 pts)

Write a Java applet to add two numbers from text fields, and

displays the result in a non-editable text field Enable your

applet to run standalone with a main method A sample run of the applet is shown in the following figure

Trang 26

4 Text I/O (10 pts)

Write a program that will count the number of characters (excluding control characters '\r' and '\n'), words, and lines, in a file Words are separated by spaces, tabs, carriage return, or line-feed

characters The file name should be passed as a command-line

argument, as shown in the following sample run

Trang 27

5 Multiple Choice Questions: (1 pts each)

(1 Mark your answers on the sheet 2 Login and click Take

Instructor Assigned Quiz for QFinal 3 Submit it online

1 _ describes the state of an object

3 If a class named Student has no constructors defined

explicitly, the following constructor is implicitly provided

5 Suppose the xMethod() is invoked in the following constructor

in a class, xMethod() is _ in the class

6 Suppose the xMethod() is invoked from a main method in a class

as follows, xMethod() is _ in the class

public static void main(String[] args) {

Trang 28

run the following code?

public class Test {

a The output "Value is 0" is printed

b An "illegal array declaration syntax" compiler error occurs

c A "possible reference before assignment" compiler error occurs

d A runtime error occurs, because x is not initialized

#

8 Analyze the following code:

public class Test {

private int t;

public static void main(String[] args) {

Test test = new Test();

System.out.println(test.t);

}

}

a The variable t is not initialized and therefore causes errors

b The variable t is private and therefore cannot be accessed in the main method

c Since t is an instance variable, it cannot appear in the

static main method

d The program compiles and runs fine

#

9 Suppose s is a string with the value "java" What will

be assigned to x if you execute the following code?

char x = s.charAt(4);

a 'a'

b 'v'

c Nothing will be assigned to x, because the execution causes

the runtime error StringIndexOutofBoundsException

d None of the above

#

10 What is the printout for the following

code? class Test {

Trang 29

public static void main(String[] args)

{ int[] x = new int[3];

System.out.println("x[0] is "+x[0]);

}

}

a The program has a syntax error because the size of the

array wasn't specified when declaring the array

b The program has a runtime error because the array elements

are not initialized

c The program runs fine and displays x[0] is 0

d None of the above

#

11 How can you get the word "abc" in the main method from

the following call?

java Test "+" 3 "abc" 2

12 Which code fragment would correctly identify the number of

arguments passed via the command line to a Java application,

excluding the name of the class that is being invoked?

a int count = args.length;

b int count = args.length - 1;

c int count = 0; while (args[count] != null) count ++;

d int count=0; while (!(args[count].equals(""))) count ++;

#

13 Show the output of running the class Test in the following

code lines:

interface A { void print();

} class C {}

class B extends C implements A { public void print() { }

} class Test { public static void main(String[] args) { B b = new B();

if (b instanceof A) System.out.println("b is an instance of A"); if (b instanceof C)

System.out.println("b is an instance of C");

}

}

Trang 30

14 When you implement a method that is defined in a superclass, you

the original method

15 What modifier should you use on a variable so that it can only be

referenced inside its defining class

"The default constructor of A is invoked");

} } class B extends A { public B() { System.out.println(

"The default constructor of B is invoked");

} } public class C { public static void main(String[] args) {

B b = new B();

} }

a none

b "The default constructor of B is invoked"

c "The default constructor of A is invoked" followed by

"The default constructor of B is invoked"

d "The default constructor of A is invoked"

#

17 Analyze the following

program class Test {

Trang 31

public static void main(String[] args)

a An exception is raised due to Integer.parseInt(s);

b An exception is raised due to 2 / i;

c The program has a compilation error

d The program compiles and runs without exceptions

c The program displays Welcome to Java three times

d The program displays Welcome to Java two times

#

19 To append data to an existing file, use _ to construct a

FileOutputStream for file out.dat

a new FileOutputStream("out.dat")

b new FileOutputStream("out.dat", false)

c new FileOutputStream("out.dat", true) d

new FileOutputStream(true, "out.dat")

Trang 32

#

20 After the following program is finished, how many bytes are written to the file t.dat?

import java.io.*;

public class Test {

public static void main(String[] args) throws IOException

{ DataOutputStream output = new DataOutputStream(

Ngày đăng: 01/03/2019, 10:37

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

w