web viewjava applications are commonly used to create online amortization calculators for current...

94
ITT TECHNICAL INSTITUTE SD1420 Introduction to Java Programming Onsite Course GRADED ASSIGNMENTS -1- 11/14/2013

Upload: ngoxuyen

Post on 31-Jan-2018

227 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

ITT TECHNICAL INSTITUTE

SD1420Introduction to Java Programming

Onsite Course

GRADED ASSIGNMENTS

-1- 11/14/2013

Page 2: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

Table of ContentsGRADED ASSIGNMENTS..............................................................................................2

Unit 1 Assignment 1: Similarities and Differences of Different Programming Languages.........2

Unit 2 Assignment 1: Research Questions................................................................................4

Unit 3 Assignment 1: Programming Questions..........................................................................6

Unit 4 Assignment 1: Java Questions........................................................................................7

Unit 5 Assignment 1: Programming Questions........................................................................20

Unit 6 Assignment 1: Object Questions...................................................................................27

Unit 7 Assignment 1: Interface Questions................................................................................37

Unit 8 Assignment 1: Exception Handling Questions...............................................................43

Unit 9 Assignment 1: Classes Questions.................................................................................44

Unit 10 Assignment 1: GUI Questions.....................................................................................52

PROJECT......................................................................................................................57Project Part 1: Mortgage Rate Calculator................................................................................57

Project Part 2: Enhanced Mortgage Rate Calculator...............................................................58

Final Project Grading...............................................................................................................59

Writing Assignment Rubric.......................................................................................................61

Question Assignment Rubric...................................................................................................62

-2- 11/14/2013

Page 3: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

Graded Assignments

Unit 1 Assignment 1: Similarities and Differences between Different Programming Languages

Course Objectives and Learning Outcomes Describe the fundamentals of the Java programming language.

Explain the features of the Java Language Specification.

Distinguish among the terms API, JDK, and IDE.

Assignment RequirementsImagine that you work for an organization that wants to create a new application for internal use. Once

the application runs solidly in the internal arena, the company wants to release it on their website for

broader use and applicability. As a developer in the IT department, you must analyze the similarities and

differences of several different programming languages to determine which one will be the best for these

project goals.

Be sure to cover Java as one of the programming languages in your analysis. Use specific details about

the Language Specification and use Java-related terms and components from your textbook.

Tasks Select the type of application (time keeping, budgeting, sales forecasting, contact management,

etc.).

Use the ITT Tech Virtual Library to find the similarities and differences between Java, C++, .NET,

BASIC, and Visual Basic.

Present your findings in a report listing and comparing the features of each programming

language.

Explain which language you would recommend to the company to achieve the desired goal.

Cite your sources using APA format.

Submit your report in a Word document to your instructor at the beginning of Unit 2.

Required Resources ITT Tech Virtual Library

Submission Requirements Format: Microsoft Word, double-spaced

Font: 12-point Times New Roman

-3- 11/14/2013

Page 4: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

Citation Style: APA

Length: 1–2 pages

Due By: Unit 2

Evaluation CriteriaThis assignment will be graded using the Writing Assignment Rubric. The rubric is at the end of this

document.

-4- 11/14/2013

Page 5: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

Unit 2 Assignment 1: Research Questions

Course Objectives and Learning Outcomes Describe the fundamentals of the Java programming language.

Identify and debug programming errors.

Implement selection control using if statements.

Implement selection control using switch statements.

Distinguish between while and do-while loops.

Assignment RequirementsAnswer the following questions in writing. Use the textbook or the ITT Tech Virtual Library to find the

answers. Present your findings in the form of a numbered answer list.

1. What is the definition of an algorithm?

2. What does a variable represent in a computer’s memory?

3. What are the meanings of the (+) sign in Java?

4. What is the standard output device and standard input device for Java?

5. What is the difference between the print method and println method?

6. What is the definition of an expression?

7. A ______ _______ is an identifier that represents a permanent value.

8. What are the three benefits of using constants?

9. What are the five standard arithmetic operators?

10. What is the definition of a literal?

11. What are the six Java comparison operators?

12. What is the definition of an if-else statement?

13. What are some of the common errors in selection statements?

14. What logical operators can be used to create a compound Boolean expression?

15. A switch statement executes statements based on what factors?

16. What is the definition of a while loop?

17. What is the difference between a do-while loop and a while loop?

18. What is the definition of break?

19. What is the definition of continue?

20. What is the definition of a sentinel value?

Required Resources ITT Tech Virtual Library

Textbook

-5- 11/14/2013

Page 6: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

Submission Requirements Format: Microsoft Word, double-spaced

Font: 12-point, Times New-Roman

Citation style: APA

Length: 1–2 pages

Due by: Unit 3

Evaluation CriteriaThis assignment will be graded using the Question Assignment Rubric. The rubric is found at the end of

this document.

-6- 11/14/2013

Page 7: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

Unit 3 Assignment 1: Programming Questions

Course Objectives and Learning Outcomes Use the for loop to control the counting and indexing of statements.

Write and use nested loops.

Assignment RequirementsAnswer the following questions in writing. Use the textbook or the ITT Tech Virtual Library to find the

answers. Present your findings in the form of a numbered answer list.

1. Write down the Java programming code to convert Decimal to Hexadecimal.

2. Describe what the Math.random does.

3. Give an example of method overloading.

4. What is the difference between “top-down” and “bottom-up” implementation?

5. What are the benefits of Stepwise Refinement?

6. A variable declared in a method is called a ___ ____.

7. Compile a list of all the API of ArrayList.

8. Explain the differences between regular array and ArrayList.

9. Write down the Java programming code for Insertion Sort.

10. Assuming a sorted array, describe whether binary or linear searches are more efficient in finding

elements of an array.

Required Resources ITT Tech Virtual Library

Textbook

Submission Requirements Format: Microsoft Word, double-spaced

Font: 12-point, Times New-Roman

Citation Style: APA

Length: 1–2 pages

Due by: Unit 4

Evaluation CriteriaThis assignment will be graded using the Question Assignment Rubric. The rubric is found at the end of

this document.

-7- 11/14/2013

Page 8: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

Unit 4 Assignment 1: Java Questions

Course Objectives and Learning Outcomes Describe the fundamentals of the Java programming language.

Write Java programs by using user-defined methods for real-world objects.

Use classes to model objects.

Explain the role of constructors when creating objects.

Use classes in the Java library (examples: java.math, java.awt.image, java.security, etc.).

Differentiate among static variables, constants, and methods.

Identify the various visibility modifiers.

Declare private data fields with appropriate get and set methods for data field encapsulation to

make classes easy to maintain.

Determine the scope of variables in the context of a class.

Assignment RequirementsAnswer the following multiple-choice questions. Present your answers as a written, numbered list of

answer choices (1. a.; 2. b.; etc.).

1. Analyze the following code:

class TempClass { int i; public void TempClass(int j) { int i = j; }}

public class C { public static void main(String[] args) { TempClass temp = new TempClass(2); }}

What will happen when the code is executed?

