CIS 1068 Program Design and Abstraction Fall 2013 Final Exam

Size: px
Start display at page:

Download "CIS 1068 Program Design and Abstraction Fall 2013 Final Exam"

Transcription

1 Fall 2013 Name: Instructor s Name: Page Points Score Total: 100 Instructions The exam is closed book. You may not use a calculator, cell phone, etc. You may bring to the exam your own cheat sheet : one 8.5 x 11 sheet of paper with notes that you have written. You may use both sides of the sheet. If a question asks you to answer briefly, it means just that. A sentence or two at most should be sufficient. Unless otherwise specified, you may use functions from the standard Java library. Good luck. i

2 Some Reminders about Syntax Miscellaneous static boolean Arrays.equals(int[ ] a1, int[ ] a2); static void Arrays.sort(int[ ] a); static int Arrays.binarySearch(int[ ] a, int key); static String Arrays.toString(int[ ] a); static double Math.max(double d1, double d2); Object class boolean equals(object obj); // indicates if some other object is "equal to" this one String tostring( ); // returns a string representation of the object String class int indexof(string s); // returns position of s, -1 if not there int indexof(string s, int k); //returns position of s at or past position k char charat(int k); // returns character at position k String substring(int k); //substring starting at k up to end String substring(int k, int h); //substring starting at k ending at h excluded int compareto(string anotherstring); String touppercase( ); boolean equalsignorecase(string s); Files Scanner sc = new Scanner(System.in); Scanner sc = new Scanner(new File(filename)); boolean sc.hasnext( ); boolean sc.hasnextline( ); String sc.next( ); String sc.nextline( ); int sc.nextint( ); PrintWriter pw = new PrintWriter(new File(filenameString)); void close( ); // works for Scanner, PrintWriters

3 Short Answer Questions 1. Please provide a brief answer to each of the following: (1 point) (a) How many bytes are in a gigabyte? How many bits? (1 point) (b) In what component of a desktop computer is most of the computation done? (1 point) (c) About how fast can the component you mentioned in question (b) compute? (1 point) (d) What s the primary job of the Java compiler? (Hint: it s not to find the errors in my syntax.) (1 point) (e) Write the single line of code which declares an int x so that x is only directly accessible within its own class. (1 point) (f) What does it mean to override a method? (1 point) (g) What does it mean to say that a method is abstract? (2 points) 2. If it takes me 3 seconds to sort 1000 data points using a bubble sort (which is an O(n 2 ) algorithm), roughly how long should it take me to sort 3000 data points using the same bubble sort on the same machine? (4 points) 3. For the array below, circle each of the cells that is checked when a program executes a binary search to find the value What is the return value from the binary search? 3. out of a possible 13 1 of 12 exam continues...

4 Trace Me Questions (3 points) 4. What are the values of variables a, b, c, and d at Reference Point 1? 1 public class BooleanExpressions 2 3 public static void main(string [] args) 4 5 boolean P = true; 6 boolean Q = false; 7 boolean R = P!Q; 8 int X = 17; 9 10 boolean a = P && Q; 11 boolean b = (P && Q) (X > 10) 12 boolean c = P && (Q!R) 13 boolean d =!!Q; 14 // Reference Point (4 points) 5. Answer the question below about this method definition: 1 public static void display(double x, char c) 2 3 int y = x * x; 4 5 if (y > x) 6 System.out.println(c); 7 else if (y < x) 8 9 if(c== A ) 10 System.out.println("found an A "); 11 System.out.println("" + y + " is less than " + x); For each method call below, indicate what the method will display on the screen. Method Call display(2.0, A ); Displays on the screen display(0.5, 8 ); display(0.1, A ); display(0.0, D ); out of a possible 7 2 of 12 exam continues...

5 (3 points) 6. What s printed when we execute the following: 1 public class ForTest 2 public static void main(string [] args) 3 int x = 1; 4 for(; x < 0; x++) 5 System.out.println("x = " + x); 6 7 (3 points) 7. What s printed when we execute the following: 1 public class DoWhileTest 2 public static void main(string [] args) 3 int x = 1; 4 do 5 6 System.out.println("x = " + x); 7 x++; 8 while (x < 0); 9 10 (3 points) 8. What s printed when we execute the following: 1 public class WhatsPrinted00 2 public static void func(int x,int y,int z) 3 4 x *= 2; 5 y += x; 6 z = (x + y) % 2; 7 System.out.println(x + " " + 8 y + " " + z); public static void main(string args[]) int x = 10, y = 20, z = 30; 16 func(z, x, y); (3 points) 9. What s printed when we execute the following: 1 public class WhatsPrinted01 2 public static void func(int x,int y,int z) 3 4 x *= 2; 5 y += x; 6 z = (x + y) % 2; public static void main(string args[]) int x = 10, y = 20, z = 30; 12 func(z, x, y); 13 System.out.println(x + " " + y + " " + z); out of a possible 12 3 of 12 exam continues...

