2 Pages

Self help exercise- evaluating new expressions

Course: CS 101, Spring 2008
School: Cornell
Rating:
 
 
 
 
 

Word Count: 207

Document Preview

exercises: Self-help evaluating new-expressions As mentioned in the lecture, evaluation of a new expression like new Animal() is a two-step process: 1. Create (or draw) a new manila folder (object) of class Animal; 2. Yield as value of the new-expression the name (on the tab) of the new object. It is important that you (1) understand this two-step process and (2) can carry it out yourself. The best way to learn...

Register Now

Unformatted Document Excerpt

Coursehero >> New York >> Cornell >> CS 101

Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Course Hero has millions of student submitted documents similar to the one below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.
exercises: Self-help evaluating new-expressions As mentioned in the lecture, evaluation of a new expression like new Animal() is a two-step process: 1. Create (or draw) a new manila folder (object) of class Animal; 2. Yield as value of the new-expression the name (on the tab) of the new object. It is important that you (1) understand this two-step process and (2) can carry it out yourself. The best way to learn this is to evaluate a new-expression ourself, carrying out the two steps. Do not procrastinate; do the two exercises below immediately, before going on to the next lecture. 1. Below are three assignments that refer to class and Animal class Patient (see the objects given below for the format), used in a previous lecture. First, draw variables p and q on a piece of paper, with value null in them. Then, execute these three assignments, one after the other, evaluating any new-expressions that have to be evaluated and storing the results in the indicated variables. Here is the answer. p= new Animal(); q= new Patient(); p= new Animal(); Solution: There are two variables, p and q, initially containing null. After execution of these assignments: p= new Animal(); q= new Patient(); p= new Animal(); the variables and created objects look like this:
Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more. Course Hero has millions of course specific materials providing students with the best way to expand their education.

Below is a small sample set of documents:

Cornell - CS - 101
Self-help exercise: Drawing objectsIt is important that you be able to draw manila folders (objects) of a class when you have to. The need will arise when executing some part of a program by hand in order to find an error. Further, the ability to dr
Cornell - CS - 101
PackagesIn the previous lecture, we used the class name javax.swing.JFrame. In this little lecture, we show how it can be abbreviated as JFrame. In Java, a package is a collection of classes that reside in the same directory on your hard drive. In o
Cornell - CS - 101
Types and referencing components of an objectA class name like Patient is also considered to be a type. Its values are the names of manila folders, or objects, of that class. The type has no operations, because one shouldn't be able to operate on th
Cornell - CS - 101
The class definitionWe write our first Java class, in the upper right pane of DrJava. This class definition will describe the components that are placed in each manilla folder, or object, of the class. We start by putting a comment that indicates wh
Cornell - CS - 101
Field declarations and getter/setter methodsConsider writing a class Chapter. Each instance of Chapter will contain information about a chapter of a book, like the chapter number, so we need to declare a variable in the class. The basic form of a de
Cornell - CS - 101
The subclass definitionThe manila folder for subclass Demo Here is a manilla folder -an object or instance- of class JFrame. The tab contains the name of the folder, the name of the class appear in the upper right, and we show only some of the meth
Cornell - CS - 101
Function and Procedure CallsA function call has the form <function-name> ( <arguments> ) and a procedure call has the form <procedure-name> ( <arguments> ) ; / this is a statement / this is an expressionwhere <arguments> is a sequence of expressio
Cornell - CS - 101
Executing method callsIntroduction It is important that you understand how a method call is executed, for several reasons. This knowledge will give you a better understanding of how a program is executed. You may have to execute a call yourself, by
Cornell - CS - 101
Conditional statements and loopsIntroductionEvery procedural programming language has conditional statements (if-statements) and iterative statements (loops). You should be familiar with the concepts -unless your only previous programming language
Cornell - CS - 101
Arrays in JavaIntroductionJava, like most programming languages has arrays -lists of elements of a certain type, where the size of a list is fixed when the array is first created. In Java, arrays are objects. We provide a very brief summary of one-
Cornell - CS - 101
Other wrapper classesEach primitive type has a corresponding wrapper class, which wraps a value of that type and provides constants and functions dealing with that primitive type. We do not go into detail here. Look at the API specs on the web or th
Cornell - CS - 101
Constraining the elements of an ArrayListYou now know that you can create an instance of class java.util.ArrayList and save it using an assignment like ArrayList b= new ArrayList(); The elements of this list have the apparent class Object. When an
Cornell - CS - 101
Class ArrayListAn instance of class java.util.ArrayList contains a list of objects. It may be a list of the courses you have taken, a list of high temperatures for each day in Ithaca in 2006, or a list of objects of totally different classes. There
Cornell - CS - 101
/* Autoboxing Integer b; b= 25; int i; i= b; / Illegal in java version 4: the types / of variable and expression don't match / Illegal in java version 4: the types / of variable and expression don't match= The assignments work in Java version 5 and
Cornell - CS - 101
import junit.framework.TestCase; public class PandaTester extends TestCase { public void testConstructor() { Panda p1 = new Panda("Shuaung",2,null); assertEquals("Shuang",p1.getName(); assertEquals(2,p1.getChild(); assertEquals(null,p1.getFather(); P
Cornell - CS - 101
Javadoc specificationsA programmer who wants to use your program should be able to look at the specification of the program, its documentation, without having to look at the code itself. Java has a facility for extracting documentation from your pr
Cornell - CS - 101
Introduction to debuggingTesting is the process of running the program against test cases to try to uncover errors. Debugging is the process of looking for the cause of an uncovered error and then fixing it -once the cause has been found. Often the
Cornell - CS - 101
ConstructorsHere's class Chapter, with three fields, the chapter number, chapter title, and the previous chapter. Here is an instance of that class, created using an assignment c= new Chapter(); . The only way to initialize the fields of the new ins
Cornell - CS - 101
import javax.swing.*; /* Answers to self-help exercises on writing your own subclass of JFrame. */ public class JFrameFun extends JFrame { /* Swap the width and height of this window. */ public void SwapHtAndWidth() { setSize(getHeight(), getWidth();
Cornell - CS - 101
Writing your own subclass of JFrameIt is important that you practice writing Java classes, and methods within them, especially in the beginning. Below, we provide some simple exercises in creating subclasses of class JFrame, as done in the topic 2 o
Cornell - CS - 101
When you have completed module 1, part 6, on objects and classes, please ask a consultant to give you a quiz on this material. The purpose of the quiz is to make sure that you understand OO concepts, can draw an object (manila folder) for a class, an
Cornell - CS - 101
Functions toString and equals in class ObjectFunction toString in class Object Function toString in class Object is defined to return the name of the manilla folder, or object in which it appears. For example, evaluate this expression in DrJava's in
Cornell - CS - 101
/* Write a function toString, which gives the values of the fields, in a format that is easy to read. */ /* An instance maintains public class Chapter { private int number; private String title; private Chapter prev; /* = info about a book chapter */
Cornell - CS - 101
TestingTesting is the process of running a program against "test cases" in order to get some evidence of the correctness of the program. If an error is discovered, then the process of debugging attempts to locate the error and fix it. This topic is
Cornell - CS - 101
Specifications of methodsYou know what the first function mini does, because its specification, in the comment preceding it, tells you. You don't need the function body -which we show you now. You have no idea what the second function does, because
Cornell - CS - 101
Wrapper classesAn instance of class Integer contains a field of type int. We haven't given the name of the field because we don't know it. But there is a getter method for it, intValue(). In fact, one can obtain the int value as a primitive value of
Cornell - CS - 101
Finding API specs on the webThe Java API specifications describe what each class that comes with Java is for and how it is to be used. These specifications are on the world wide web, so you have to be connected to the internet to use them. You can
Cornell - CS - 101
AutoboxingUp through version 4 of Java, an assignment like Integer b; b= 25; int i; i= b; were illegal, because the types of the variable and expression did not match -one is an int and the other is class Integer. In version 5 of Java, autoboxing w
Cornell - CS - 101
/* An instance is a point (x, y) in the plane */ public class Point { /* The x and y coordinates of a point */ private double x; private double y; /* Constructor: a point (b, c) */ public Point(double b, double c) { x= b; y= c; } /* = a representatio
Cornell - CS - 101
Return StatementsExecution of a return statement terminates execution of the method body and, hence, of the method call. The return statement in the body of a function differs from the return statement in a procedure or constructor. See below.The
Cornell - CS - 101
Method HeadersWe summarize method headers, define the signature of a method, and discuss its use. This material is covered in more detail in the course text, Gries/Gries. A method declaration consists of a specification (as a comment), a method head
Cornell - CS - 101
Declaring local variables where they belong, logically speakingWe discuss the placement of local variable declarations. Generally, the declarations should go where they belong, logically speaking, and this usually means placing them as close to the
Cornell - CS - 101
Local variablesA local variable is a variable that is declared within a method body. The program you see has two different local variables, both named temp. The syntax of a local variable declaration is: <type> <variable-name> ; and it can be an in
Cornell - CS - 101
Specifications of methodsYou know what the first function mini does, because its specification, in the comment preceding it, tells you. You don't need the function body -which we show you now. You have no idea what the second function does, because
UCF - HUM - 2210
Part 1: The Beginning of Civilization Chap. 1-31. Prehistoric To Civilized Societies (Ch. 1) a. Stone Age Society i. Hunting-gathering to farming settlements ii. Stone and wooden tools to copper b. Religion i. Animism (25): All nature is alive like
UCF - HUM - 2210
Part II: The Greek Legacy: Triumph Humanism and Reason1. Individualism and the Greek Community (Vol. 1, Chap 5 & 6) a. Heroic Age (1200-750 B.C.): i. Homer (750 BC) creates "Epic Heroes" to build a new culture for his time after "dark ages." ii. Ba
UCF - HUM - 2210
Huynh, Quoc July 2, 2008 HUM-2210 Dr. EvansPart 3: Pax Romana and Roman Legacy, Chap 81. Major Impact of Roman Society a. Government: i. Republic (Res publica) = rule by people (509-31 BC). Elected representatives ii. Forum = common plaza for mee
UCF - HUM - 2210
Part IV: The Shaping of the middle Ages1. The Beginning of Christianity: Ch. 9 a. Jewish Backgrounds i. Hebrew Bible (Torah = Law of Moses): becomes Christian "Old Testament" ii. Monotheism: one universal God for all iii. Supernatural Beings: demon
UCF - HUM - 2210
EvansHUM 2211REVIEW SHEETEXAM 1LISTS 1. Features that identify a society as "civilized" 2. Geographical areas of early civilizations 3. Ages of early Greek mythology to Ovid 4. Dominant and alternate cultural themes in the Iliad 5. Literary w
LSU - PSYCH - 3081
Chapter 20: Summary and Possible Future DirectionsIntroductionPersonality psychologists seek to understand the whole of personality However, understanding the whole may be impossible Instead, the difficult task of understanding the whole person is
LSU - PSYCH - 3081
Chapter 19: Disorders of PersonalityThe Concept of DisorderPsychological disorder o Pattern of behavior or experience that is distressing and painful to the person o Leads to disability or impairment in important life domains o Associated with the
LSU - PSYCH - 3081
Chapter 18: Stress, Coping, Adjustment, and Health Models of the Personality-Illness ConnectionInteractional model o Objective events happen to a person, but personality determines the impact of events by influencing a person's ability to copy o Per
LSU - PSYCH - 3081
Chapter 17: Culture and PersonalityIntroduction Several reasons personality psychologists believe it is useful to explore personality across cultures o Discover whether concepts of personality that are prevalent in one culture are also applicable in
LSU - PSYCH - 3081
Chapter 17 terms Cultural variations: within group similarities and between group differences can be of any sort-physical, psychological, behavioral, or attitudinal. These phenomena are often referred to as cultural variations. Two ingredients are ne
USF - MAR - 3023
To: From: Subject: Reference: Date:Prof. Noel, MAR 3023 #1. Marketing Concept BW Jan 14, 2008 pg. 24 - see attached article Jan 22, 2008In "That Computer Is So You", a Business Week article by journalists Steve Hamm and Jay Greene, attention is g
USF - MAR - 3023
To: From: Subject: Reference: Date:Prof. Noel, MAR 3023 #4 Marketing Era BW Mar. 17, 2008 pg. 60 - see attached article March 20, 2008In "Upwardly Mobile Stationery", a Business Week article by Aaron Pressman, Staples is upgrading their image fro
USF - MAR - 3023
To: From: Subject: Reference: Date:Prof. Noel, MAR 3023 #2. Marketing Segmentation BW Feb. 4, 2008 pg. 68 - see attached article February 5, 2008In "Social Networks That Break a Sweat, by Paula Lehman in Business Week, Bode Miller is introduced a
USF - MAR - 3023
To: From: Subject: Reference: Date:Prof. Noel, MAR 3023 #5 Product Life Cycle BW March 17, 2008 - see attached article March 28, 2008Apple is undergoing some changes, as documented in Business Week's "The iPhone in the Gray Flannel Suit", an arti
USF - MAR - 3023
To: From: Subject: Reference: Date:Prof. Noel, MAR 3023 #3. Positioning BW Feb. 25, 2008 pg. 55 - see attached article February 22, 2008In Business Week article, "Japan: Google's Real-Life Lab" by Kenji Hall, the web-based giant Google is bringin
USC - ISE - 382
Database Systems: Concepts, design, and implementationISE 382 (3 Units)Description Concepts in modeling data for industry applications. Designing and implementing robust databases. Querying databases to extract business intelligence; Global Enterpr
USC - ISE - 382
ISE 382Midterm Review Questions (with answers)1) What does DBMS stand for? DBMS stands for Database Management System 2 What is a data model? Why are such models important? A data model is a logical representation of the structure of the database.
USC - ISE - 382
Homework 1 ISE 382 Database Systems 15 pointsDue Date Friday February 8thAnswer the following questions from your textbook. (1 point each) Page 24 1.7, 1.14, 1.18, 1.19, 1.24, 1.29, 1.30, 1.31 Page 95 3.10, 3.12, 3.15, 3.16, 3.17, 3.18, 3.20 Turn
USC - ISE - 310L
FACILITIES PLANNING ISE310L SESSION 1 INTRODUCTION, JANUARY 14, 2008OUTLINEIntroduce TAIntroduce instructor Registration for www.gezabottlik.comQuestionnaire (on line) Resume (submit on line) Take roll Grades Go over syllabus
USC - ISE - 310L
FACILITIES PLANNING ISE310L SESSION 3 PERFORMANCE, JANUARY 23, 2008OUTLINE Roll Questions? Chapter 2 - PerformanceGeza P. BottlikPage 1FACILITIES PLANNING ISE310L SESSION 3 PERFORMANCE, JANUARY 23, 2008Performance - Introduction Compet
USC - ISE - 310L
FACILITIES PLANNING ISE310L SESSION 2 Chapter 1, January 16, 2008OUTLINE Take roll Quiz example Chapter 1 Understanding the Supply ChainGeza P. BottlikPage 1FACILITIES PLANNING ISE310L SESSION 2 Chapter 1, January 16, 2008Example of a
USC - ISE - 310L
FACILITIES PLANNING ISE310L SESSION 7 Chapter 5, February 6, 2008OUTLINE Questions? Stories, experiences? Solver Chapter 5 Examples Decide on quizGeza P. BottlikPage 1FACILITIES PLANNING ISE310L SESSION 7 Chapter 5, February 6, 2008
USC - ISE - 310L
ISE310 Spring 20067/10/2008Probability Demand up Probability Demand down Probability staying the same % change0.5 0.5 0 20% Revenue CostProbability Price up 0.5 Probability Price down 0.5 Probability staying the same 0 % change 10% Spot Profi
USC - ISE - 310L
FACILITIES PLANNING ISE310L SESSION 6 CHAPTER 5, FEBRUARY 4, 2008OUTLINE Questions? Decide on Quiz Roll if no quiz Chapter 5.4Geza P. BottlikPage 1FACILITIES PLANNING ISE310L SESSION 6 CHAPTER 5, FEBRUARY 4, 2008Chapter 5 Network Des
USC - ISE - 310L
FACILITIES PLANNING ISE310L SESSION 5 CHAPTER 4, JANUARY 30, 2008OUTLINE Questions? Roll Any supply chain stories in the news? Chapter 4 Designing the distribution network Decide on quizGeza P. BottlikPage 1FACILITIES PLANNING ISE310L
Cornell - MATH - 1120
This syllabus is subject to CHANGE. Any changes will be announced in class and on the course web page as the semester progresses. The schedule is for MWF sections, but as it is meant to be only approximate, it gives a good enough idea of when various
Berkeley - POL SCI - 149
Defining Oneself Identity Politics in Modern Southeast AsiaMulticulturalism pervades Southeast Asia. Indeed, this culturally vibrant region is home to thousands of ethnic groups, languages, and religious practices. Instead of embracing its countrie