a. The program compiles and runs fine.

b. The program has a compilation error because TempClass does not have a constructor

with an int argument.

c. The program compiles fine, but it does not run because class C is not public.

d. The program has a compilation error because TempClass does not have a default

constructor.

-8- 11/14/2013

Page 9: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

2. Analyze the following code:

public class Test { public static void main(String[] args) { Count myCount = new Count(); int times = 0;

for (int i=0; i<100; i++) increment(myCount, times);

System.out.println( "myCount.count = " + myCount.count); System.out.println("times = "+ times); }

public static void increment(Count c, int times) { c.count++; times++; }}

class Count { int count;

Count(int c) { count = c; }

Count() { count = 1; }}

What will be the value of “times”?

a. 100

b. 98

c. 99

d. 0

e. 101

-9- 11/14/2013

Page 10: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

3. What is the printout of the second println statement in the main method?

public class Foo { int i; static int s;

public static void main(String[] args) { Foo f1 = new Foo(); System.out.println("f1.i is " + f1.i + " f1.s is " + f1.s); Foo f2 = new Foo(); System.out.println("f2.i is " + f2.i + " f2.s is " + f2.s); Foo f3 = new Foo(); System.out.println("f3.i is " + f3.i + " f3.s is " + f3.s); }

public Foo() { i++; s++; }}

a. f2.i is 2 f2.s is 2

b. f2.i is 1 f2.s is 2

c. f2.i is 1 f2.s is 1

d. f2.i is 2 f2.s is 1

-10- 11/14/2013

Page 11: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

4. What is the printout for the first statement in the following main method?

public class Foo { static int i = 0; static int j = 0;

public static void main(String[] args) { int i = 2; int k = 3; { int j = 3; System.out.println("i + j is " + i + j); }

k = i + j; System.out.println("k is " + k); System.out.println("j is " + j); }}

a. i + j is 23

b. i + j is 5

c. i + j is 22

d. i + j is 6

-11- 11/14/2013

Page 12: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

5. Analyze the following code:

public class Test { int x; public Test(String t) { System.out.println("Test"); }

public static void main(String[] args) { Test test = null; System.out.println(test.x); }}

What will happen when the code is executed?

a. The program has a syntax error because Test is not initialized.

b. The program has a syntax error because Test does not have a default constructor.

c. The program has a syntax error because x has not been initialized.

d. The program has a syntax error because an object cannot be created from the class that

defines the object.

e. The program has a runtime NullPointerException because Test is null while executing

test.x.

-12- 11/14/2013

Page 13: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

6. What is the printout of the third println statement in the main method?

public class Foo { int i; static int s;

public static void main(String[] args) { Foo f1 = new Foo(); System.out.println("f1.i is " + f1.i + " f1.s is " + f1.s); Foo f2 = new Foo(); System.out.println("f2.i is " + f2.i + " f2.s is " + f2.s); Foo f3 = new Foo(); System.out.println("f3.i is " + f3.i + " f3.s is " + f3.s); }

public Foo() { i++; s++; }}

a. f3.i is 3 f3.s is 1

b. f3.i is 1 f3.s is 3

c. f3.i is 1 f3.s is 1

d. f3.i is 3 f3.s is 3

e. f3.i is 1 f3.s is 2

7. Analyze the following code:

class Circle { private double radius; public Circle(double radius) { radius = radius; }}

What will happen when the code is executed?

a. The program does not compile because Circle does not have a default constructor.

b. The program has a compilation error because radius cannot be assigned to radius.

c. The program will compile, but an object of Circle cannot be created with a specified

radius. The object will always have radius 0.

d. The program has a compilation error because it does not have a main method.

-13- 11/14/2013

Page 14: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

8. Given the declaration Circle[] x = new Circle[10], which of the following statements is most

accurate?

a. x contains an array of 10 int values.

b. x contains an array of 10 objects of the Circle type.

c. x contains a reference to an array, and each element in the array can hold a Circle

object.

d. x contains a reference to an array, and each element in the array can hold a reference to

a Circle object.

9. Analyze the following code:

public class Test { public static void main(String[] args) { double radius; final double PI= 3.15169; double area = radius * radius * PI; System.out.println("Area is " + area); }}

What will happen when the code is executed?

a. The program has a syntax error because a constant PI is defined inside a method.

b. The program compiles and runs fine.

c. The program has a syntax error because the variable radius is not initialized.

d. The program has no syntax errors but will get a runtime error because radius is not

initialized.

10. Suppose you want to provide an accessor method for a Boolean property Finished. What should

the signature of the method be?

a. public boolean getFinished()

b. public void isFinished()

c. public boolean isFinished()

d. public void getFinished()

-14- 11/14/2013

Page 15: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

11. Analyze the following code:

public class Test { private int t;

public static void main(String[] args) { int x; System.out.println(t); }}

What will happen when the code is executed?

a. The variable t is private and, therefore, cannot be accessed in the main method.

b. The variable x is not initialized and, therefore, causes errors.

c. The variable t is non-static, and it cannot be referenced in a static context in the main

method.

d. The variable t is not initialized and, therefore, causes errors.

e. The program compiles and runs fine.

12. Analyze the following code:

public class Test { int x;

public Test(String t) { System.out.println("Test"); }

public static void main(String[] args) { Test test = new Test(); System.out.println(test.x); }}

What will happen when the code is executed?

a. The program has a syntax error because an object cannot be created from the class that

defines the object.

b. The program has a syntax error because Test does not have a default constructor.

c. The program has a syntax error because System.out.println method cannot be invoked

from the constructor.

d. The program has a syntax error because x has not been initialized.

-15- 11/14/2013

Page 16: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

13. Which of the following is an advantage of encapsulation?

a. Making the class final causes no consequential changes to other code.

b. Encapsulation changes a class’s contract without changing the implementation and

causes no consequential changes to other code.

c. Encapsulation changes the implementation without changing a class’s contract and

causes no consequential changes to other code.

d. Only public methods are needed.

14. Analyze the following code:

public class Test { public static void main(String[] args) { int n = 2; xMethod(n); System.out.println("n is " + n); }

void xMethod(int n) { n++; }}

What will happen when the code is executed?

a. The code prints n as 1.

b. The code prints n as 3.

c. The code has a syntax error because xMethod is not declared static.

d. The code has a syntax error because xMethod does not return a value.

e. The code prints n as 2.

-16- 11/14/2013

Page 17: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

15. Analyze the following code and choose the best answer.

public class Foo { private int x;

public static void main(String[] args) { Foo foo = new Foo(); System.out.println(foo.x); }}

a. Because x is defined in the class Foo, it can be accessed by any method inside the class

without using an object. The code can be written to access x without creating an object,

such as foo, in this code.

b. A self-referenced object cannot be created; that is, foo is created inside the class Foo.

c. Because x is an instance variable, it cannot be directly used inside a main method.

However, it can be accessed through an object such as foo in this code.

d. Because x is private, it cannot be accessed from an object foo.

16. Analyze the following code:

public class Test { public static void main(String args[]) { NClass nc = new NClass(); nc.t = nc.t++; }}

class NClass { int t; private NClass() { }}

What will happen when the code is executed?

a. The program compiles but has a runtime error because t has no initial value.

b. The program compiles and runs fine.

c. The program has a compilation error because the NClass class has a private constructor.

d. The program does not compile because the parameter list of the main method is wrong.

-17- 11/14/2013

Page 18: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

17. What is the printout for the third statement in the main method?

public class Foo { static int i = 0; static int j = 0;

public static void main(String[] args) { int i = 2; int k = 3; { int j = 3; System.out.println("i + j is " + i + j); }

k = i + j; System.out.println("k is " + k); System.out.println("j is " + j); }}

a. j is 0

b. j is 2

c. j is 1

d. j is 3

18. To declare a constant MAX_LENGTH as a member of the class, you write which of the following?

a. static double MAX_LENGTH = 99.98;

b. final static float MAX_LENGTH = 99.98;

c. final double MAX_LENGTH = 99.98;

d. final static double MAX_LENGTH = 99.98;

e. final static MAX_LENGTH = 99.98;

-18- 11/14/2013

Page 19: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

19. What is the value of myCount.count displayed?

public class Test { public static void main(String[] args) { Count myCount = new Count(); int times = 0;

for (int i=0; i<100; i++) increment(myCount, times);

System.out.println( "myCount.count = " + myCount.count); System.out.println("times = "+ times); }

public static void increment(Count c, int times) { c.count++; times++; }}

class Count { int count;

Count(int c) { count = c; }

Count() { count = 1; }}

a. 100

b. 101

c. 99

d. 98

-19- 11/14/2013

Page 20: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

20. What is the printout for the second statement in the main method?

public class Foo { static int i = 0; static int j = 0;

public static void main(String[] args) { int i = 2; int k = 3; { int j = 3; System.out.println("i + j is " + i + j); }

k = i + j; System.out.println("k is " + k); System.out.println("j is " + j); }}

a. k is 3

b. k is 0

c. k is 2

d. k is 1

Required Resources ITT Tech Virtual Library

Textbook

Submission Requirements Format: Microsoft Word, double-spaced

Font: 12-point, Times New-Roman

Citation style: APA

Length: 1–2 pages

Due by: Unit 5

Evaluation CriteriaYour instructor will use an answer key to grade your assignment.

-20- 11/14/2013

Page 21: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

Unit 5 Assignment 1: Programming Questions

Course Objectives and Learning Outcomes Describe the fundamentals of the Java programming language.

Use the String class to process fixed strings.

Use the Character class to process a single character.

Use the StringBuffer class to process flexible strings.

Describe the following relationship types: association, aggregation, composition, dependency,

strong inheritance, and weak inheritance.

Assignment RequirementsThe following homework is designed to cover the course objectives for Unit 5. The following questions

require you to examine each question, do research, and find the correct answer to the 20 questions listed

below.

1. What is the output of the following code?

public class Test { public static void main(String[] args) { String s1 = new String("Welcome to Java!"); String s2 = s1.toUpperCase();

if (s1 == s2) System.out.println("s1 and s2 reference to the same String object"); else if (s1.equals(s2)) System.out.println("s1 and s2 have the same contents"); else System.out.println("s1 and s2 have different contents"); }}

a. s1 and s2 reference to the same String object

b. s1 and s2 have different contents

c. s1 and s2 have the same contents

-21- 11/14/2013

Page 22: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

2. What will be the output of the following program?

public class Test { public static void main(String[] args) { String s = "Java"; StringBuffer buffer = new StringBuffer(s); change(buffer); System.out.println(buffer); } private static void change(StringBuffer buffer) { buffer.append(" and HTML"); }}

a. and HTML

b. nothing

c. Java

d. Java and HTML

3. What does the following statement display?

System.out.println("Java is neat".replaceAll("is", "AAA"));

a. Java AAA neat

b. JavaAAA neat

c. JavaAAAneat

d. Java AAAneat

4. Which of the following statements creates an instance of File on Window for the file c:\t.txt?

a. new File("c:\t.txt")

b. new File("c://t.txt")

c. new File("c:\\t.txt")

d. new File("c:/t.txt")

5. Which code fragment would correctly identify the number of arguments passed through the

command line to a Java application, excluding the name of the class that is being invoked?

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

b. int count = args.length;

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

d. int count = args.length - 1;

-22- 11/14/2013

Page 23: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

6. Which of the following statements returns the last character in a StringBuffer variable named

strBuf?

a. StringBuffer.charAt(strBuf.length() - 1)

b. strBuf.charAt(strBuf.length() - 1)

c. StringBuffer.charAt(strBuf.capacity() - 1)

d. strBuf.charAt(strBuf.capacity() - 1)

7. What will be the output of the following program?

public class Test { public static void main(String[] args) { String s = "Java"; StringBuffer buffer = new StringBuffer(s); change(s); System.out.println(s); } private static void change(String s) { s = s + " and HTML"; }}

a. and HTML

b. Java and HTML

c. Java

d. Nothing is displayed

8. 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. 'v'

b. Nothing will be assigned to x because the execution causes the runtime error

StringIndexOutofBoundsException.

c. 'a'

-23- 11/14/2013

Page 24: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

9. What is displayed by the following code?

public static void main(String[] args) throws Exception { String[] tokens = "Welcome to Java".split("o"); for (int i = 0; i < tokens.length; i++) { System.out.print(tokens[i] + " "); } }

a. Welc me t Java

b. Welc me to Java

c. Welcome to Java

d. Welcome t Java

10. Identify the problems in the following code:

public class Test { public static void main(String argv[]) { System.out.println("argv.length is " + argv.length); }}

a. If this program is run without passing any arguments, the program would display

argv.length is 0.

b. The program has a syntax error because String argv[] is wrong, and it should be replaced

by String[] args.

c. The program has a syntax error because String args[] is wrong, and it should be replaced

by String args[].

d. If this program is run without passing any arguments, the program would have a runtime

error because argv is null.

11. Which method can be used to read a whole line from the file?

a. next

b. nextLine

c. nextDouble

d. nextInt

-24- 11/14/2013

Page 25: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

12. Assuming s is "ABCABC," the method __________ returns a new string "aBCaBC."

a. s.toLowerCase(s)

b. s.toLowerCase()

c. s.replace("ABCABC", "aBCaBC")

d. s.replace('A', 'a')

e. s.replace('a', 'A')

13. Which method can be used to create an input object for file temp.txt?

a. new Scanner("temp.txt")

b. new Scanner(File("temp.txt"))

c. new Scanner(temp.txt)

d. new Scanner(new File("temp.txt"))

14. How can you get the word "abc" in the main method from the following call?

java Test "+" 3 "abc" 2

a. args[2]

b. args[1]

c. args[3]

d. args[0]

15. Which class contains the method for checking whether a file exists?

a. PrintWriter

b. File

c. Scanner

d. System

16. Assuming s is "ABCABC," the method __________ returns an array of characters.