6 (3 points) 10. What s printed when we execute the following: 1 public class WhatsPrinted02 2 public static void func(int A[]) 3 for (int i=1; i<a.length; i++) 4 A[i]+=A[i-1]; public static void main(string args[]) 8 int A[] = 10,20,30; 9 func(a); 10 System.out.println(A[2]); (3 points) 11. What s printed when we execute the following: 1 public class WhatsPrinted public static int func(int A[], int B[]) 4 5 A = B; 6 return A[1]; public static void main(string args[]) 10 int A[] = 10,20,30; 11 int B[] = 40,50,60; int x = func(a, B); 14 System.out.println(x + " " + A[1]); (3 points) 12. What s printed when we execute the following: 1 class Stuff 2 int x; 3 4 public Stuff(int x) 5 this.x = x; 6 7 public void move() 8 x++; public class WhatsPrinted05 16 public static void func(stuff s) 17 s.move(); public static void main(string args[]) 21 Stuff a = new Stuff(10); 22 Stuff b = a; func(a); 25 b.move(); 26 System.out.println(a.x); out of a possible 9 4 of 12 exam continues...

7 (4 points) 13. The following two classes together have 9 different compile-time (syntax) errors. Circle the parts of the code where 4 of them occur (do not circle more than 4, you do not need to find them all). For each error that you circled, write a brief explanation of what the error is. 1 public class WillNotCompile 2 3 private int myfield = 3; 4 5 public static WillNotCompile(double initval) 24 public static void main(string [] args) 6 7 myfield = this.initval; public void getfield() return myfield; public static int setfield(int newval) this.myfield = newval; public class AlsoWillNotCompile WillNotCompile obj = 27 new WillNotCompile(7); obj.setfield(10); obj.myfield++; int final = WillNotCompile.getField() + 5; System.out.println(final); out of a possible 4 5 of 12 exam continues...

8 (6 points) 14. Given the following class definitions: 1 class Lack extends Liatorp 2 public void b() 3 System.out.println("Lack b"); class Liatorp 7 public void a() 8 System.out.println("Liatorp a"); 9 10 public void b() 11 System.out.println("Liatorp b"); public String tostring() 14 return "Liatorp"; class Ektorp extends Kvissle 18 public void a() 19 System.out.println("Ektorp a"); class Kvissle extends Lack 23 public void a() 24 System.out.println("Kvissle a"); public String tostring() 27 return "Kvissle"; IfwehaveLiatorp[ ] theflurgs = new Ektorp(), new Kvissle(), new Liatorp(), new Lack(), what s printed when we execute: (a) System.out.println(theFlurgs[0]); (b) System.out.println(theFlurgs[1]); (c) System.out.println(theFlurgs[2]); (d) System.out.println(theFlurgs[3]); (e) theflurgs[0].a(); (f) theflurgs[1].a(); (g) theflurgs[2].a(); (h) theflurgs[3].a(); (i) theflurgs[0].b(); (j) theflurgs[1].b(); (k) theflurgs[2].b(); (l) theflurgs[3].b(); (a) (b) (c) (d) (e) (f) (g) (h) (i) (j) (k) (l) out of a possible 6 6 of 12 exam continues...

9 Coding Questions (8 points) 15. (a) Write a static method abbreviate( ) which is passed a String s and an int max. The method returns a new String which contains the content of s abbreviated to at most max characters, but where the last three characters are ellipses (i.e., the characters...). For example, if s is "Too bad Spongebob s not here to enjoy Spongebob not being here. ---Squidward." and max is 10, the method returns the 10-character String "Too bad..." If s is shorter than max characters, return the original String. If max is less than 3 and less than the length of s, return the empty String. (2 points) (b) Write a main method that calls the abbreviate method twice, and prints the result to the screen each time. The first call should abbreviate the String "How now, brown cow?" down to 10 characters. The second call should abbreviate the result of the first abbreviation down to 5 characters. out of a possible 10 7 of 12 exam continues...

10 Secret Message (12 points) 16. Below is a partially filled-out CipherDocument class that contains a String [] lines as a field. Each element of lines contains one line of text in the document. But there is a secret message encoded in the CipherDocument! Write an instance method called getsecretmessage() that returns a String containing the second character of each word in the document, or a space if the word is only one letter long. Hint: Recall that you can construct a Scanner object on a String. That way you can find all of the words inside of the String by repeatedly calling the next() method. After this code runs, it should display "easy problem" on the screen. public class CipherDocument private String [] lines; public CipherDocument(String [] doclines) this.lines = doclines; public static void main(string [] args) String [] doc = "He sat us by a spinning drum.", "You obstinate old eel, Emma!"; CipherDocument cd = new CipherDocument(doc); String secretmessage = cd.getsecretmessage(); System.out.println(secretMessage); // your definition of the getsecretmessage() method goes here out of a possible 12 8 of 12 exam continues...

11 GradeBook 17. Below is a partially filled-out GradeBook class, which stores the names and grades of students in a course. Names are stored in an array of Strings. Grades are stored in a two-dimensional array of doubles, one row for each student, and one column for each test. public class GradeBook private String [] names; private double [][] grades; public GradeBook(String [] names, double [][] grades) this.names = names; this.grades = grades; // additional methods that you will write (see below) will go here (2 points) (a) Write a getter (or accessor) method for the GradeBook class that takes an int i as argument, and returns the name of the i th student. (5 points) (b) Implement an instance method which is passed an int row as an argument. The method should return the average of the grades on that row. out of a possible 7 9 of 12 question 17 continues...

12 (5 points) (c) Implement an instance method that determines the row of grades with the highest average. The method should return the row number. You may call the method from part b in your answer to this question. (3 points) (d) Write a class called Teacher that has just a main method. The main method should construct a GradeBook for a class with two students, "Jack" and "Jill". Jack s grades on the three tests for the class are 33, 55, and 77. Jill s grades are 99, 66, and 33. After constructing the GradeBook object, main should use the instance methods of the GradeBook class to determine the name of the student with the highest average grades. Print the name of this student on the screen. out of a possible 8 10 of 12 exam continues...

