CS100J Prelim I, 29 Sept. 2003

Similar documents
CS100J Prelim 1 22 February 2007

CS100J, Fall 2003 Preparing for Prelim 1: Monday, 29 Sept., 7:30 9:00PM

Lecture 10. Overriding & Casting About

CS211 Prelim Oct 2001 NAME NETID

Notes on Chapter Three

CS 1110 Prelim 2 November 6th, 2012

CS/ENGRD 2110 FALL Lecture 5: Local vars; Inside-out rule; constructors

CS32 - Week 4. Umut Oztok. Jul 15, Umut Oztok CS32 - Week 4

1B1b Classes in Java Part I

Abstract class & Interface

Classes and Objects 3/28/2017. How can multiple methods within a Java class read and write the same variable?

CS 100J Prelim 2 Have a good break!!! 15 March 2007

Java Object Oriented Design. CSC207 Fall 2014

C a; C b; C e; int c;

a) Answer all questions. b) Write your answers in the space provided. c) Show all calculations where applicable.

CS 1110 Prelim 1 October 4th, 2012

Programming Using C# QUEEN S UNIVERSITY BELFAST. Practical Week 7

CMP-326 Total 120 Points Final Fall 2012

Software and Programming 1

Goals for Today. CSE1030 Introduction to Computer Science II. CSE1030 Lecture #9. Review is-a versus has-a. Lecture #9 Inheritance I

Informatik II. Tutorial 6. Mihai Bâce Mihai Bâce. April 5,

CS 1110 Prelim 2 November 13th, 2014

Prelim 1. CS 2110, March 15, 2016, 5:30 PM Total Question Name True False. Short Answer

CS 1110 Prelim 2 November 10th, 2016

CS 1110 Prelim 2 November 12th, 2015

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

COMP 401 Fall 2014 Midterm 2

1 (5pts) 2 (20 pts) 3 (20 pts) 4 (10 pts) 5 (15 pts) 6 (30 pts) Total NAME: CU ID: Recitation instructor/time

Readings for This Lecture

Questions Answer Key Questions Answer Key Questions Answer Key

Week 5-1: ADT Design

Function Overloading

What is an algorithm?

Informatik II Tutorial 6. Subho Shankar Basu

Announcements for the Class

Informatik II (D-ITET) Tutorial 6

What is an algorithm?

Rectangle. Lecture 2 week 2 - Objects & Classes Exercise 1. A. Write a driver class code in java depending on the following UML:

CS Prelim 2 Review Fall 2014

Prelim 1. CS 2110, March 15, 2016, 7:30 PM Total Question Name True False. Short Answer

CS 1331 Exam 1. Fall Failure to properly fill in the information on this page will result in a deduction of up to 5 points from your exam score.

Darrell Bethea June 6, 2011