a. s.toChars()

b. String.toCharArray()

c. s.toCharArray()

d. String.toChars()

e. toChars(s)

-25- 11/14/2013

Page 26: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

17. Which of the following returns the path separator character?

a. File.pathSeparatorChar

b. File.pathSeparator

c. File.separator

d. File.separatorChar

18. Which class will you use to write data into a text file?

a. PrintWriter

b. System

c. Scanner

d. File

19. Which class will you use to read data into a text file?

a. PrintWriter

b. Scanner

c. File

d. System

20. Assuming StringBuffer strBuf is "ABCDEFG," after invoking _________, strBuf contains

"ABCRRRRDEFG."

a. strBuf.insert(3, "RRRR")

b. strBuf.insert(1, "RRRR")

c. strBuf.insert(2, "RRRR")

d. strBuf.insert(4, "RRRR")

Tasks Present your findings in the form of a numbered answer list.

Cite your sources using APA format.

Submit your report in a Word document to your instructor at the beginning of

Unit 6.

Required Resources ITT Tech Virtual Library

Textbook

Submission Requirements Format: Microsoft Word, Double-Spaced

-26- 11/14/2013

Page 27: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

Font: 12-point Times New-Roman

Citation Style: APA

Length: 1–2 pages

Due By: Unit 6

Evaluation CriteriaThis assignment will be graded using an answer key.

-27- 11/14/2013

Page 28: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

Unit 6 Assignment 1: Object Questions

Course Objectives and Learning Outcomes Describe the fundamentals of the Java programming language.

Create a subclass from a superclass through inheritance.

Differentiate between overriding and overloading methods.

Explore the Object class and its toString() method.

Explain polymorphism, dynamic binding, and generic programming.

Explain how to cast Objects and implement the instanceOf operator.

Restrict access to data and methods using the protected visibility modifier.

Declare constants, unmodifiable methods, and nonextendable classes using the final modifier.

Use the this keyword to refer to the calling object.

Assignment RequirementsThe following homework is designed to cover the course objectives for Unit 6. The following questions

require you to do research and examine the questions to find the correct answer to the 20 questions listed

below.

-28- 11/14/2013

Page 29: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

1. The following two programs display the same result.

// Program 1public class Test { public static void main(String[] args) { Object a1 = new A(); Object a2 = new A(); System.out.println(((A)a1).equals((A)a2)); }}

class A { int x;

public boolean equals(A a) { return this.x == a.x; }}

// Program 2public class Test { public static void main(String[] args) { A a1 = new A(); A a2 = new A(); System.out.println(a1.equals(a2)); }}

class A { int x;

public boolean equals(A a) { return this.x == a.x; }}

a. True

b. False

2. Encapsulation means ______________.

a. that a class can contain another class

b. that data fields should be declared private

c. that a class can extend another class

d. that a variable of supertype can refer to a subtype object

-29- 11/14/2013

Page 30: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

3. What is the output of the following code?

import java.util.Date;

public class Test { public static void main(String[] args) { Date date1 = new Date(); Date date2 = new Date(); System.out.print((date1 == date2) + " " + (date1.getClass() == date2.getClass())); }}

a. false true

b. false false

c. true true

d. true false

-30- 11/14/2013

Page 31: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

4. What is the output of the following program?

public class Test { public static void main(String[] args) { new A(); } { System.out.print("Z"); }}

class A extends B { A() { System.out.print("A"); } { System.out.print("X"); }}

class B { B() { System.out.print("B"); } { System.out.print("Y"); }}

a. XYAB

b. ABXYZ

c. BXAY

d. YBXAZ

e. YBXA

-31- 11/14/2013

Page 32: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

5. Analyze the following code:

public class Test { public static void main(String[] args) { B b = new B(); b.m(5); System.out.println("i is " + b.i); }}

class A { int i;

public void m(int i) { this.i = i; }}

class B extends A { public void m(String s) { }}

What happens when the code is executed?

a. The method m is not overridden in B. B inherits the method m from A and defines an

overloaded method m in B.

b. The program has a compilation error because b.m(5) cannot be invoked since the

method m(int) is hidden in B.

c. The program has a runtime error on b.i, because i is not accessible from b.

d. The program has a compilation error, because m is overridden with a different signature

in B.

6. The visibility of the following modifiers increases in this order:

a. none, if no modifier is used; protected; private; and public

b. private; protected; none, if no modifier is used; and public

c. none, if no modifier is used; private; protected; and public

d. private; none, if no modifier is used; protected; and public

7. Which of the following statements is correct?

a. The finalized method can be invoked to finalize an object.

b. Every object can be cloned using the clone() method.

c. Every class should override the finalized method.

d. The clone() method can be invoked on an array object to create another array.

-32- 11/14/2013

Page 33: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

8. Analyze the following code:

public class Test { int x;

{ x++; }}

How will you debug this code?

a. An instance of Test cannot be constructed because it does not have a constructor.

b. The program cannot be compiled because the statement x++ must be placed inside a

method or a constructor.

c. When an instance of Test is constructed, the value of x becomes 1;

d. When an instance of Test is constructed, the value of x becomes 0;

9. A class design requires that a particular member variable be accessible by any subclasses of the

same class but not by the classes that are not members of the same package. What should be

done to achieve this?

a. The variable should have no special access modifier.

b. The variable should be marked protected.

c. The variable should be marked private and an accessor method provided.

d. The variable should be marked public.

e. The variable should be marked private.

10. Suppose ArrayList x contains two strings [Beijing, Singapore]. Which of the following methods will

cause the list to become [Beijing, Chicago, Singapore]?

a. x.add("Chicago")

b. x.add(0, "Chicago")

c. x.add(1, "Chicago")

d. x.add(2, "Chicago")

11. Which of the following modifiers should you use on the members of a class so that they are not

accessible to another class in a different package but are accessible to any subclasses in any

package?

a. protected

b. public

c. default modifier

d. private

-33- 11/14/2013

Page 34: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

12. Analyze the following code:

public class Test { int x;

static { x++; }}

Which of the following statements is true?

a. The program cannot be compiled because no main method is declared.

b. When an instance of Test is constructed, the value of x becomes 0.

c. When an instance of Test is constructed, the value of x becomes 1.

d. The program cannot be compiled because the statement x++ must be placed inside a

method or a constructor.

13. Which of the statements regarding the super keyword is incorrect?

a. You can use super to invoke a super class method.

b. You cannot invoke a method in superclass’s parent class.

c. You can use super to invoke a super class constructor.

d. You can use super.super.p to invoke a method in superclass’s parent class.

14. Polymorphism means ______________.

a. that a class can extend another class

b. that a class can contain another class

c. that a variable of supertype can refer to a subtype object

d. that data fields should be declared private

15. Debug the following program segment:

public class Test { public static void main(String[] args) { String s = new String("Welcome to Java"); String o = s; String d = (String)o; } }

a. When casting o to s in String d = (String)o, the contents of o is changed.

b. Strings s, o, and d reference the same String object.