13 18. Consider the CellPhone class below. public class CellPhone private String phonenumber; // stores e.g. " " private String carrier; // stores e.g. "Verizon" private boolean incall = false; // stores whether the phone is currently in a call private String connectedto = null; // the number of the other phone being called public CellPhone(String number, String carrier) this.phonenumber = number; this.carrier = carrier; public void initiatecall(string otherphone) incall = true; connectedto = otherphone; public void stopcall() incall = false; connectedto = null; (3 points) (a) Write a tostring method for the CellPhone class. It should return something like "Verizon, ". out of a possible 3 11 of 12 question 18 continues...

14 (5 points) (b) Write a subclass of the CellPhone class called SmartPhone that will allow the client class PhoneUser below to execute. SmartPhone should have two new fields: one that stores the name of the type of phone (either "ios" or "Android"), and one that stores an array of names for Apps that are stored on the phone. The SmartPhone class should also have a constructor that does everything that the superclass s constructor does, plus it should initialize the type of phone and the array of Apps. public class PhoneUser public static void main(string [] args) String [] apps = "SnapChat", "Doodle Jump"; SmartPhone phone = new SmartPhone(" ", "AT&T", "ios", apps); phone.initiatecall(" "); phone.stopcall(); System.out.println(phone); (1 point) (c) Do you need to add a stopcall or initiatecall method to the SmartPhone class in order to make the PhoneUser class run properly? Why or why not? (1 point) (d) What does the PhoneUser class display on the screen when it is executed? (2 points) (e) What would we need to add (if anything) to the SmartPhone class in order for the command System.out.println(phone); to display everything that the CellPhone class s tostring method returns, plus the type of the SmartPhone object ("ios" or "Android")? out of a possible 9 12 of 12 end of exam

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013 Oct 4, 2013, p 1 Name: CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013 1. (max 18) 4. (max 16) 2. (max 12) 5. (max 12) 3. (max 24) 6. (max 18) Total: (max 100)

More information

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals 1 Recall From Last Time: Java Program import java.util.scanner; public class EggBasket { public static void main(string[]

More information

Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007

Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007 Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007 The Java Type System By now, you have seen a fair amount of Java. Time to study in more depth the foundations of the language,

More information

java Features Version April 19, 2013 by Thorsten Kracht

java Features Version April 19, 2013 by Thorsten Kracht java Features Version April 19, 2013 by Thorsten Kracht Contents 1 Introduction 2 1.1 Hello World................................................ 2 2 Variables, Types 3 3 Input/Output 4 3.1 Standard I/O................................................

More information

Object-Oriented Programming in Java

Object-Oriented Programming in Java CSCI/CMPE 3326 Object-Oriented Programming in Java Class, object, member field and method, final constant, format specifier, file I/O Dongchul Kim Department of Computer Science University of Texas Rio

More information

Sample CSE8A midterm Multiple Choice (circle one)

Sample CSE8A midterm Multiple Choice (circle one) Sample midterm Multiple Choice (circle one) (2 pts) Evaluate the following Boolean expressions and indicate whether short-circuiting happened during evaluation: Assume variables with the following names

More information

AP Computer Science Java Subset

AP Computer Science Java Subset APPENDIX A AP Computer Science Java Subset The AP Java subset is intended to outline the features of Java that may appear on the AP Computer Science A Exam. The AP Java subset is NOT intended as an overall

More information

AP Computer Science Java Mr. Clausen Program 9A, 9B

AP Computer Science Java Mr. Clausen Program 9A, 9B AP Computer Science Java Mr. Clausen Program 9A, 9B PROGRAM 9A I m_sort_of_searching (20 points now, 60 points when all parts are finished) The purpose of this project is to set up a program that will

More information

Course Intro Instructor Intro Java Intro, Continued

Course Intro Instructor Intro Java Intro, Continued Course Intro Instructor Intro Java Intro, Continued The syllabus Java etc. To submit your homework, do Team > Share Your repository name is csse220-200830-username Use your old SVN password. Note to assistants:

More information

Chulalongkorn University International School of Engineering Department of Computer Engineering 2140105 Computer Programming Lab.

Chulalongkorn University International School of Engineering Department of Computer Engineering 2140105 Computer Programming Lab. Chulalongkorn University Name International School of Engineering Student ID Department of Computer Engineering Station No. 2140105 Computer Programming Lab. Date Lab 2 Using Java API documents, command

More information

Preet raj Core Java and Databases CS4PR. Time Allotted: 3 Hours. Final Exam: Total Possible Points 75

Preet raj Core Java and Databases CS4PR. Time Allotted: 3 Hours. Final Exam: Total Possible Points 75 Preet raj Core Java and Databases CS4PR Time Allotted: 3 Hours Final Exam: Total Possible Points 75 Q1. What is difference between overloading and overriding? 10 points a) In overloading, there is a relationship

More information

CS 111 Classes I 1. Software Organization View to this point:

CS 111 Classes I 1. Software Organization View to this point: CS 111 Classes I 1 Software Organization View to this point: Data Objects and primitive types Primitive types operators (+, /,,*, %). int, float, double, char, boolean Memory location holds the data Objects

More information

First Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science

First Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science First Java Programs V. Paúl Pauca Department of Computer Science Wake Forest University CSC 111D Fall, 2015 Hello World revisited / 8/23/15 The f i r s t o b l i g a t o r y Java program @author Paul Pauca

More information

Part I. Multiple Choice Questions (2 points each):

Part I. Multiple Choice Questions (2 points each): Part I. Multiple Choice Questions (2 points each): 1. Which of the following is NOT a key component of object oriented programming? (a) Inheritance (b) Encapsulation (c) Polymorphism (d) Parallelism ******

More information

Computer Programming I

Computer Programming I Computer Programming I COP 2210 Syllabus Spring Semester 2012 Instructor: Greg Shaw Office: ECS 313 (Engineering and Computer Science Bldg) Office Hours: Tuesday: 2:50 4:50, 7:45 8:30 Thursday: 2:50 4:50,

More information

The following program is aiming to extract from a simple text file an analysis of the content such as:

The following program is aiming to extract from a simple text file an analysis of the content such as: Text Analyser Aim The following program is aiming to extract from a simple text file an analysis of the content such as: Number of printable characters Number of white spaces Number of vowels Number of

More information

1) Which of the following is a constant, according to Java naming conventions? a. PI b. Test c. x d. radius

