I pledge by honor that I will not discuss this exam with anyone until my instructor reviews the exam in the class.

Similar documents
Full download all chapters instantly please go to Solutions Manual, Test Bank site: testbanklive.com

1. Which of the following is the correct expression of character 4? a. 4 b. "4" c. '\0004' d. '4'

Exam Duration: 2hrs and 30min Software Design

CIS 265/506 Exam1 Spring 2012 Prof. V. Matos Exam Last Name First Name:

Date: Dr. Essam Halim

CS 113 PRACTICE FINAL

Chapter 1: Introduction to Computers, Programs, and Java

Instruction to students:

b. Suppose you enter input from the console, when you run the program. What is the output?

Introduction to OOP with Java. Instructor: AbuKhleif, Mohammad Noor Sep 2017

Questions Answer Key Questions Answer Key Questions Answer Key

Full file at Chapter 2 - Inheritance and Exception Handling

Practice Questions for Final Exam: Advanced Java Concepts + Additional Questions from Earlier Parts of the Course

Final Examination Semester 3 / Year 2008

Computer Science II (20073) Week 1: Review and Inheritance

Chapter 8 Objects and Classes Dr. Essam Halim Date: Page 1

Computer Programming, I. Laboratory Manual. Final Exam Solution

CIS265 - Spring Exam 2 First Name Last Name CSU#

WOSO Source Code (Java)

Full file at

Prelim 1 SOLUTION. CS 2110, September 29, 2016, 7:30 PM Total Question Name Loop invariants. Recursion OO Short answer

Selected Questions from by Nageshwara Rao

Introduction to Programming Using Java (98-388)

Practice Questions for Chapter 9

Java Identifiers, Data Types & Variables

c) And last but not least, there are javadoc comments. See Weiss.

CSCI 136 Written Exam #0 Fundamentals of Computer Science II Spring 2013

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

Class, Variable, Constructor, Object, Method Questions

Prelim 1. Solution. CS 2110, 14 March 2017, 7:30 PM Total Question Name Short answer

CS 177 Spring 2010 Exam I

CMSC 331 Second Midterm Exam

CH. 2 OBJECT-ORIENTED PROGRAMMING

Introduction to OOP with Java. Instructor: AbuKhleif, Mohammad Noor Sep 2017

24. Inheritance. Java. Fall 2009 Instructor: Dr. Masoud Yaghini

JAVA MOCK TEST JAVA MOCK TEST II

Contents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance

Birkbeck (University of London) Software and Programming 1 In-class Test Mar 2018

COMPUTER APPLICATIONS

22. Inheritance. Java. Summer 2008 Instructor: Dr. Masoud Yaghini

Questions Answer Key Questions Answer Key Questions Answer Key

Exception-Handling Overview

1. Java is a... language. A. moderate typed B. strogly typed C. weakly typed D. none of these. Answer: B

Inheritance and Polymorphism

CSC Java Programming, Fall Java Data Types and Control Constructs

Java Foundations Certified Junior Associate

Problem Grade Total

boolean, char, class, const, double, else, final, float, for, if, import, int, long, new, public, return, static, throws, void, while

Full file at

Islamic University of Gaza Faculty of Engineering Computer Engineering Department

Name Return type Argument list. Then the new method is said to override the old one. So, what is the objective of subclass?

Chapter 2: Basic Elements of Java

CSCI 136 Written Exam #0 Fundamentals of Computer Science II Spring 2015

Prelim 1. Solution. CS 2110, 14 March 2017, 5:30 PM Total Question Name Short answer

Questions Answer Key Questions Answer Key Questions Answer Key

Objective Questions. BCA Part III Paper XIX (Java Programming) page 1 of 5

Lara Technologies Special-Six Test

