Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > A question about a few variables in a class

Reply
Thread Tools

A question about a few variables in a class

 
 
Chad
Guest
Posts: n/a
 
      08-14-2011
On Aug 13, 5:49*pm, Eric Sosman <esos...@ieee-dot-org.invalid> wrote:
> On 8/13/2011 1:30 PM, Chad wrote:
>
> > On Aug 6, 4:56 am, Eric Sosman<esos...@ieee-dot-org.invalid> *wrote:
> >>[...]
> >> * * * We don't actually know what Rectangle is because there areno
> >> import statements to tell us what package it's in. *It clearly
> >> cannot be java.awt.Rectangle, which has public width and height
> >> members but which has no getArea() and no suitable constructor.

>
> > Aye. I broke away from my own personal rule of posting code snippets.
> > I should know better since it really annoys me when people post code
> > snippets on comp.lang.c, and then, like magic, expect the group to be
> > able to magically interpet their line of thought.

>
> * * *Just out of curiosity, what *is* the `Rectangle' you used?
>


Below is all 5 million lines of code from the book....

public class GeometricObject1 {
private String color = "white";
private boolean filled;
private java.util.Date dateCreated;

public GeometricObject1() {
dateCreated = new java.util.Date();
}

public GeometricObject1(String Color, boolean filled) {
dateCreated = new.java.util.Date();
this.color = color;
this.filled = filled;
}

public String getColor() {
return color;
}

public void setColor(String color) {
this.color = color;
}

public boolean isFilled() {
return filled;
}

public void setFilled(boolean filled) {
this.filled = filled;
}

public java.util.Date getDateCreated() {
return dateCreated;
}

public String toString() {
return "created on " + dateCreated + "\ncolor" + color +
" and filled" + filled;
}
}

//Rectangle1 isn't a typo
public class Rectangle1 extends GeometricObject1 {
private double width;
private double height;

public Rectangle1() {
}

public Rectangle1(double width, double height, String color,
boolean filled) {
this.width = width;
this.height = height;
setColor(oolor);
setFilled(filled);
}

public double getWidth() {
return width;
}

public void setWidth(double width) {
this.width = width;
}

public double getHeight() {
return height;
}

public double setHeight(double height) {
this.height = height;
}

public double getArea() {
return width * height;
}

public double getPerimeter() {
return 2 * (width + height);
}
}
 
Reply With Quote
 
 
 
 
markspace
Guest
Posts: n/a
 
      08-14-2011
On 8/14/2011 1:23 PM, Chad wrote:
> public Rectangle1(double width, double height, String color,
> boolean filled) {


Method parameters.


> this.width = width;
> this.height = height;


Instance fields on the left of the assignment. (Note "data fields"
isn't used in any Java documentation I can recall.)

> setColor(oolor);
> setFilled(filled);


Method invocation, in the super class these methods set more instance
fields.
 
Reply With Quote
 
 
 
 
Eric Sosman
Guest
Posts: n/a
 
      08-14-2011
On 8/14/2011 4:23 PM, Chad wrote:
> On Aug 13, 5:49 pm, Eric Sosman<esos...@ieee-dot-org.invalid> wrote:
>> On 8/13/2011 1:30 PM, Chad wrote:
>>
>>> On Aug 6, 4:56 am, Eric Sosman<esos...@ieee-dot-org.invalid> wrote:
>>>> [...]
>>>> We don't actually know what Rectangle is because there are no
>>>> import statements to tell us what package it's in.[...]

>>
>> Just out of curiosity, what *is* the `Rectangle' you used?