Tutorial 4. public class Stock { private int numberofshares; private double dividend; private String TickerSymbol;

Week 3 Classes and Objects

IS-A is a way of saying: This object is a type of that object. Let us see how the extends keyword is used to achieve inheritance.

COMP 401 Fall 2014 Midterm 2

Inheritance & Polymorphism Recap. Inheritance & Polymorphism 1

Distributed Systems Recitation 1. Tamim Jabban

Chapter 3 Classes. Activity The class as a file drawer of methods. Activity Referencing static methods

Lecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University

CS 1110 Prelim 2 November 14th, 2013

Object Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming

Inheritance and Polymorphism

Relationships Between Real Things CSE 143. Common Relationship Patterns. Employee. Supervisor

Prelim 1 Solutions. CS 2110, March 10, 2015, 5:30 PM Total Question True False. Loop Invariants Max Score Grader

Object Oriented Programming

Scope. Scope is such an important thing that we ll review what we know about scope now:

CS1150 Principles of Computer Science Objects and Classes

Abstract Classes and Interfaces

An example from Zoology

CS 1110 Prelim 2 November 12th, 2015

Assignment3 CS206 Intro to Data Structures Fall Part 1 (50 pts) due: October 13, :59pm Part 2 (150 pts) due: October 20, :59pm

COMP 401 Spring 2013 Midterm 1

CISC-124. Dog.java looks like this. I have added some explanatory comments in the code, and more explanation after the code listing.

5.6.1 The Special Variable this

Relationships Between Real Things. CSE 143 Java. Common Relationship Patterns. Composition: "has a" CSE143 Sp Student.

Object Oriented Programming (II)

Relationships Between Real Things CSC 143. Common Relationship Patterns. Composition: "has a" CSC Employee. Supervisor

CS Prelim 2 Review Fall 2015

CS 1110 Final, December 16th, 2013

Islamic University of Gaza Faculty of Engineering Computer Engineering Department

Basic Object-Oriented Concepts. 5-Oct-17

COMP 401 Spring 2013 Midterm 2

COMP 249: Object Oriented Programming II. Tutorial 2: Intro to Inheritance

UML IB Computer Science. Content developed by Dartford Grammar School Computer Science Department

Name: Username: I. 20. Section: II. p p p III. p p p p Total 100. CMSC 202 Section 06 Fall 2015

XC Total Max Score Grader

CIT Special final examination

CS 1331 Exam 1 ANSWER KEY

CS/ENGRD 2110 FALL Lecture 6: Consequence of type, casting; function equals

Java Session. Day 2. Reference: Head First Java

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

CSCI 136 Data Structures & Advanced Programming. Lecture 3 Fall 2017 Instructors: Bill & Bill

Inheritance (Part 5) Odds and ends

Question 0. (out of 01) Question 1. (out of 10) Question 2. (out of 12) Question 3. (out of 12) Question 4. (out of 12) Question 5.

EKT472: Object Oriented Programming. Overloading and Overriding Method

CSE 331 Summer 2017 Final Exam. The exam is closed book and closed electronics. One page of notes is allowed.

CS 1110 Final, December 16th, 2013

CS 1110 Final, December 8th, Question Points Score Total: 100

PREPARING FOR PRELIM 2

Prelim 1. CS 2110, October 1, 2015, 5:30 PM Total Question Name True Short Testing Strings Recursion

AP CS Unit 8: Inheritance Exercises

Classes, objects, references, encapsulation and whatnot

Classes, objects, references, encapsulation and whatnot

COMP 401 Spring 2014 Midterm 1

CSCI 135 Exam #2 Fundamentals of Computer Science I Fall 2013

CSC 210, Exam Two Section February 1999

Prelim One Solution. CS211 Fall Name. NetID

COMP 401 Spring 2013 Midterm 2

Abstract Classes. Abstract Classes a and Interfaces. Class Shape Hierarchy. Problem AND Requirements. Abstract Classes.

Transcription:

CS100J Prelim I, 29 Sept. 2003 CORNELL NETID NAME (PRINT LEGIBLY!) (last, first) Question 0 out of 02 This 90-minute exam has 6 questions worth a total of 100 points. Question 1 out of 20 We suggest that you spend a few minutes looking at all questions before beginning so that you can see what is expected. Budget your Question 2 out of 20 time wisely. Use the back of the pages, if you need more space. Question 3 out of 18 Question 0 (2 points). Write your netid and your name, legibly, at the top of each page. Question 1 (20 points). Write the body of method fixcase, which is specified below. Remember that a string can be empty (can contain 0 characters). Also, class String has the following methods: s.charat(k) = the character at position (or index) k of string s s.substring(h, k) = a string consisting of characters s[h], s[h+1],, s[k 1] s.substring(h) = a string consisting of characters s[h], s[h+1],, s[s.length() 1] s.tolowercase() = s but with all its letters in lower case s.touppercase() = s but with all its letters in upper case s.indexof(c) = index of the first occurrence of character c in s (-1 if none) /** If the first character of s is a, then return s but with all its letters in lower case. If the first character of s is A, then return s but with all its letters in upper case. If the first character of s is a blank, then return s but with the first occurrence of new line character \n in it removed (if present). Otherwise, return s. */ public String fixcase(string s) { Question 4 out of 20 Question 5 out of 20 Total out of 100 1

Question 2 (20 points). Below are two class definitions, for classes MP and S. (a) Draw a manilla folder (or instance, or object) of class MP. (b) Draw a manilla folder of class S. Note that both fields in S are given by initializing declarations. You have to draw the values in these fields correctly. If this requires drawing new folders, do so. public class MP { public class S extends MP{ private int d= 5; private MP one= null; public static int x= 0; private MP two= new MP(); public void m(string p) { public static final double pi= 3.14; d= p.length(); public void setd(int v) { d= v; x= x + 1; 2

Question 3 (18 points). This question deals with classes Animal and Lion, shown below, and two variables x and y declared as: Animal x; Lion y; (a) Write down the names of methods that class Lion inherits. (b) Write down the names of methods in class Lion that override other methods. (c) Write a syntactically legal assignment that assigns x to y. (d) Suppose x contains the name of a folder of class Lion. Is the expression x.tostring() legal? If yes, what method does it call? (e) Suppose x contains the name of a folder of class Lion. Is the expression x.noise() legal? If yes, what method does it call? (f) Suppose y contains a Lion with name Narasimhan and age 1008. Write down the value of expression y.tostring(). // An instance is an animal with a name and age public class Animal { // Name of this animal (e.g. Fido ) private String name= ; // Age of this animal private int age= 0; // = this animal s age public int getage() { return age; // = this animal s name public String getname() { return name; // Set this animal s name to n public void setname(string n) { name= n; // Set this animal s age to b public void setage(int b) {age= b; return name +, + age; // An instance is a lion, which makes a noise public class Lion extends Animal{ // = the noise this lion makes public String noise() { if (getage() < 1) return mew! ; return roar! ; return super.tostring() +, + noise(); 3

Question 4 (20 points). This question deals with classes Animal and Lion (they are the same as in exercise 3). Write a subclass Horse of Animal. It needs one field, which contains the number of horns that the horse has (e.g. unicorns are a kind of mythical horse that have one horn). Please write getter and setter methods for the field. Write methods noise() and tostring() they should do something reasonable, based on those methods in other classes. // An instance is an animal with a name and age public class Animal { // Name of this animal (e.g. Fido ) private String name= ; // Age of this animal private int age= 0; // = this animal s age public int getage() { return age; // = this animal s name public String getname() {return name; // Set this animal s name to n public void setname(string n) { name= n; // Set this animal s age to b public void setage(int b) {age= b; return name +, + age; // An instance is a lion, which makes a noise public class Lion extends Animal{ // = the noise this lion makes public String noise() { if (getage() < 1) return mew! ; return roar! ; return super.tostring() +, + noise(); 4

Question 5 (20 points). (a) Define the term parameter. 0 out of 02 1 out of 20 2 out of 20 3 out of 18 4 out of 20 (b) Define the term argument. 5 out of 20 Total out of 100 (c) Give the syntax of the assignment statement and explain how to execute an assignment statement. (d) What is a local variable, and what is its scope? (e) Suppose a function body is being executed because of a function call. What kind of statement causes the function body to terminate? 5