1) Which of the following is a constant, according to Java naming conventions? a. PI b. Test c. x d. radius Programming Concepts Practice Test 1 1) Which of the following is a constant, according to Java naming conventions? a. PI b. Test c. x d. radius 2) Consider the following statement: System.out.println("1

More information

Introduction to Java

Introduction to Java Introduction to Java The HelloWorld program Primitive data types Assignment and arithmetic operations User input Conditional statements Looping Arrays CSA0011 Matthew Xuereb 2008 1 Java Overview A high

More information

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner. Handout 1 CS603 Object-Oriented Programming Fall 15 Page 1 of 11 Handout 1 Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner. Java

More information

Java Basics: Data Types, Variables, and Loops

Java Basics: Data Types, Variables, and Loops Java Basics: Data Types, Variables, and Loops If debugging is the process of removing software bugs, then programming must be the process of putting them in. - Edsger Dijkstra Plan for the Day Variables

More information

UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming

UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming 1 2 Foreword First of all, this book isn t really for dummies. I wrote it for myself and other kids who are on the team. Everything

More information

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program Free Java textbook available online "Thinking in Java" by Bruce Eckel, 4th edition, 2006, ISBN 0131872486, Pearson Education Introduction to the Java programming language CS 4354 Summer II 2015 The third

More information

File class in Java. Scanner reminder. Files 10/19/2012. File Input and Output (Savitch, Chapter 10)

File class in Java. Scanner reminder. Files 10/19/2012. File Input and Output (Savitch, Chapter 10) File class in Java File Input and Output (Savitch, Chapter 10) TOPICS File Input Exception Handling File Output Programmers refer to input/output as "I/O". The File class represents files as objects. The

More information

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program Free Java textbook available online "Thinking in Java" by Bruce Eckel, 4th edition, 2006, ISBN 0131872486, Pearson Education Introduction to the Java programming language CS 4354 Summer II 2014 Jill Seaman

More information

Chapter 2 Introduction to Java programming

Chapter 2 Introduction to Java programming Chapter 2 Introduction to Java programming 1 Keywords boolean if interface class true char else package volatile false byte final switch while throws float private case return native void protected break

More information

J a v a Quiz (Unit 3, Test 0 Practice)

J a v a Quiz (Unit 3, Test 0 Practice) Computer Science S-111a: Intensive Introduction to Computer Science Using Java Handout #11 Your Name Teaching Fellow J a v a Quiz (Unit 3, Test 0 Practice) Multiple-choice questions are worth 2 points

More information

Lab Experience 17. Programming Language Translation

Lab Experience 17. Programming Language Translation Lab Experience 17 Programming Language Translation Objectives Gain insight into the translation process for converting one virtual machine to another See the process by which an assembler translates assembly

More information

Week 1: Review of Java Programming Basics

Week 1: Review of Java Programming Basics Week 1: Review of Java Programming Basics Sources: Chapter 2 in Supplementary Book (Murach s Java Programming) Appendix A in Textbook (Carrano) Slide 1 Outline Objectives A simple Java Program Data-types

More information

Java Interview Questions and Answers

Java Interview Questions and Answers 1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write and compile the java

More information

Scanner sc = new Scanner(System.in); // scanner for the keyboard. Scanner sc = new Scanner(System.in); // scanner for the keyboard

Scanner sc = new Scanner(System.in); // scanner for the keyboard. Scanner sc = new Scanner(System.in); // scanner for the keyboard INPUT & OUTPUT I/O Example Using keyboard input for characters import java.util.scanner; class Echo{ public static void main (String[] args) { Scanner sc = new Scanner(System.in); // scanner for the keyboard

More information

COSC 1020 3.0 Introduction to Computer Science I Section A, Summer 2005. Question Out of Mark A Total 16. B-1 7 B-2 4 B-3 4 B-4 4 B Total 19

COSC 1020 3.0 Introduction to Computer Science I Section A, Summer 2005. Question Out of Mark A Total 16. B-1 7 B-2 4 B-3 4 B-4 4 B Total 19 Term Test #2 COSC 1020 3.0 Introduction to Computer Science I Section A, Summer 2005 Family Name: Given Name(s): Student Number: Question Out of Mark A Total 16 B-1 7 B-2 4 B-3 4 B-4 4 B Total 19 C-1 4

More information

Handout 3 cs180 - Programming Fundamentals Spring 15 Page 1 of 6. Handout 3. Strings and String Class. Input/Output with JOptionPane.

Handout 3 cs180 - Programming Fundamentals Spring 15 Page 1 of 6. Handout 3. Strings and String Class. Input/Output with JOptionPane. Handout 3 cs180 - Programming Fundamentals Spring 15 Page 1 of 6 Handout 3 Strings and String Class. Input/Output with JOptionPane. Strings In Java strings are represented with a class type String. Examples:

More information

Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013

Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013 Masters programmes in Computer Science and Information Systems Object-Oriented Design and Programming Sample module entry test xxth December 2013 This sample paper has more questions than the real paper

More information

Crash Course in Java

Crash Course in Java Crash Course in Java Based on notes from D. Hollinger Based in part on notes from J.J. Johns also: Java in a Nutshell Java Network Programming and Distributed Computing Netprog 2002 Java Intro 1 What is

More information

CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O

CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O 1 Sending Output to a (Text) File import java.util.scanner; import java.io.*; public class TextFileOutputDemo1 public static void

More information

Problem 1. CS 61b Summer 2005 Homework #2 Due July 5th at the beginning of class

Problem 1. CS 61b Summer 2005 Homework #2 Due July 5th at the beginning of class CS 61b Summer 2005 Homework #2 Due July 5th at the beginning of class This homework is to be done individually. You may, of course, ask your fellow classmates for help if you have trouble editing files,

More information

1.00 Lecture 1. Course information Course staff (TA, instructor names on syllabus/faq): 2 instructors, 4 TAs, 2 Lab TAs, graders

1.00 Lecture 1. Course information Course staff (TA, instructor names on syllabus/faq): 2 instructors, 4 TAs, 2 Lab TAs, graders 1.00 Lecture 1 Course Overview Introduction to Java Reading for next time: Big Java: 1.1-1.7 Course information Course staff (TA, instructor names on syllabus/faq): 2 instructors, 4 TAs, 2 Lab TAs, graders

More information

public static void main(string[] args) { System.out.println("hello, world"); } }

