
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

1. /** See Prelim for the spec.*/
public static String fixZip(String s) {
if (s.indexOf("Cornell") == -1) {
return s;
int k= s.indexOf("14850");
if (k == -1) {
return s;
return s.substring(0,k) + "14853" +
s.substring(k+5);
2a.
s _ null __
m(String) setX( int )
c
5a. Parameter: a variable that is declared within the
parentheses of a method header.
5b. 1. Create (draw) a new manila folder (object) of the
class, in this case, C. 2. Execute the constructor call in the
new-expression, in this case, C(5, 3). 3. Yield as value of the
new-expression he name (on the tab) of the new object.
5c. 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. Name, netId, Student, getName, getNetId,
toString, equals (you do not have to remember
this one; it is in class Object).
3b. toString.
3c. "Johnny, JD123, A&S".
3d. /** An instance: info about a freshman */
public class Freshman extends Undergrad
private int APcredits; // no. of AP credits
/** Constructor: a freshman named n with
netId id, in college c, and with x AP credits */
public Freshman(String n, String id,
String c, int x) {
super (n, id, c);
APcredits= x;
/** = number of APCredits of this student */
public int getAPCredits() {
return APcredits;
/** = set the number of APCredits to ap */
public void setAPCredits( int ap) {
APcredits= ap;
/** = a representation of this student */
public String toString() {
return super .toString() + ", " +
APcredits + " AP credits";
4. Below is the output. We also show the final
state of variables b, c, d.
d (0, 5)
b (9, 5)
c (6, 7)
d (9, 5)
b (0, 0)
d (9, 5)
s _ null __
m(String) setX( int )
c
two __ null __
one c3
s _ null __
m(String) setX( int )
c
2b.
a
x
y
Point
b a
c a
d a
a
x
y
Point
a
x
y
Point