Assignment A2 - Introduction to Computing Using Java | CS 1110, Study notes of Computer Science

Material Type: Notes; Class: Introduction to Computing Using Java; Subject: Computer Science; University: Cornell University; Term: Fall 2008;

Typology: Study notes

Pre 2010

Uploaded on 08/30/2009

koofers-user-87k
koofers-user-87k 🇺🇸

10 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Assignment A2 CS1110 Fall 2008
Due 23 September, IN CLASS
This assignment asks you to draw a few objects (manila
folders). The purpose is to ensure that you know how to
draw them. It shouldn't take more than 15 minutes to do
this assignment. Please hand it in at the BEGINNING of
lecture on Thursday, 14 February.
Remember: Any class that does not extend another class
automatically extends class Object, which is in pack-
age java.lang. So, writing public class What-
ever {...} has exactly the same effect as public
class Whatever extends Object {...}.
Class Object has two important functions:
equals(Object) and toString().
Draw an object of each of the following 4 classes In-
clude the partition for class Object. When finished,
you should have drawn four objects. Do not draw any
file drawers or static components. When done, read the
notes in the next column, carefully.
public class Ex {
public static final int ZERO= 0;
private int h;
public Ex(int ph) {
h= ph;
}
public int getH() {
return h;
}
public String toString() { ... }
public static int what(int x) {
... }
}
public class Sub extends Ex {
private int k;
public Sub(int pk) {
k= pk;
}
public String toString() { ... }
}
public class SubSub1 extends Sub {
public SubSub1() {
super(5);
}
public int hPlus1() {
return getH()+1;
}
public String toString() { ... }
}
public class SubSub2 extends Sub {
private int p;
}
Notes One semester, when we gave this homework,
some students did so miserably that we gave them an-
other chance to learn. So that you don't have this prob-
lem —we won't be giving second chances—, here are
notes that we gave out to the students who did things
wrong. After completing this assignment, read through
these notes and see whether you made the same mis-
takes. If so, correct them.
Note 1. You did not follow directions at all. We do not
see, separately, an instance of Ex, an instance of Sub, an
instance of SubSub1, etc. You may have put them all
together in one picture, but that is not what we asked for
and it shows no understanding of drawing objects. 20
points.
Note 2. In a folder like one for SubSub1, you placed all
the components together in one place. You did not put
those for Object on top, then those for Ex, then those for
Sub next, and finally those for SubSub1 at the bottom.
50 points.
Note 3. You did not draw field p of Subsub2 as a vari-
able —either with a line after it or a box after it. 5
points.
Note 4. You left off the part for superclass Ex and/or
Sub in your diagrams. You did not follow directions. –
20 points.
Note 5. You did not draw variables correctly. They
should be drawn with the name of the variable followed
either by an underline with the value on it or by a box
with the value in it. –5 points.
Note 6. Method what and field Zero in class Ex are
static. Therefore, they should not be drawn in each
folder of class Ex —they belong separately in the file
drawer for Ex, wich should not be drawn. –5 points.
Note 7. In drawing a folder for SubSub2, you put in it a
place for SubSub1 components. That is not correct.
SubSub2 extends Sub, not SubSub1. –15 points.

Partial preview of the text

Download Assignment A2 - Introduction to Computing Using Java | CS 1110 and more Study notes Computer Science in PDF only on Docsity!

Assignment A2 CS1110 Fall 2008

Due 23 September, IN CLASS

This assignment asks you to draw a few objects (manila folders). The purpose is to ensure that you know how to draw them. It shouldn't take more than 15 minutes to do this assignment. Please hand it in at the BEGINNING of lecture on Thursday, 14 February. Remember: Any class that does not extend another class automatically extends class Object, which is in pack- age java.lang. So, writing public class What- ever {...} has exactly the same effect as public class Whatever extends Object {...}. Class Object has two important functions: equals(Object) and toString(). Draw an object of each of the following 4 classes In- clude the partition for class Object. When finished, you should have drawn four objects. Do not draw any file drawers or static components. When done, read the notes in the next column, carefully. public class Ex { public static final int ZERO= 0; private int h; public Ex( int ph) { h= ph; } public int getH() { return h; } public String toString() { ... } public static int what( int x) { ... } } public class Sub extends Ex { private int k; public Sub( int pk) { k= pk; } public String toString() { ... } } public class SubSub1 extends Sub { public SubSub1() { super (5); } public int hPlus1() { return getH()+1; } public String toString() { ... } } public class SubSub2 extends Sub { private int p; } Notes One semester, when we gave this homework, some students did so miserably that we gave them an- other chance to learn. So that you don't have this prob- lem —we won't be giving second chances—, here are notes that we gave out to the students who did things wrong. After completing this assignment, read through these notes and see whether you made the same mis- takes. If so, correct them. Note 1. You did not follow directions at all. We do not see, separately, an instance of Ex, an instance of Sub, an instance of SubSub1, etc. You may have put them all together in one picture, but that is not what we asked for and it shows no understanding of drawing objects. – 20 points. Note 2. In a folder like one for SubSub1, you placed all the components together in one place. You did not put those for Object on top, then those for Ex, then those for Sub next, and finally those for SubSub1 at the bottom. – 50 points. Note 3. You did not draw field p of Subsub2 as a vari- able —either with a line after it or a box after it. – 5 points. Note 4. You left off the part for superclass Ex and/or Sub in your diagrams. You did not follow directions. – 20 points. Note 5. You did not draw variables correctly. They should be drawn with the name of the variable followed either by an underline with the value on it or by a box with the value in it. – 5 points. Note 6. Method what and field Zero in class Ex are static. Therefore, they should not be drawn in each folder of class Ex —they belong separately in the file drawer for Ex, wich should not be drawn. – 5 points. Note 7. In drawing a folder for SubSub2, you put in it a place for SubSub1 components. That is not correct. SubSub2 extends Sub, not SubSub1. – 15 points.