Final Exam, Version 1 Solutions - MIT OpenCourseWare [PDF]

May 11, 2005 - Compiling and Executing Java Code (20 points). The questions in this section refer to the incorrect Echo

0 downloads 5 Views 255KB Size

Recommend Stories


Final Exam Solutions
The happiest people don't have the best of everything, they just make the best of everything. Anony

Solutions to Final Exam
Stop acting so small. You are the universe in ecstatic motion. Rumi

Final Exam Solutions Good Luck!!
No amount of guilt can solve the past, and no amount of anxiety can change the future. Anonymous

EECE2412 Final Exam with Solutions
Make yourself a priority once in a while. It's not selfish. It's necessary. Anonymous

The Creation of OpenCourseWare at MIT
What you seek is seeking you. Rumi

Solutions to Review for Final Exam
Ask yourself: What are the biggest actions you can take now to create the biggest results in your life?

Solutions to Math 41 Final Exam
Ego says, "Once everything falls into place, I'll feel peace." Spirit says "Find your peace, and then

Doktorarbeit mit englischer PDF Version
Raise your words, not voice. It is rain that grows flowers, not thunder. Rumi

TTC FINAL VERSION 4.11.pdf
You can never cross the ocean unless you have the courage to lose sight of the shore. Andrè Gide

Final Exam
Almost everything will work again if you unplug it for a few minutes, including you. Anne Lamott

Idea Transcript


MASSACHUSETTS INSTITUTE OF TECHNOLOGY SP.772 FINAL EXAMINATION WEDNESDAY, MAY 11, 2005 INSTRUCTIONS: You have three hours to complete this exam. There are 230 total possible points. Good luck. Name: Java Basics: Expressions and Statements (10 points).................................................................... 2 Compiling and Executing Java Code (20 points) ........................................................................... 3 Methods (25 points) ........................................................................................................................ 5 Writing a Basic Class (35 points) ................................................................................................... 6 Inheritance, Access Control, and Field Modifiers (35 points)........................................................ 8 Implementing an Interface (40 points).......................................................................................... 10 Exceptions (25 points) .................................................................................................................. 12 I/O and Parsing (25 points) ........................................................................................................... 13 Swing (15 points).......................................................................................................................... 14 APPENDIX: Specifications of Selected Java Classes ................................................................. 15 public abstract class InputStream extends Object .......................................................... 15 public abstract class OutputStream extends Object........................................................ 15 public abstract class Reader extends Object ...................................................................... 16 public abstract class Writer extends Object ...................................................................... 16 public class StringTokenizer extends Object implements Enumeration ............... 17

Java Basics: Expressions and Statements (10 points) 1. (4 pts) Given the declaration int x = 9, what is the value of the following expressions?

x / 3.0 / 6 * 2

=

14 % (x / 5 + 1)

=

--x + ++x

=

--x == x++

=

1 0 17 true

2. (6 pts) Rewrite the following code segment using if-else statements. Assume that grade has been declared as a type char. switch (grade) { case 'A': System.out.println("Excellent"); case 'B': System.out.println("Good"); case 'C': System.out.println("OK"); default: System.out.println("Let's talk"); } if (grade == ‘A’) System.out.println(“Excellent”); if (grade == ‘A’ || grade == ‘B’) System.out.println(“Good”); if (grade == ‘A’ || grade == ‘B’ || grade == ‘C’) System.out.println(“OK”); System.out.println(“Let’s talk”); Other solutions possible. Full credit given for semantically correct solutions. 5 points for correctly translating as if there were break statements. Partial Credit: +5 – Realize there are no break statements

2

Compiling and Executing Java Code (20 points) The questions in this section refer to the incorrect Echo program below. The Echo program accepts arguments from the command line and prints them (echoes them) to the screen. Line numbers are included for your reference and are not part of the program code. You may find it helpful to read all of the questions before beginning this section. 1 2 3 4 6 7 8 9 10 11 12 13

public class Echo { public static void main(String[] args) { print(args); } static void print(String[] greetings) { for (int i = 0; i

Smile Life

When life gives you a hundred reasons to cry, show life that you have a thousand reasons to smile

Get in touch

© Copyright 2015 - 2024 PDFFOX.COM - All rights reserved.