prelim1fall2003ans - toString. 3c. y= (Lion) x; 3d....

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
6 1. public String fixCase(String s) { 2a. if (s.length() == 0) return s; if (s.charAt(0) == ‘a’) return s.toLowerCase(); if (s.charAt(0) == ‘A’) return s.toUpperCase(); if (s.charAt(0) == ‘ ’) { 2b. int k= s.indexOf(‘\n’); if (k == –1) return s; return s.substring(0, k) + s.substring(k); } return s; } d __5__ m(String) setD( int ) c1 MP d __5__ m(String) setD( int ) c2 MP S one __ null __ two __c3__ d __5__ m(String) setD( int ) c3 MP 5a. Parameter: a variable that is declared within the parentheses of a method header. 5b. Argument: an expression that appears within the parentheses of a method call. 5c. < variable >= < expression >. Evaluate the < expression > and store its value in the < variable >. 5d. Local variable: a variable declared in a method body. Its scope is the sequence of statements that follow the declaration, until the end of the block. 5e. return < expression > 3a. getAge, getName, setName, setAge, toString. 3b.
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: toString. 3c. y= (Lion) x; 3d. x.toString() is legal. It calls the overriding method in folder x --the method in the Lion partition of the folder. 3e. x.noise() is not legal, since noise is not declared in Animal. 3f. Narashimhan, 1008, roar! CS100J Prelim I answers Netid _________ Name __________________ 4. // An instance is a horse, with a number of horns public class Horse extends Animal { // Number of horns this horse has private int horns= 0; // = number of horns on this horse public int getHorns() { return horns; } // Set the number of horns to n public void setHorns( int n) { horns= n; } // = noise this horse makes public String noise() { return whinny; } // = description of this animal public String toString() { return super .toString() + , + n + horns; } }...
View Full Document

Ask a homework question - tutors are online