c. When assigning s to o in Object o = s, a new object is created.

d. When casting o to s in String d = (String)o, a new object is created.

-34- 11/14/2013

Page 35: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

16. Object-oriented programming allows you to derive new classes from existing classes. This is

called ____________.

a. abstraction

b. generalization

c. inheritance

d. encapsulation

17. What is the output of running class C?

class A { public A() { System.out.println( "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. There is no output.

b. "The default constructor of B is invoked""The default constructor of A is invoked"

c. "The default constructor of B is invoked"

d. "The default constructor of A is invoked""The default constructor of B is invoked"

e. "The default constructor of A is invoked"

-35- 11/14/2013

Page 36: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

18. What is the output of running A?

public class A extends B { int x = 1; public static void main(String[] args) { System.out.print(new A().x); System.out.print(new B().x); }}

class B { int x = 5;}

a. 51

b. 15

c. 55

d. 11

19. What is the output of the following program?

public class Test extends Object { public static void main(String[] args) { Test test = new Test(); }

public Test() { System.out.print("A"); }

{ System.out.print("B"); }

static { System.out.print("C"); }}

a. ABC

b. BAC

c. ACB

d. CBA

e. CAB

-36- 11/14/2013

Page 37: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

20. Suppose you create a class Cylinder to be a subclass of Circle. Debug the following code:

class Cylinder extends Circle { double length; Cylinder(double radius) { Circle(radius); }

}

a. The program has a syntax error because you attempted to invoke the Circle class’s

constructor illegally.

b. The program compiles fine but has a runtime error because of invoking the Circle class’s

constructor illegally.

c. The program compiles fine, but you cannot create an instance of Cylinder because the

constructor does not specify the length of the cylinder.

Tasks Present your findings in the form of a numbered answer list.

Cite your sources using APA format.

Submit your report in a Word document to your instructor at the beginning of

Unit 7.

Required Resources ITT Tech Virtual Library

Textbook

Submission Requirements Format: Microsoft Word, Double-Spaced

Font: 12-point Times New-Roman

Citation Style: APA

Length: 1–2 pages

Due By: Unit 7

Evaluation CriteriaThis assignment will be graded with an answer key.

-37- 11/14/2013

Page 38: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

Unit 7 Assignment 1: Interface Questions

Course Objectives and Learning Outcomes Describe the fundamentals of the Java programming language.

Develop GUIs (Graphical User Interfaces) for Java applications.

Develop graphics components for Java applications.

Create user interfaces using frames, panels, and simple GUI components.

Explain the role of layout managers in developing GUI interfaces.

Specify colors and fonts using the Color and Font classes.

Draw figures and images using the methods of the Graphics class.

Use a panel to draw graphics.

Draw strings, lines, rectangles, and ovals.

Assignment RequirementsThe following homework is designed to cover the course objectives for Unit 7. The following questions

that require you to do research and examine the questions to find the correct answer to the 20 questions

listed below.

1. What layout manager should you use so that every component occupies the same size in the

container?

a. A GridLayout

b. A FlowLayout

c. None

d. A BorderLayout

2. To position a Button within an application Frame so that the size of the Button is not affected by

the Frame size, you should use _______.

a. a GridLayout

b. the East or West area of a BorderLayout

c. a FlowLayout

d. the center area of a BorderLayout

e. the North or South area of a BorderLayout

-38- 11/14/2013

Page 39: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

3. Suppose a JFrame uses the GridLayout(2, 2). If you add six buttons to the frame, how many

columns are displayed?

a. 4

b. 1

c. 3

d. 2

4. To draw several messages in a panel with different colors and font, you would use the setColor

and setFont methods in the _____ class?

a. Event

b. Component

c. Graphics

d. Variable

5. Which of the following best describes the relationship between a container and a Swing GUI

object in the container?

a. Aggregation

b. Association

c. Composition

d. Inheritance

6. The default layout out of a JPanel is __________.

a. GridLayout

b. BorderLayout

c. FlowLayout

d. None

7. Which component cannot be added to a container?

a. JPanel

b. JButton

c. JFrame

d. JComponent

-39- 11/14/2013

Page 40: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

8. __________ are referred to as heavyweight components.

a. Non-GUI components

b. GUI components

c. Swing components

d. AWT components

9. How many frames are displayed in the following?

import javax.swing.*;public class Test extends JFrame { public static void main(String[] args) { JFrame f1 = new Test(); JFrame f2 = new Test(); JFrame f3 = new Test(); f1.setVisible(true); f2.setVisible(true); f3.setVisible(true); }}

a. 3

b. 2

c. 1

d. 0

10. Which of the following statements is used for terminating the program when closing the frame?

a. frame.setDefaultCloseOperation(null)

b. frame.setDefaultCloseOperation(JFrame.STOP_ON_CLOSE)

c. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)

d. frame.setDefaultCloseOperation(JFrame.TERMINATE_ON_CLOSE)

11. Which of the following best describes the relationship between a container and a layout

manager?

a. Inheritance

b. Aggregation

c. Composition

d. Association

-40- 11/14/2013

Page 41: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

12. To add a component c to a JPanel p, use _________.

a. p.insert(c)

b. p.append(c)

c. p.getContentPane(c)

d. p.add(c)

13. Which of the following best describes the relationship between JComponent and JButton?

a. Aggregation

b. Composition

c. Inheritance

d. Association

14. Which of the following classes is a heavy-weight component?

a. JTextField

b. JPanel

c. JButton

d. JFrame

15. To create a JPanel of the BorderLayout, use ______________.

a. JPanel p = new JPanel().setLayout(new BorderLayout());

b. JPanel p = new JPanel(new BorderLayout());

c. JPanel p = new JPanel(BorderLayout());

d. JPanel p = new JPanel()

16. Suppose a JFrame uses the GridLayout(0, 2). If you add six buttons to the frame, how many

columns are displayed?

a. 2

b. 4

c. 3

d. 1

-41- 11/14/2013

Page 42: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

17. How many frames are displayed in the following?

import javax.swing.*;

public class Test { public static void main(String[] args) { JFrame f1 = new JFrame("My Frame"); JFrame f2 = f1; JFrame f3 = f2; f1.setVisible(true); f2.setVisible(true); f3.setVisible(true); }}

a. 0

b. 1

c. 3

d. 2

18. The _____ class has the setBackground, setForeground, and setFont methods?

a. Abstract

b. Component

c. Variable

d. Identifier

19. Suppose a JFrame uses the GridLayout(2, 0). If you add six buttons to the frame, how many

columns are displayed?

a. 4

b. 3

c. 1

d. 2

20. You should override the __________ method to draw things on a Swing component.

a. init()

b. update()

c. paintComponent()

d. repaint()

Tasks Present your findings in the form of a bulleted answer list.

Cite your sources using APA format.

-42- 11/14/2013

Page 43: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

Submit your report in a Word document to your instructor at the beginning of Unit 8.

Required Resources ITT Tech Virtual Library

Textbook

Submission Requirements Format: Microsoft Word, Double-Spaced

Font: 12-point Times New-Roman

Citation Style: APA

Length: 1–2 pages

Due By: Unit 8

Evaluation CriteriaThis assignment will be graded using an answer key.

-43- 11/14/2013

Page 44: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

Unit 8 Assignment 1: Exception Handling Questions

Course Objectives and Learning Outcomes Describe the fundamentals of the Java programming language.

Use exceptions and assertions to handle errors in Java programs.

Write Java programs by using text I/O.

Describe exceptions and exception handling.

Distinguish between the following exception types: error or fatal versus exception or non-fatal

exceptions and checked versus unchecked exceptions.

Declare exceptions in the method header.

Throw exceptions out of a method.

Write a try-catch block to handle exceptions.

Assignment RequirementsException Handling in Java is a very powerful capability. Exception Handling allows us to check input,

verify if files exist, prevent division by zero, prevent array out of bounds, and a whole host of other things.

What are some of the more popular exception handling uses? Find a problem and describe how

exception handling can be used to solve the problem. You don't need to be overly detailed, just provide a

general description of how you could use exception handling to solve it.

Tasks Cite any sources using APA format.

Submit your report in a Word document to your instructor at the beginning of Unit 9.

Required Resources ITT Tech Virtual Library

Textbook

Submission Requirements Format: Microsoft Word, Double-Spaced

Font: 12-point Times New-Roman

Citation Style: APA

Length: One to two pages

Due By: Unit 9

Evaluation CriteriaThis assignment will be graded using the Writing Assignment Rubric, which is found at the back of this

document.

-44- 11/14/2013

Page 45: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

Unit 9 Assignment 1: Classes Questions

Course Objectives and Learning Outcomes Describe the fundamentals of the Java programming language.

Write Java programs by using primitive data types and operations.

Write Java programs by using abstract classes and interfaces.

List custom exception classes.

Identify file properties and delete and rename files using the File class.

Read and write data to a file.

Design and use abstract classes.

Process a calendar using the Calendar and GregorianCalendar classes.

Declare interfaces to model weak inheritance relationships.

Declare listener classes and write code to handle events.

Assignment RequirementsAnswer the following multiple-choice questions. Present your answers as a written, numbered list of

answer choices (1. a.; 2. b.; etc.).

1. Which of the following statements converts a double value d into a string s?

a. s = new Double(d).stringOf();

b. s = String.stringOf(d);

c. s = (new Double(d)).toString();

d. s = (Double.valueOf(s)).toString();

2. Assume Calendar calendar = new GregorianCalendar(). Which of the following statements will

return the number of days in a month?

a. calendar.getActualMaximum(Calendar.DAY_OF_MONTH)

b. calendar.get(Calendar.MONTH_OF_YEAR)

c. calendar.get(Calendar.WEEK_OF_MONTH)

d. calendar.get(Calendar.WEEK_OF_YEAR)

e. calendar.get(Calendar.MONTH)

3. Assume Calendar calendar = new GregorianCalendar(). Which of the following statements will

return the week of the year?

a. calendar.get(Calendar.MONTH_OF_YEAR)

b. calendar.get(Calendar.WEEK_OF_YEAR)

c. calendar.get(Calendar.WEEK_OF_MONTH)

d. calendar.get(Calendar.MONTH)

-45- 11/14/2013

Page 46: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

4. What will be the output of running the class Test with the following code lines?

interface A {}

class C { }

class B extends D implements A {}

public class Test extends Thread { 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"); }}

class D extends C { }

a. b is an instance of A followed by b is an instance of C.

b. b is an instance of C.

c. There will be no output.

d. b is an instance of A.

5. What is the output of the following code?

public class Test { public static void main(String[] args) { java.math.BigInteger x = new java.math.BigInteger("3"); java.math.BigInteger y = new java.math.BigInteger("7"); x.add(y); System.out.println(x); }}

a. 3

b. 4

c. 11

d. 10

-46- 11/14/2013

Page 47: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

6. Assume Calendar calendar = new GregorianCalendar(). Which of the following statements will

return the month of the year?

a. calendar.get(Calendar.MONTH_OF_YEAR)

b. calendar.get(Calendar.MONTH)

c. calendar.get(Calendar.WEEK_OF_YEAR)

d. calendar.get(Calendar.WEEK_OF_MONTH)

7. Analyze the following code:

Number[] numberArray = new Integer[2]; numberArray[0] = new Double(1.5);

What will happen when the code is executed?

a. At runtime, new Integer[2] is assigned to numberArray. This makes each element of

numberArray an Integer object. Therefore, you cannot assign a Double object to it.

b. You cannot use Number as a data type because it is an abstract class.

c. Each element of numberArray is of the Number type; therefore, you cannot assign a

Double object to it.

d. Each element of numberArray is of the Number type; therefore, you cannot assign an

Integer object to it.

8. Which of the following statements will convert a string s into a double value d?

a. d = Double.parseDouble(s);

b. d = Double.valueOf(s).doubleValue();

c. d = (new Double(s)).doubleValue();

d. All of the above

9. Which of the following declares an abstract method in an abstract Java class?

a. public abstract method();

b. public abstract void method() {}

c. public void abstract Method();

d. public abstract void method();

e. public void method() {}

-47- 11/14/2013

Page 48: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

10. Analyze the following code:

public class Test { public static void main(String[] args) { Number x = new Integer(3); System.out.println(x.intValue()); System.out.println(x.compareTo(new Integer(4))); }}

What will happen when the code is executed?

a. The program has a syntax error because intValue is an abstract method in Number.

b. The program has a syntax error because x does not have the compareTo method.

c. The program has a syntax error because an Integer instance cannot be assigned to a

Number variable.

d. The program compiles and runs fine.

11. Analyze the following code:

public class Test { public static void main(String[] args) { Number x = new Integer(3); System.out.println(x.intValue()); System.out.println((Integer)x.compareTo(new Integer(4))); }}

What will happen when the code is executed?

a. The program has a syntax error because x cannot be cast into Integer.

b. The program has a syntax error because an Integer instance cannot be assigned to a

Number variable.

c. The program compiles and runs fine.

d. The program has a syntax error because the member access operator (.) is executed

before the casting operator.

e. The program has a syntax error because intValue is an abstract method in Number.

-48- 11/14/2013

Page 49: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

12. Analyze the following code:

Number numberRef = new Integer(0);

Double doubleRef = (Double)numberRef;

What will happen when the code is executed?

a. A runtime class casting exception occurs because numberRef cannot be cast as a

Double.

b. You can convert an int to double; therefore, you can cast an Integer instance to a Double

instance.

c. There is no such class named Integer. You should use the class Int.

d. The compiler detects that numberRef is not an instance of Double.

e. The program runs fine because Integer is a subclass of Double.

13. Which of the following statements correctly declares an interface?

a. abstract interface A { abstract void print() { };}

b. interface A { void print() { }; }

c. abstract interface A { print(); }

d. interface A { void print();}

14. What is the output of Integer.parseInt("10", 2)?

a. 2;

b. Invalid statement;

c. 10;

d. 1;

15. Which of the following class definitions defines a legal abstract class?

a. public class abstract A { abstract void unfinished(); }

b. abstract class A { abstract void unfinished(); }

c. class A { abstract void unfinished(); }

d. class A { abstract void unfinished() { } }

-49- 11/14/2013

Page 50: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

16. Analyze the following code:

1. import java.util.*;

2. public class Test {

3. public static void main(String[] args) {

4. Calendar[] calendars = new Calendar[10];

5. calendars[0] = new Calendar();

6. calendars[1] = new GregorianCalendar();

7. }

8. }

What will happen when the code is executed?

a. The program has a syntax error on Line 6 because Calendar[1] is not of a

GregorianCalendar type.

b. The program has a syntax error on Line 5 because java.util.Calendar is an abstract class.

c. The program has a syntax error on Line 4 because java.util.Calendar is an abstract class.

17. __________ is a special form of association that represents an ownership relationship between

two objects.

a. Inheritance

b. Aggregation

c. Association

d. Composition

-50- 11/14/2013

Page 51: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

18. The Rational class in this chapter extends java.lang.Number and implements

java.lang.Comparable. Analyze the following code:

1. public class Test {

2. public static void main(String[] args) {

3. Number[] numbers = {new Rational(1, 2), new Integer(4), new Double(5.6)};

4. java.util.Arrays.sort(numbers);

5. }

6. }

What will happen when the code is executed?

a. The program has a syntax error because numbers is declared as Number[]; therefore,

you cannot pass it to Arrays.sort(Object[]).

b. The program has a syntax error because numbers is declared as Number[]; therefore,

you cannot assign {new Rational(1, 2), new Integer(4), new Double(5.6)} to it.

c. The program has a runtime error because the compareTo methods in Rational, Integer,

and Double classes do not compare the value of one type with a value of another type.

d. The program has a runtime error because number is declared as Number[]; therefore,

you cannot assign {new Rational(1, 2), new Integer(4), new Double(5.6)} to it.

19. __________ array is actually an array in which each element is another array.

a. One

b. Two

c. Three

d. Multidimensional

20. Which of the following statements is incorrect about constructors?

a. A constructor may invoke a static method.

b. A constructor may be private.

c. A constructor may invoke an overloaded constructor.

d. A constructor invokes its superclass no-arg constructor by default if a constructor does

not invoke an overloaded constructor or its superclass’s constructor.

e. A constructor may be static.

Tasks Present your findings in a numbered answer list.

Submit your report in a Word document to your instructor at the beginning of Unit 9.

-51- 11/14/2013

Page 52: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

Required Resources ITT Tech Virtual Library

Textbook

Submission Requirements Format: Microsoft Word, Double-Spaced

Font: 12-point Times New-Roman

Citation Style: APA

Length: One to two pages

Due By: Unit 10

Evaluation CriteriaThis assignment will be graded using an answer key.

-52- 11/14/2013

Page 53: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

Unit 10 Assignment 1: GUI Questions

Course Objectives and Learning Outcomes Describe the fundamentals of the Java programming language.

Implement event-driven programming in Java programs.

Use the Swing components in previously created user interfaces.

Write programs to deal with MouseEvent and KeyEvent.

Create graphical user interfaces with various user-interface components: JButton, JCheckBox,

JRadioButton, JLabel, JTextField, JTextArea, JComboBox, JList, JScrollBar, and JSlider.

Display multiple windows in an application.

Assignment RequirementsAnswer the following multiple-choice questions. Present your answers as a written, numbered list of

answer choices (1. a.; 2. b.; etc.).

1. Which of the following statements registers a panel object p as a listener for a button variable jbt?

a. addActionListener(p);

b. jbt.addActionListener(p);

c. jbt.addEventListener(p);

d. jbt.addActionEventListener(p);

2. To listen to mouse-clicked events, the listener must implement the __________ interface or

extend the _______ adapter.

a. MouseMotionListener; MouseMotionAdapter

b. MouseListener; MouseAdapter

c. WindowListener; WindowAdapter

d. ComponentListener; ComponentAdapter

3. The listener’s __________ method is invoked after a mouse button is pressed but not yet

released.

a. public void mousePressed(MouseEvent e)

b. public void mouseClicked(MouseEvent e)

c. public void mouseEntered(MouseEvent e)

d. public void mouseExited(MouseEvent e)

e. public void mouseReleased(MouseEvent e)

-53- 11/14/2013

Page 54: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

4. Which of the following interfaces should be implemented to listen for a button action event?

a. WindowListener

b. ContainerListener

c. ActionListener

d. FocusListener

e. MouseListener

5. Suppose A is an inner class in Test. A is compiled into a file named _________.

a. A$Test.class

b. Test&A.class

c. A.class

d. Test$A.class

6. Which of the following methods in the ActionEvent returns the action command of the button?

a. getModifiers()

b. getID()

c. getActionCommand()

d. paramString()

7. To be a listener for ActionEvent, an object must be an instance of ____________.

a. ActionListener

b. EventObject

c. WindowEvent

d. WindowListener

e. ActionEvent

8. The handler, for example actionPerformed, is a method in ________.

a. the EventObject class

b. the Object class

c. a source object

d. both source and listener object

e. a listener object

-54- 11/14/2013

Page 55: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

9. The listener object processes the event fired from the ___________.

a. source object

b. adapter object

c. adaptee object

d. listener object

10. When clicking a button, the button creates and fires a(n) _________.

a. ComponentEvent

b. ContainerEvent

c. ItemEvent

d. MouseMotionEvent

e. ActionEvent

11. Suppose A is an anonymous inner class in Test. A is compiled into a file named _________.

a. Test&1.class

b. A.class

c. Test$A.class

d. Test$1.class

e. A$Test.class

12. Pressing a button generates __________.

a. a ContainerEvent

b. an ActionEvent

c. a MouseEvent

d. an ItemEvent

e. a MouseMotionEvent

13. A component that enables the user to choose a single value or multiple values is a

__________________.

a. combo box

b. label

c. text field

d. list

-55- 11/14/2013

Page 56: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

14. Clicking a JCheckBox object generates __________ events.

a. ActionEvent and ItemEvent

b. ActionEvent and ContainerEvent

c. ComponentEvent and ContainerEvent

d. ItemEvent and ComponentEvent

15. The method __________ gets the contents of the text field jtf.

a. jtf.getText()

b. jtf.getText(s)

c. jtf.getString()

d. jtf.findString()

16. To wrap a line in a text area jta, invoke ____________.

a. jta.setLineWrap(false)

b. jta.setLineWrap(true)

c. jta.wrapText()

d. jta.WrapLine()

17. The method __________ adds an item s into a JComboBox jcbo.

a. jcbo.addItem(s)

b. jcbo.addChoice(s)

c. jcbo.add(s)

d. jcbo.addObject(s).

18. To enter or display a string, you can use a __________.

a. label

b. radio button

c. button

d. text field

e. check box

19. Clicking a JRadioButton generates _____________ events.

a. ItemEvent and ActionEvent

b. ItemEvent Ony

c. ComponentEvent and Container Event

d. ContainerEvent Only

e. ActionEvent Only

-56- 11/14/2013

Page 57: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

20. The method __________ creates a test area with scroll bars if there is more text than the physical

size of the text area.

a. jScrollPane

b. jlblImageTitle

c. jTextArea

Tasks Present your findings in a numbered answer list.

Submit your report in a Word document to your instructor at the beginning of Unit 10.

Required Resources ITT Tech Virtual Library

Textbook

Submission Requirements Format: Microsoft Word, Double-Spaced

Font: 12-point Times New-Roman

Citation Style: APA

Length: One to two pages

Due By: Unit 10

Evaluation CriteriaThis assignment will be graded using an answer key.

-57- 11/14/2013

Page 58: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

Project

Project Part 1: Mortgage Rate Calculator

PurposeOne of the most common uses of Java applications is an online amortization calculator for current

mortgage rates. A mortgage loan calculator is a tool that allows for quick access to loan amount, years

the loan will take to pay off, and interest rates. The purpose of Project Part 1 is to create a loan

amortization calculator that will allow the user to input a specific loan amount along with the number of

years and interest rate, and with a click of a button be able to see a full report of monthly payments and

the overall length of the loan.

Course Objectives and Learning Outcomes Write Java programs by using primitive data types and operations.

Write Java programs by using user-defined methods for real world objects.

Write Java programs by using user-defined objects and classes.

Create, compile, and execute a Java program.

Write a Java program to display text in a message dialog box.

Identify and analyze the different numeric data types to support object-oriented programming.

Create user interfaces using frames, panels, and simple GUI components.

Required Resources ITT Tech Virtual Library

Textbook

Project LogisticsTo successfully complete Part 1 of the project, you must develop a Java application that will display a

loan amortization table. To receive a passing grade, the application must do the following:

1. Allow loan amount inputs

2. Allow number of years of loan inputs

3. Allow interest rate of loan inputs

4. Produce output that generates monthly payments and total loan repayment based on input

Deliverables One working Java application file

Documentation on any problem areas

Due in Unit 8

-58- 11/14/2013

Page 59: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

Project Part 2: Enhanced Mortgage Rate Calculator

PurposeJava applications are commonly used to create online amortization calculators for current mortgage rates.

An amortization calculator is a tool that helps users input the loan amount, years the loan will take to pay

off, and the interest rates to receive a report of monthly payments. The purpose of Project Part 2 is to

create a loan amortization calculator that lets the user input a specific loan amount, number of years, and

interest rate. Then with a click of a button the calculator displays a full report of monthly payments along

with the decrease in the overall balance for each month.

Course Objectives and Learning Outcomes Write Java programs by using primitive data types and operations.

Write Java programs by using user-defined methods for real world objects.

Write Java programs by using user-defined objects and classes.

Develop GUIs (Graphical User Interfaces) for Java applications.

Create, compile, and execute a Java program.

Write a Java program to display text in a message dialog box.

Identify and analyze the different numeric data types to support object-oriented programming.

Write a program that receives input from the console.

Create user interfaces using frames, panels, and simple GUI components.

Required Resources ITT Tech Virtual Library

Textbook

Project LogisticsTo successfully complete Part 2 of the project, you must develop another amortization table in Java. To

receive a passing grade, the application must do the following:

1. Allow the input of the loan amount

2. Allow the input of interest rate

3. Allow the input of length of loan

4. Produce output to display overall monthly decrease in total payments from overall loan amount.

Deliverables One working Java application file

Documentation on any problem areas

Due in Unit 11

-59- 11/14/2013

Page 60: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

Final Project Grading Rubric

The final project is worth 17% of the overall grade. The final project has two parts, the first part being 8%

of the overall grade and the second part being 9% of the overall grade. Grade each question based off of

the information that is listed below.

Calculations: Do the math calculations for the interest rates produce the desired results every time?

Excellent results every time, 3 points, satisfactory, 2 points and poor, 1 point.

GUI: Does the Java program have a Graphical User Interface and not in the command prompt? Excellent

GUI display, 3 points, satisfactory, 2 points, and poor, 1 point.

Documentation: Throughout the Java programming code, are different sections documented to make

reviewing the code and changes easy to understand? Excellent documentation is present and easy to

understand, 3 points, satisfactory, 2 points, and poor, 1 point.

Code: Are all sections of the code relevant to the application that will be created and displayed on the

computer? Excellent use of code format and structure, 3 points, satisfactory, 2 points, and poor, 1 point.

Display: Does the application display the input boxes along with the output information in the correct

areas of the application? Excellent use of alignment and positioning, 3 points, satisfactory, 2 points, and

poor, 1 point.

Comparison: Is the application able to display several interest rates on the same page of the application

for comparison purposes? Excellent use of comparing multiple input information, 3 points, satisfactory, 2

points, and poor, 1 point.

Week:

Final Exam Date:

Student Name:

Part 1: / 18 (8%)

Part 2: / 18 (9%)

Total Grade: / 36

-60- 11/14/2013

Page 61: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

Directions: Grade both sections based off of the table below. The results will be combined for the overall

final project grade worth 17%.

Part 1 Part 2

Calculations

GUI

Documentation

Code

Display

Comparison

Total

-61- 11/14/2013

Page 62: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

Writing Assignment Rubric

Length: If the paper meets the required length, 3 points; 75% of length, 2 points; and less than 75%, 1

point.

Context: Is the paper organized with an introduction and conclusion? Excellent organization, 3 points;

satisfactory organization, 2 points; poor organization, 1 point.

Progression: Does the writer progress logically from paragraph to paragraph and idea to idea? Excellent

progression of ideas, 3 points; satisfactory progression, 2 points; poor progression, 1 point.

Coverage: Does the writer cover all areas of each assigned topic or question? Excellent coverage of

question asked, 3 points; satisfactory coverage, 2 points; poor coverage, 1 point.

Elaboration: Does the writer provide evidence for conclusions or statements using the text or other

materials? Excellent elaboration of ideas, 3 points; satisfactory elaboration, 2 points; poor elaboration, 1

point.

Week:

Assignment:

Student Name:

Total Grade: / 15

Directions: Provide a rating that best represents performance in completing the assignment.

Excellent: 3 Satisfactory: 2 Poor: 1

Length

Context

Progression

Coverage

Elaboration

Total

-62- 11/14/2013

Page 63: Web viewJava applications are commonly used to create online amortization calculators for current mortgage rates. An amortization calculator is a tool that helps users input

Introduction to Java Programming GRADED ASSIGNMENTS

Question Assignment Rubric

The assignments, either written or questions are worth 2% each week for a total of 20% of the overall

grade. Grade each question assignment based off of the information that is listed below.

Multiple Choices: There are a total of 20 questions, either multiple choice or fill in the blank.

Week:

Question Assignment:

Student Name:

Total Grade: / 20

Directions: Each question is worth 1 point and each question only has one correct answer.

-63- 11/14/2013