>
> Below is all 5 million lines of code from the book....
>[...]
> //Rectangle1 isn't a typo
> public class Rectangle1 extends GeometricObject1 {


Not a typo, fine. Also still not `Rectangle' ...

Chad, if you ever expect to make any progress in programming
you will have to learn a few hard truths about exactness. First, of
course, is that the computer will do exactly what you tell it to --
and the whole huge activity called "debugging" amounts to exploring
the gap between what was said and what was meant. That being the
case, it is counterproductive in the extreme to widen the gap
gratuitously, as you have done in this thread by persisting in
sloppiness. You are just making things harder, unnecessarily harder,
and people may tire of working unnecessarily hard to help you.

By the way, the status of the thread's question is just as it
was nine days ago: "Insufficient information to support an answer."
Not much progress for nine days, is it?

--
Eric Sosman
d
 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      08-14-2011
On 8/14/2011 4:23 PM, Chad wrote:
> On Aug 13, 5:49 pm, Eric Sosman<esos...@ieee-dot-org.invalid> wrote:
>> On 8/13/2011 1:30 PM, Chad wrote:
>>
>>> On Aug 6, 4:56 am, Eric Sosman<esos...@ieee-dot-org.invalid> wrote:
>>>> [...]
>>>> We don't actually know what Rectangle is because there are no
>>>> import statements to tell us what package it's in.[...]

>>
>> Just out of curiosity, what *is* the `Rectangle' you used?

>
> Below is all 5 million lines of code from the book....
>[...]
> //Rectangle1 isn't a typo
> public class Rectangle1 extends GeometricObject1 {


Not a typo, fine. Also still not `Rectangle' ...

Chad, if you ever expect to make any progress in programming
you will have to learn a few hard truths about exactness. First, of
course, is that the computer will do exactly what you tell it to --
and the whole huge activity called "debugging" amounts to exploring
the gap between what was said and what was meant. That being the
case, it is counterproductive in the extreme to widen the gap
gratuitously, as you have done in this thread by persisting in
sloppiness. You are just making things harder, unnecessarily harder,
and people may tire of working unnecessarily hard to help you.

By the way, the status of the thread's question is just as it
was nine days ago: "Insufficient information to support an answer."
Not much progress for nine days, is it?

--
Eric Sosman
d
 
Reply With Quote
 
Chad
Guest
Posts: n/a
 
      08-15-2011
On Aug 14, 3:04*pm, Eric Sosman <esos...@ieee-dot-org.invalid> wrote:
> On 8/14/2011 4:23 PM, Chad wrote:
>
> > On Aug 13, 5:49 pm, Eric Sosman<esos...@ieee-dot-org.invalid> *wrote:
> >> On 8/13/2011 1:30 PM, Chad wrote:

>
> >>> On Aug 6, 4:56 am, Eric Sosman<esos...@ieee-dot-org.invalid> * *wrote:
> >>>> [...]
> >>>> * * * *We don't actually know what Rectangle is because there are no
> >>>> import statements to tell us what package it's in.[...]

>
> >> * * * Just out of curiosity, what *is* the `Rectangle' you used?

>
> > Below is all 5 million lines of code from the book....
> >[...]
> > //Rectangle1 isn't a typo
> > public class Rectangle1 extends GeometricObject1 {

>
> * * *Not a typo, fine. *Also still not `Rectangle' ...
>
> * * *Chad, if you ever expect to make any progress in programming
> you will have to learn a few hard truths about exactness. *First, of
> course, is that the computer will do exactly what you tell it to --
> and the whole huge activity called "debugging" amounts to exploring
> the gap between what was said and what was meant. *That being the
> case, it is counterproductive in the extreme to widen the gap
> gratuitously, as you have done in this thread by persisting in
> sloppiness. *You are just making things harder, unnecessarily harder,
> and people may tire of working unnecessarily hard to help you.
>


I'd like to believe I've more progress, than say, a few unnamed people
that keep posting questions in comp.lang.c.

> * * *By the way, the status of the thread's question is just as it
> was nine days ago: "Insufficient information to support an answer."
> Not much progress for nine days, is it?
>


Well, I believe that I've gone on record in the past as saying that
I'm kind of slow. I'm not ashamed of the fact that I got flat out
rejected by both UCLA and UC Berkeley on numerous occassions. I'm fine
with the fact that I have to read a section in the school book
multiple times and ask questions before anything actually sinks in. I
know there are people in this program that don't have to study and
still manage to get A's. I'm not one of them.

Chad
 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      08-15-2011
On 8/14/2011 8:09 PM, Chad wrote:
>[...]
> Well, I believe that I've gone on record in the past as saying that
> I'm kind of slow. I'm not ashamed of the fact that I got flat out
> rejected by both UCLA and UC Berkeley on numerous occassions. I'm fine
> with the fact that I have to read a section in the school book
> multiple times and ask questions before anything actually sinks in. I
> know there are people in this program that don't have to study and
> still manage to get A's. I'm not one of them.


All the more reason to cultivate discipline, to make almost
a fetish of exactness. It may or may not limit the scope of your
creativity, but it *will* limit the scope of your mistakes. I've
made a pretty successful career out of being a careful non-genius;
you can do so too. But "careful" is the word, "meticulous" is
the byword, "slapdash" is the word you must reject.

--
Eric Sosman
d
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      08-15-2011
markspace wrote:
> Chad wrote:
>> public Rectangle1(double width, double height, String color,
>> boolean filled) {

>
> Method parameters.


Constructor parameters, not method parameters.

>> this.width = width;
>> this.height = height;

>
> Instance fields on the left of the assignment. (Note "data fields"
> isn't used in any Java documentation I can recall.)


Also called instance attributes, although that term is more apt for the methods that cover them, or for public instance fields.

Another name is instance member fields.

>> setColor(oolor);
>> setFilled(filled);

>
> Method invocation, in the super class these methods set more instance
> fields.


Note that the use of non-final member methods in a constructor of the same class is dangerous.

--
Lew
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      08-15-2011
Chad wrote:
> Eric Sosman wrote:
>>>[...]
>>> //Rectangle1 isn't a typo
>>> public class Rectangle1 extends GeometricObject1 {

>>
>> * * *Not a typo, fine. *Also still not `Rectangle' ...
>>
>> * * *Chad, if you ever expect to make any progress in programming
>> you will have to learn a few hard truths about exactness. *First, of
>> course, is that the computer will do exactly what you tell it to --
>> and the whole huge activity called "debugging" amounts to exploring
>> the gap between what was said and what was meant. *That being the
>> case, it is counterproductive in the extreme to widen the gap
>> gratuitously, as you have done in this thread by persisting in
>> sloppiness. *You are just making things harder, unnecessarily harder,
>> and people may tire of working unnecessarily hard to help you.

>
> I'd like to believe I've more progress, than say, a few unnamed people
> that keep posting questions in comp.lang.c.


So the eff what? How does that influence the price of gefulte fish in Beijing?

>> * * *By the way, the status of the thread's question is just as it
>> was nine days ago: "Insufficient information to support an answer."
>> Not much progress for nine days, is it?

>
> Well, I believe that I've gone on record in the past as saying that
> I'm kind of slow. I'm not ashamed of the fact that I got flat out
> rejected by both UCLA and UC Berkeley on numerous occassions. I'm fine
> with the fact that I have to read a section in the school book
> multiple times and ask questions before anything actually sinks in. I
> know there are people in this program that don't have to study and
> still manage to get A's. I'm not one of them.


Look, no one is saying anyone has to be a genius or a straight-A student, but to get all defensive like that and whine about not being smart instead of taking the coaching is a boneheaded stupid reaction. If you cannot take advice to improve your skills, but instead make pathetic excuses that are utterly irrelevant and do yourself a disservice to boot, why do you even bother asking for help?

Go back and read Eric's advice again and follow it, and get your ego out ofthe way or get out of programming.

--
Lew
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Internet connects for a few seconds then disconnects for a few sec Cody Wireless Networking 2 06-28-2009 08:24 PM
Put variables into member variables or function variables? tjumail@gmail.com C++ 9 03-23-2008 04:03 PM
To delete few lines and add few lines at the end of a text file using c program Murali C++ 2 03-09-2006 04:45 PM
question about class variables and instance variables Eric D. Ruby 3 02-01-2006 07:57 PM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57