public static void main(string[] args) { System.out.println(hello, world); } } Java in 21 minutes hello world basic data types classes & objects program structure constructors garbage collection I/O exceptions Strings Hello world import java.io.*; public class hello { public static

More information

The Java Series. Java Essentials I What is Java? Basic Language Constructs. Java Essentials I. What is Java?. Basic Language Constructs Slide 1

The Java Series. Java Essentials I What is Java? Basic Language Constructs. Java Essentials I. What is Java?. Basic Language Constructs Slide 1 The Java Series Java Essentials I What is Java? Basic Language Constructs Slide 1 What is Java? A general purpose Object Oriented programming language. Created by Sun Microsystems. It s a general purpose

More information

Part 3: GridWorld Classes and Interfaces

Part 3: GridWorld Classes and Interfaces GridWorld Case Study Part 3: GridWorld Classes and Interfaces In our example programs, a grid contains actors that are instances of classes that extend the Actor class. There are two classes that implement

More information

Inheritance, overloading and overriding

Inheritance, overloading and overriding Inheritance, overloading and overriding Recall with inheritance the behavior and data associated with the child classes are always an extension of the behavior and data associated with the parent class

More information

Building Java Programs

Building Java Programs Building Java Programs Chapter 3 Lecture 3-3: Interactive Programs w/ Scanner reading: 3.3-3.4 self-check: #16-19 exercises: #11 videos: Ch. 3 #4 Interactive programs We have written programs that print

More information

How To Write A Program In Java (Programming) On A Microsoft Macbook Or Ipad (For Pc) Or Ipa (For Mac) (For Microsoft) (Programmer) (Or Mac) Or Macbook (For

How To Write A Program In Java (Programming) On A Microsoft Macbook Or Ipad (For Pc) Or Ipa (For Mac) (For Microsoft) (Programmer) (Or Mac) Or Macbook (For Projet Java Responsables: Ocan Sankur, Guillaume Scerri (LSV, ENS Cachan) Objectives - Apprendre à programmer en Java - Travailler à plusieurs sur un gros projet qui a plusieurs aspects: graphisme, interface

More information

CS170 Lab 11 Abstract Data Types & Objects

CS170 Lab 11 Abstract Data Types & Objects CS170 Lab 11 Abstract Data Types & Objects Introduction: Abstract Data Type (ADT) An abstract data type is commonly known as a class of objects An abstract data type in a program is used to represent (the

More information

Introduction to Programming

Introduction to Programming Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems sjmaybank@dcs.bbk.ac.uk Spring 2015 Week 2b: Review of Week 1, Variables 16 January 2015 Birkbeck

More information

Basic Object-Oriented Programming in Java

Basic Object-Oriented Programming in Java core programming Basic Object-Oriented Programming in Java 1 2001-2003 Marty Hall, Larry Brown http:// Agenda Similarities and differences between Java and C++ Object-oriented nomenclature and conventions

More information

AP Computer Science Static Methods, Strings, User Input

AP Computer Science Static Methods, Strings, User Input AP Computer Science Static Methods, Strings, User Input Static Methods The Math class contains a special type of methods, called static methods. A static method DOES NOT operate on an object. This is because

More information

Introduction to Programming System Design. CSCI 455x (4 Units)

Introduction to Programming System Design. CSCI 455x (4 Units) Introduction to Programming System Design CSCI 455x (4 Units) Description This course covers programming in Java and C++. Topics include review of basic programming concepts such as control structures,

More information

Programming Languages

Programming Languages Programming Languages Programming languages bridge the gap between people and machines; for that matter, they also bridge the gap among people who would like to share algorithms in a way that immediately

More information

Grundlæggende Programmering IT-C, Forår 2001. Written exam in Introductory Programming

Grundlæggende Programmering IT-C, Forår 2001. Written exam in Introductory Programming Written exam in Introductory Programming IT University of Copenhagen, June 11, 2001 English version All materials are permitted during the exam, except computers. The exam questions must be answered in

More information

COMPUTER SCIENCE. Paper 1 (THEORY)

COMPUTER SCIENCE. Paper 1 (THEORY) COMPUTER SCIENCE Paper 1 (THEORY) (Three hours) Maximum Marks: 70 (Candidates are allowed additional 15 minutes for only reading the paper. They must NOT start writing during this time) -----------------------------------------------------------------------------------------------------------------------

More information

qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq

qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq Introduction to Programming using Java wertyuiopasdfghjklzxcvbnmqwertyui

More information

Unit 6. Loop statements

Unit 6. Loop statements Unit 6 Loop statements Summary Repetition of statements The while statement Input loop Loop schemes The for statement The do statement Nested loops Flow control statements 6.1 Statements in Java Till now

More information

Computing Concepts with Java Essentials

Computing Concepts with Java Essentials 2008 AGI-Information Management Consultants May be used for personal purporses only or by libraries associated to dandelon.com network. Computing Concepts with Java Essentials 3rd Edition Cay Horstmann

More information

Explain the relationship between a class and an object. Which is general and which is specific?

Explain the relationship between a class and an object. Which is general and which is specific? A.1.1 What is the Java Virtual Machine? Is it hardware or software? How does its role differ from that of the Java compiler? The Java Virtual Machine (JVM) is software that simulates the execution of a

More information

Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following:

Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following: In creating objects of the type, we have used statements similar to the following: f = new (); The parentheses in the expression () makes it look like a method, yet we never created such a method in our

More information

Java Crash Course Part I

Java Crash Course Part I Java Crash Course Part I School of Business and Economics Institute of Information Systems HU-Berlin WS 2005 Sebastian Kolbe skolbe@wiwi.hu-berlin.de Overview (Short) introduction to the environment Linux

More information

INPUT AND OUTPUT STREAMS

INPUT AND OUTPUT STREAMS INPUT AND OUTPUT The Java Platform supports different kinds of information sources and information sinks. A program may get data from an information source which may be a file on disk, a network connection,

More information

Mobile App Design Project #1 Java Boot Camp: Design Model for Chutes and Ladders Board Game

Mobile App Design Project #1 Java Boot Camp: Design Model for Chutes and Ladders Board Game Mobile App Design Project #1 Java Boot Camp: Design Model for Chutes and Ladders Board Game Directions: In mobile Applications the Control Model View model works to divide the work within an application.

More information

Iteration CHAPTER 6. Topic Summary

Iteration CHAPTER 6. Topic Summary CHAPTER 6 Iteration TOPIC OUTLINE 6.1 while Loops 6.2 for Loops 6.3 Nested Loops 6.4 Off-by-1 Errors 6.5 Random Numbers and Simulations 6.6 Loop Invariants (AB only) Topic Summary 6.1 while Loops Many

More information

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives Introduction to Programming and Algorithms Module 1 CS 146 Sam Houston State University Dr. Tim McGuire Module Objectives To understand: the necessity of programming, differences between hardware and software,

More information

Software Engineering Techniques

Software Engineering Techniques Software Engineering Techniques Low level design issues for programming-in-the-large. Software Quality Design by contract Pre- and post conditions Class invariants Ten do Ten do nots Another type of summary

More information

CS 106 Introduction to Computer Science I

CS 106 Introduction to Computer Science I CS 106 Introduction to Computer Science I 01 / 21 / 2014 Instructor: Michael Eckmann Today s Topics Introduction Homework assignment Review the syllabus Review the policies on academic dishonesty and improper

More information

Basic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C

Basic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C Basic Java Constructs and Data Types Nuts and Bolts Looking into Specific Differences and Enhancements in Java compared to C 1 Contents Hello World Program Statements Explained Java Program Structure in

More information

LAB4 Making Classes and Objects

LAB4 Making Classes and Objects LAB4 Making Classes and Objects Objective The main objective of this lab is class creation, how its constructer creation, object creation and instantiation of objects. We will use the definition pane to

More information

Overview. java.math.biginteger, java.math.bigdecimal. Definition: objects are everything but primitives The eight primitive data type in Java

Overview. java.math.biginteger, java.math.bigdecimal. Definition: objects are everything but primitives The eight primitive data type in Java Data Types The objects about which computer programs compute is data. We often think first of integers. Underneath it all, the primary unit of data a machine has is a chunks of bits the size of a word.

More information

JAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system.

JAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system. http://www.tutorialspoint.com/java/java_quick_guide.htm JAVA - QUICK GUIDE Copyright tutorialspoint.com What is Java? Java is: Object Oriented Platform independent: Simple Secure Architectural- neutral

More information

Semantic Analysis: Types and Type Checking

Semantic Analysis: Types and Type Checking Semantic Analysis Semantic Analysis: Types and Type Checking CS 471 October 10, 2007 Source code Lexical Analysis tokens Syntactic Analysis AST Semantic Analysis AST Intermediate Code Gen lexical errors

More information

Chapter 13 - Inheritance

Chapter 13 - Inheritance Goals Chapter 13 - Inheritance To learn about inheritance To understand how to inherit and override superclass methods To be able to invoke superclass constructors To learn about protected and package

More information

CS193j, Stanford Handout #10 OOP 3

CS193j, Stanford Handout #10 OOP 3 CS193j, Stanford Handout #10 Summer, 2003 Manu Kumar OOP 3 Abstract Superclass Factor Common Code Up Several related classes with overlapping code Factor common code up into a common superclass Examples

More information

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. Exam Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) The JDK command to compile a class in the file Test.java is A) java Test.java B) java

More information

C# and Other Languages

C# and Other Languages C# and Other Languages Rob Miles Department of Computer Science Why do we have lots of Programming Languages? Different developer audiences Different application areas/target platforms Graphics, AI, List

More information

Java CPD (I) Frans Coenen Department of Computer Science

Java CPD (I) Frans Coenen Department of Computer Science Java CPD (I) Frans Coenen Department of Computer Science Content Session 1, 12:45-14:30 (First Java Programme, Inheritance, Arithmetic) Session 2, 14:45-16:45 (Input and Programme Constructs) Materials

More information

Lecture 11 Doubly Linked Lists & Array of Linked Lists. Doubly Linked Lists

Lecture 11 Doubly Linked Lists & Array of Linked Lists. Doubly Linked Lists Lecture 11 Doubly Linked Lists & Array of Linked Lists In this lecture Doubly linked lists Array of Linked Lists Creating an Array of Linked Lists Representing a Sparse Matrix Defining a Node for a Sparse

More information

Designing with Exceptions. CSE219, Computer Science III Stony Brook University http://www.cs.stonybrook.edu/~cse219

Designing with Exceptions. CSE219, Computer Science III Stony Brook University http://www.cs.stonybrook.edu/~cse219 Designing with Exceptions CSE219, Computer Science III Stony Brook University http://www.cs.stonybrook.edu/~cse219 Testing vs. Debugging Testing Coding Does the code work properly YES NO 2 Debugging Testing

More information

Java Programming Fundamentals

Java Programming Fundamentals Lecture 1 Part I Java Programming Fundamentals Topics in Quantitative Finance: Numerical Solutions of Partial Differential Equations Instructor: Iraj Kani Introduction to Java We start by making a few

More information

CS 1302 Ch 19, Binary I/O

CS 1302 Ch 19, Binary I/O CS 1302 Ch 19, Binary I/O Sections Pages Review Questions Programming Exercises 19.1-19.4.1, 19.6-19.6 710-715, 724-729 Liang s Site any Sections 19.1 Introduction 1. An important part of programming is

More information

CS 112/ Section 02 Hilal Ünal Aslıhan Ekim Merve Özkılınç Notes of March 11, 2008 and March 13, 2008: Pig Latin: add adday. main.

CS 112/ Section 02 Hilal Ünal Aslıhan Ekim Merve Özkılınç Notes of March 11, 2008 and March 13, 2008: Pig Latin: add adday. main. CS 112/ Section 02 Hilal Ünal Aslıhan Ekim Merve Özkılınç Notes of March 11, 2008 and March 13, 2008: Pig Latin: happy appyhay want antway add adday two consonants: the ethay main translate translateword

More information

CSE 2123 Collections: Sets and Iterators (Hash functions and Trees) Jeremy Morris

CSE 2123 Collections: Sets and Iterators (Hash functions and Trees) Jeremy Morris CSE 2123 Collections: Sets and Iterators (Hash functions and Trees) Jeremy Morris 1 Collections - Set What is a Set? A Set is an unordered sequence of data with no duplicates Not like a List where you

More information

Habanero Extreme Scale Software Research Project

Habanero Extreme Scale Software Research Project Habanero Extreme Scale Software Research Project Comp215: Java Method Dispatch Zoran Budimlić (Rice University) Always remember that you are absolutely unique. Just like everyone else. - Margaret Mead

More information

Event-Driven Programming

Event-Driven Programming Event-Driven Programming Lecture 4 Jenny Walter Fall 2008 Simple Graphics Program import acm.graphics.*; import java.awt.*; import acm.program.*; public class Circle extends GraphicsProgram { public void

More information

Java Cheatsheet. http://introcs.cs.princeton.edu/java/11cheatsheet/ Tim Coppieters Laure Philips Elisa Gonzalez Boix

Java Cheatsheet. http://introcs.cs.princeton.edu/java/11cheatsheet/ Tim Coppieters Laure Philips Elisa Gonzalez Boix Java Cheatsheet http://introcs.cs.princeton.edu/java/11cheatsheet/ Tim Coppieters Laure Philips Elisa Gonzalez Boix Hello World bestand genaamd HelloWorld.java naam klasse main methode public class HelloWorld

More information

Creating a Simple, Multithreaded Chat System with Java

Creating a Simple, Multithreaded Chat System with Java Creating a Simple, Multithreaded Chat System with Java Introduction by George Crawford III In this edition of Objective Viewpoint, you will learn how to develop a simple chat system. The program will demonstrate

More information

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language Translation Translating to Java Introduction to Computer Programming The job of a programmer is to translate a problem description into a computer language. You need to be able to convert a problem description

More information

Yosemite National Park, California. CSE 114 Computer Science I Inheritance

Yosemite National Park, California. CSE 114 Computer Science I Inheritance Yosemite National Park, California CSE 114 Computer Science I Inheritance Containment A class contains another class if it instantiates an object of that class HAS-A also called aggregation PairOfDice

More information

CS1020 Data Structures and Algorithms I Lecture Note #1. Introduction to Java

CS1020 Data Structures and Algorithms I Lecture Note #1. Introduction to Java CS1020 Data Structures and Algorithms I Lecture Note #1 Introduction to Java Objectives Java Basic Java features C Java Translate C programs in CS1010 into Java programs 2 References Chapter 1 Section

More information

Inside the Java Virtual Machine

Inside the Java Virtual Machine CS1Bh Practical 2 Inside the Java Virtual Machine This is an individual practical exercise which requires you to submit some files electronically. A system which measures software similarity will be used

More information

Exception Handling. Overloaded methods Interfaces Inheritance hierarchies Constructors. OOP: Exception Handling 1

Exception Handling. Overloaded methods Interfaces Inheritance hierarchies Constructors. OOP: Exception Handling 1 Exception Handling Error handling in general Java's exception handling mechanism The catch-or-specify priciple Checked and unchecked exceptions Exceptions impact/usage Overloaded methods Interfaces Inheritance

More information

CMSC 202H. ArrayList, Multidimensional Arrays

CMSC 202H. ArrayList, Multidimensional Arrays CMSC 202H ArrayList, Multidimensional Arrays What s an Array List ArrayList is a class in the standard Java libraries that can hold any type of object an object that can grow and shrink while your program

More information

Programming Languages CIS 443

Programming Languages CIS 443 Course Objectives Programming Languages CIS 443 0.1 Lexical analysis Syntax Semantics Functional programming Variable lifetime and scoping Parameter passing Object-oriented programming Continuations Exception

More information

An Incomplete C++ Primer. University of Wyoming MA 5310

An Incomplete C++ Primer. University of Wyoming MA 5310 An Incomplete C++ Primer University of Wyoming MA 5310 Professor Craig C. Douglas http://www.mgnet.org/~douglas/classes/na-sc/notes/c++primer.pdf C++ is a legacy programming language, as is other languages

More information

You are to simulate the process by making a record of the balls chosen, in the sequence in which they are chosen. Typical output for a run would be:

You are to simulate the process by making a record of the balls chosen, in the sequence in which they are chosen. Typical output for a run would be: Lecture 7 Picking Balls From an Urn The problem: An urn has n (n = 10) balls numbered from 0 to 9 A ball is selected at random, its' is number noted, it is set aside, and another ball is selected from

More information

Chapter 2 Elementary Programming

Chapter 2 Elementary Programming Chapter 2 Elementary Programming 2.1 Introduction You will learn elementary programming using Java primitive data types and related subjects, such as variables, constants, operators, expressions, and input

More information

A TOOL FOR DATA STRUCTURE VISUALIZATION AND USER-DEFINED ALGORITHM ANIMATION

A TOOL FOR DATA STRUCTURE VISUALIZATION AND USER-DEFINED ALGORITHM ANIMATION A TOOL FOR DATA STRUCTURE VISUALIZATION AND USER-DEFINED ALGORITHM ANIMATION Tao Chen 1, Tarek Sobh 2 Abstract -- In this paper, a software application that features the visualization of commonly used

More information

Limitations of Data Encapsulation and Abstract Data Types

Limitations of Data Encapsulation and Abstract Data Types Limitations of Data Encapsulation and Abstract Data Types Paul L. Bergstein University of Massachusetts Dartmouth pbergstein@umassd.edu Abstract One of the key benefits provided by object-oriented programming

More information

MIDTERM 1 REVIEW WRITING CODE POSSIBLE SOLUTION

MIDTERM 1 REVIEW WRITING CODE POSSIBLE SOLUTION MIDTERM 1 REVIEW WRITING CODE POSSIBLE SOLUTION 1. Write a loop that computes (No need to write a complete program) 100 1 99 2 98 3 97... 4 3 98 2 99 1 100 Note: this is not the only solution; double sum

More information

2 The first program: Little Crab

2 The first program: Little Crab 2 The first program: Little Crab topics: concepts: writing code: movement, turning, reacting to the screen edges source code, method call, parameter, sequence, if statement In the previous chapter, we

More information

Project 2: Bejeweled

Project 2: Bejeweled Project 2: Bejeweled Project Objective: Post: Tuesday March 26, 2013. Due: 11:59PM, Monday April 15, 2013 1. master the process of completing a programming project in UNIX. 2. get familiar with command

More information

CS1002: COMPUTER SCIENCE OO MODELLING & DESIGN: WEEK 5

CS1002: COMPUTER SCIENCE OO MODELLING & DESIGN: WEEK 5 This Week CS1002: COMPUTER SCIENCE OO MODELLING & DESIGN: WEEK 5 School of Computer Science University of St Andrews Graham Kirby Alan Dearle More on Java classes Constructors Modifiers cdn.videogum.com/img/thumbnails/photos/commenter.jpg

More information