( &% class MyClass { }

Course Outline. Introduction to java

CS260 Intro to Java & Android 03.Java Language Basics

Introduction. Exceptions: An OO Way for Handling Errors. Common Runtime Errors. Error Handling. Without Error Handling Example 1

Prelim 1. CS 2110, September 29, 2016, 7:30 PM Total Question Name Loop invariants

Fundamentals of Object Oriented Programming

Chapter 11 Inheritance and Polymorphism. Motivations. Suppose you will define classes to model circles,

CS171:Introduction to Computer Science II

The Sun s Java Certification and its Possible Role in the Joint Teaching Material

Chapter 10 Inheritance and Polymorphism. Dr. Hikmat Jaber

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring

Java Programming. MSc Induction Tutorials Stefan Stafrace PhD Student Department of Computing

Exam 1 Prep. Dr. Demetrios Glinos University of Central Florida. COP3330 Object Oriented Programming

CMSC 331 Second Midterm Exam

CLASS DESIGN. Objectives MODULE 4

F I N A L E X A M I N A T I O N

CS-202 Introduction to Object Oriented Programming

Oracle 1Z Java SE 8 Programmer I. Download Full Version :

Vendor: Oracle. Exam Code: 1Z Exam Name: Java SE 8 Programmer. Version: Demo

Datatypes, Variables, and Operations

3. Convert 2E from hexadecimal to decimal. 4. Convert from binary to hexadecimal

The Java language has a wide variety of modifiers, including the following:

CHETTINAD COLLEGE OF ENGINEERING & TECHNOLOGY JAVA

Zheng-Liang Lu Java Programming 45 / 79

CMSC131. Inheritance. Object. When we talked about Object, I mentioned that all Java classes are "built" on top of that.

COMP 250: Java Programming I. Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette

Computer Science II (20082) Week 1: Review and Inheritance

Name:... ID:... class A { public A() { System.out.println( "The default constructor of A is invoked"); } }

HAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner.

1.Which four options describe the correct default values for array elements of the types indicated?

Computer Programming, I. Laboratory Manual. Experiment #3. Selections

UNIVERSITI TEKNOLOGI MALAYSIA FINAL EXAMINATION SEMESTER II, 2016 / 2017

Eng. Mohammed S. Abdualal

UNIVERSITI SAINS MALAYSIA. CIT502 Object-Oriented Programming and Software Engineering

CS 110 Practice Final Exam originally from Winter, Instructions: closed books, closed notes, open minds, 3 hour time limit.

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

Points To Remember for SCJP

CSC System Development with Java. Exception Handling. Department of Statistics and Computer Science. Budditha Hettige

CS 113 MIDTERM EXAM 2 SPRING 2013

IST311. Advanced Issues in OOP: Inheritance and Polymorphism

CIS 110 Introduction To Computer Programming. February 29, 2012 Midterm

CIS 110: Introduction to computer programming

CS115. Chapter 17 Exception Handling. Prof. Joe X. Zhou Department of Computer Science. To know what is exception and what is exception handling

Transcription:

Name: Covers Chapters 1-3 50 mins CSCI 1301 Introduction to Programming Armstrong Atlantic State University Instructor: Dr. Y. Daniel Liang I pledge by honor that I will not discuss this exam with anyone until my instructor reviews the exam in the class. Signed by Date Part I. (10 pts) Show the output of the following code: (write the output next to each println statement if the println statement is executed in the program). public class Test { public static void main(string[] args) { System.out.println((int)(Math.random())); System.out.println(Math.pow(2, 3)); System.out.println(34 % 7); System.out.println(3 + 4 * 2 > 2 * 9); int number = 4; if (number % 3 == 0) System.out.println(3 * number); System.out.println(4 * number); int x = 943; System.out.println(x / 100); System.out.println(x % 100); System.out.println(x + " is " + ((x % 2 == 0)? "even" : "odd")); int y = -1; y++; System.out.println(y); Part II: 1. (10 pts) Write a program that prompts the user to enter the exchange rate from currency US dollars to Chinese RMB. Prompt the user to enter 0 to convert from US dollars to Chinese RMB and 1 vice versa. Prompt the user to enter the amount in US dollars or Chinese RMB to convert it to 1

Chinese RMB or US dollars, respectively. Here are the sample runs: <Output> Enter the exchange rate from dollars to RMB: 6.81 Enter 0 to convert dollars to RMB and 1 vice versa: 0 Enter the dollar amount: 100 $100.0 is 681.0 Yuan <End Output> <Output> Enter the exchange rate from dollars to RMB: 6.81 Enter 0 to convert dollars to RMB and 1 vice versa: 1 Enter the RMB amount: 10000 10000.0 Yuan is $1468.43 <End Output> <Output> Enter the exchange rate from dollars to RMB: 6.81 Enter 0 to convert dollars to RMB and 1 vice versa: 5 Incorrect input <End Output> 2

2. (10 pts) Write a program that prompts the user to enter an integer. If the number is a multiple of 5, print HiFive. If the number is divisible by 2 or 3, print Georgia. Here are the sample runs: <Output> Enter an integer: 6 Georgia <End Output> <Output> Enter an integer: 15 HiFive Georgia <End Output> <Output> Enter an integer: 25 HiFive <End Output> <Output> Enter an integer: 1 <End Output> 3

Name: Part III: Multiple Choice Questions: (1 pts each) (Please circle your answers on paper first. After you finish the test, enter your choices online to LiveLab. Log in and click Take Instructor Assigned Quiz. Choose Quiz1. You have 5 minutes to enter and submit the answers.) 1. The expression (int)(76.0252175 * 100) / 100 evaluates to. a. 76 b. 76.0252175 c. 76.03 d. 76.02 2. What is y after the following switch statement? int x = 0; int y = 0; switch (x + 1) { case 0: y = 0; case 1: y = 1; default: y = -1 a. 2 b. 1 c. 0 d. -1 3. Assume x is 0. What is the output of the following statement? if (x > 0) System.out.print("x is greater than 0"); else if (x < 0) System.out.print("x is less than 0"); else System.out.print("x equals 0"); a. x is less than 0 b. x is greater than 0 c. x equals 0 d. None 4

4. Analyze the following code: Code 1: boolean even; if (number % 2 == 0) even = true; else even = false; Code 2: boolean even = (number % 2 == 0); a. Code 2 has syntax errors. b. Code 1 has syntax errors. c. Both Code 1 and Code 2 have syntax errors. d. Both Code 1 and Code 2 are correct, but Code 2 is better. 5. What is the output of the following switch statement? char ch = 'a'; switch (ch) { case 'a': case 'A': System.out.print(ch); break; case 'b': case 'B': System.out.print(ch); break; case 'c': case 'C': System.out.print(ch); break; case 'd': case 'D': System.out.print(ch); a. ab b. a c. aa d. abc e. abcd 5

6. What is x after evaluating x = (2 > 3)? 2 : 3; a. 5 b. 2 c. 3 d. 4 7. Analyze the following code. int x = 0; if (x > 0); { System.out.println("x"); a. The value of variable x is always printed. b. The symbol x is always printed twice. c. The symbol x is always printed. d. Nothing is printed because x > 0 is false. 8. To declare a constant MAX_LENGTH inside a method with value 99.98, you write a. final double MAX_LENGTH = 99.98; b. double MAX_LENGTH = 99.98; c. final MAX_LENGTH = 99.98; d. final float MAX_LENGTH = 99.98; 9. Which of the following is a constant, according to Java naming conventions? a. read b. MAX_VALUE c. ReadInt d. Test 10. What is y after the following switch statement is executed? x = 3; switch (x + 3) { case 6: y = 0; case 7: y = 1; default: y += 1; 6

a. 1 b. 4 c. 3 d. 2 e. 0 11. Which of the following code displays the area of a circle if the radius is positive. a. if (radius <= 0) System.out.println(radius * radius * 3.14159); b. if (radius!= 0) System.out.println(radius * radius * 3.14159); c. if (radius >= 0) System.out.println(radius * radius * 3.14159); d. if (radius > 0) System.out.println(radius * radius * 3.14159); Please double check your answer before clicking the Submit button. Whatever submitted to LiveLab is FINAL and counted for your grade. Have you submitted your answer to LiveLib? What is your score? 7

Sample Final Exam for CSCI 1302 FINAL EXAM AND COURSE OUTCOMES MATCHING COURSE OUTCOMES 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: Question Matches outcomes 1 1 2 2 3 3, 4, 5 4 6, 7 5 1, 2, 3, 4, 5, 6, 7 1

Name: Covers chs8-19 Final Exam CSCI 1302 Introduction to Programming Armstrong Atlantic State University Instructor: Dr. Y. Daniel Liang 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. 2

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. 3

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. 4

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. 5

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 within 5 mins. 4. Close the Internet browser.) 1. describes the state of an object. a. data fields b. methods c. constructors d. none of the above 2. An attribute that is shared by all objects of the class is coded using. a. an instance variable b. a static variable c. an instance method d. a static method 3. If a class named Student has no constructors defined explicitly, the following constructor is implicitly provided. a. public Student() b. protected Student() c. private Student() d. Student() 4. If a class named Student has a constructor Student(String name) defined explicitly, the following constructor is implicitly provided. a. public Student() b. protected Student() c. private Student() d. Student() e. None 5. Suppose the xmethod() is invoked in the following constructor in a class, xmethod() is in the class. public MyClass() { xmethod(); a. a static method b. an instance method c. a static method or an instance method 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) { 6

xmethod(); a. a static method b. an instance method c. a static or an instance method 7. What would be the result of attempting to compile and run the following code? public class Test { static int x; public static void main(string[] args){ System.out.println("Value is " + x); 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 { 7

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 a. args[0] b. args[1] c. args[2] d. args[3] 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"); 8

a. Nothing. b. b is an instance of A. c. b is an instance of C. d. b is an instance of A followed by b is an instance of C. 14. When you implement a method that is defined in a superclass, you the original method. a. overload b. override c. copy d. call 15. What modifier should you use on a variable so that it can only be referenced inside its defining class. a. public b. private c. protected d. Use the default modifier. 16. 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. 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 { 9

public static void main(string[] args) { try { String s = "5.6"; Integer.parseInt(s); // Cause a NumberFormatException int i = 0; int y = 2 / i; System.out.println("Welcome to Java"); catch (Exception ex) { System.out.println(ex); 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. 18. What is displayed on the console when running the following program? class Test { public static void main(string[] args) { try { System.out.println("Welcome to Java"); int i = 0; int y = 2/i; System.out.println("Welcome to Java"); catch (RuntimeException ex) { System.out.println("Welcome to Java"); finally { System.out.println("End of the block"); a. The program displays Welcome to Java three times followed by End of the block. b. The program displays Welcome to Java two times followed by End of the block. 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") 10

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( new FileOutputStream("t.dat")); output.writeshort(1234); output.writeshort(5678); output.close(); a. 2 bytes. b. 4 bytes. c. 8 bytes. d. 16 bytes. Have you submitted your answer to LiveLib? 11