 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
MuscularMind@comic.com Guest
|
Posted: Wed Nov 02, 2005 12:32 am Post subject: New to java -- help! |
|
|
Hi there,
I've just started an introductory to Java course, but I'm a tad behind
because I started the course a few weeks into the curriculum. This is
a bit embarrassing for me to admit, but I have no idea what one of my
assignments is asking for. Could someone help me.
Any help would be incredibly groovy.
Here's what the assignment is asking for:
1. Write a class called Train with the fields, constants, constructors
and methods outlined below.
2. Add Javadoc comments for the public class, fields, and methods.
Hand in a printout of the source code for the class. No need to hand in
the Javadoc documentation (the interface view), but PLEASE CHECK AND
MAKE SURE THAT EACH OF YOUR JAVADOC COMMENTS OCCUR AS EXPECTED IN THE
INTERFACE VIEW.
Please note: we will be using this class in Assignment 5.
fields
a private String field called name to hold the name of the train
private double fields as follow:
speed
xDirection
yDirection
xStartLocation
yStartLocation
xCurrentLocation
yCurrentLocation
constants
a public static constant named MAX_SPEED, with its value set to 55.0
public constructors
first constructor
parameters: a String called name, and three doubles called
xStartLocation, yStartLocation, and speed.
This constructor should set the values of the instance variables for
name, xStartLocation, yStartLocation
and speed to the values of the parameters. If the speed parameter is
less than 0, set the speed to 0, and if it is
greater than MAX_SPEED, set the speed to MAX_SPEED. xCurrentLocation
and yCurrentLocation should be set to the same values as xStartLocation
and yStartLocation
Second constructor:
Parameters: a String called name, and two doubles called xStartLocation
and yStartLocation.
This constructor should call the other constructor with a default value
of 0 for the speed.
public methods
Copy and paste the first three methods into your class. They contain
calculations for which you are not responsible.
Review each of these methods, as you will need to understand what they
do so that you can Javadoc comment them. They may also contain code
which will be useful for implementing other methods.
public void setDirection(double x, double y)
{
// the direction vector is stored internally in
// normalized form to simplify travel calculations
double d = Math.sqrt(x*x + y*y);
xDirection = x/d;
yDirection = y/d;
}
public void travel(int hours, int minutes)
{
double time = hours + minutes / 60.0;
xCurrentLocation += speed * time * xDirection;
yCurrentLocation += speed * time * yDirection;
}
public double computeDistanceTravelled()
{
// compute the distance between start location and current location
double x = xCurrentLocation - xStartLocation;
double y = yCurrentLocation - yStartLocation;
return Math.sqrt(x*x + y*y);
}
Write the rest of the methods described below the first three.
Method name: setSpeed
Parameters: a parameter named speed, data type double
Return type: void
Purpose: set the instance variable speed to the value of the parameter.
If the parameter is less than 0, set the train's speed to 0, and if
the parameter is greater than the constant MAX_SPEED, set the train's
speed to MAX_SPEED
Method name: stop
Parameters: none
Return type: void
Purpose: stop the train!
Method name: getSpeed
Parameters: none
Return type: double
Purpose: return the current speed of the train
Method name: computeDistanceApart
Parameters: a parameter of type Train called otherTrain
Return type: double
Purpose: calculate the distance between this train and otherTrain -
the calculation will look similar to the distance calculation in the
method computeDistanceTravelled() (if you aren't as excited about
math as I am, ask for some help with this method)
Method name: travel
Parameters: an int called minutes - the number of minutes the train
should travel
Return type: void
Purpose: computes the new location after travelling the number of
minutes in the parameter at the current speed for the train. This
method should convert the parameter to hours and minutes and call the
other travel method.
Method name: toString
Parameters: none
Return type: String
Purpose: Returns a formatted String of information about the train,
including its name, speed, start location and current location. When
printed, this String should print across several lines with easy to
read numbers. You can use the helper method fmt to display numbers
rounded to 2 decimal places.
private String fmt(double number)
{
DecimalFormat formatter = new DecimalFormat("###,##0.00");
return formatter.format(number);
}
Hand in a printout of the source code for the class. No need to hand in
the Javadoc documentation (the interface view), but PLEASE CHECK AND
MAKE SURE THAT EACH OF YOUR JAVADOC COMMENTS OCCUR AS EXPECTED IN THE
INTERFACE VIEW.
|
|
| Back to top |
|
 |
Michael Dunn Guest
|
Posted: Wed Nov 02, 2005 12:40 am Post subject: Re: New to java -- help! |
|
|
<standard reply>
the correct way to get help in forums/newsgroups like this is to post:
1) the specific problem you have
2) the code you have tried
3) the 'output you expect'
4) the 'output you get'
5) any relevant error messages
posting the assignment makes it look like just another
"do my homework for me" plea - even though that may not be your
intention.
|
|
| Back to top |
|
 |
Roedy Green Guest
|
Posted: Wed Nov 02, 2005 2:54 am Post subject: Re: New to java -- help! |
|
|
On 1 Nov 2005 16:32:10 -0800, [email]MuscularMind (AT) comic (DOT) com[/email] wrote, quoted or
indirectly quoted someone who said :
| Quote: | , but I have no idea what one of my
assignments is asking for. Could someone help me.
|
How about you at least read your textbook pages that you have covered
so for even once over. You have put zero effort into this so far. Why
should we? You are malingering as helpless. How can anyone even talk
to you if you have not even taken the effort to learn a single word of
Java?
Surely you can learn enough to at least write 10 lines of code in your
assignment or at least understand what the problem is. Surely you can
at least learn the definitions of the basics even if you can't figure
out how to use them.
You are like some valley girl who refuses to learn technical terms
like "steering wheel", "brake" and "ignition" as too difficult and
expects someone to teach her to drive.
See http://mindprod.com/jgloss/homework.html
That degree of learned helplessness usual only occurs in those who
parents give them names like "Bambi", "Brandi", "Missy", "Candi" or
"Snookums".
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
|
|
| Back to top |
|
 |
Bjorn Abelli Guest
|
Posted: Wed Nov 02, 2005 11:39 am Post subject: Re: New to java -- help! |
|
|
<MuscularMind (AT) comic (DOT) com> wrote...
[Follow-up set to comp.lang.java.help]
Take the assignment stepwise, and compile between each step, so you know
that you haven't introduced any errors in the latest step.
If you have errors, look carefully at the compiler's output to try to
understand why it occurs, before you attempt to correct them.
| Quote: | Here's what the assignment is asking for:
1. Write a class called Train with the fields, constants,
constructors and methods outlined below.
|
- Start with the chapter "Defining a class" and simply
define an empty class Train.
- Compile
- Go on to "Adding attributes to a class" (fields).
- Compile
| Quote: | fields
a private String field called name to hold the name of the train
private double fields as follow:
speed
xDirection
yDirection
xStartLocation
yStartLocation
xCurrentLocation
yCurrentLocation
|
- Probably the same chapter says something
about constants.
- Compile
| Quote: | constants
a public static constant named MAX_SPEED, with its value set to 55.0
|
- Next step is to read the special section in you book
on "Constructors".
- Compile
| Quote: | public constructors
first constructor
|
[snip]
- Do the next constructor.
- Compile
| Quote: | Second constructor:
[snip] |
- When you're done with the constructors, paste the "ready-made"
methods (including the method "fmt") in an appropriate place
in your code.
- Compile
| Quote: | public methods
[code snipped] |
- Look up in your book what it says about
setters and getters (mutators, accessors)
and start with those methods.
Take one method at the time.
- Compile
| Quote: | Method name: setSpeed
Method name: getSpeed
|
- Go on to the "simple" methods, still one method at the time.
- Compile
| Quote: | Method name: toString
Method name: stop
|
- Finally the more complex methods, still one method at the time.
- Compile
| Quote: | Method name: travel
Method name: computeDistanceApart
|
- and finally look up the chapter "Commenting the code".
- Compile, so you see that your insertion of comments haven''t interfered
with your code.
| Quote: | 2. Add Javadoc comments for the public class, fields, and methods.
|
- run javadoc on you file.
http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/javadoc.html
// Bjorn A
|
|
| Back to top |
|
 |
Mike Cocker Guest
|
Posted: Wed Nov 02, 2005 11:07 pm Post subject: Re: New to java -- help! |
|
|
Wow, tough crowd. I'd give my pay cheque to see what you guys were like when
you were learning programming. It's almost like you guys wait for posts like
this so you can gang up on the guy. I agree that he should tackle it to some
degree. Maybe he has. I think everyone needs to lighten up. Here's an idea,
if you didn't want to help him, don't reply to the message. With that said,
"musclemind", let me look at this a bit more and I'll post soon.
"Roedy Green" <my_email_is_posted_on_my_website (AT) munged (DOT) invalid> wrote in
message news:9v9gm1928ijdaa20kdq1k6f0dcmnub669o (AT) 4ax (DOT) com...
| Quote: | On 1 Nov 2005 16:32:10 -0800, [email]MuscularMind (AT) comic (DOT) com[/email] wrote, quoted or
indirectly quoted someone who said :
, but I have no idea what one of my
assignments is asking for. Could someone help me.
How about you at least read your textbook pages that you have covered
so for even once over. You have put zero effort into this so far. Why
should we? You are malingering as helpless. How can anyone even talk
to you if you have not even taken the effort to learn a single word of
Java?
Surely you can learn enough to at least write 10 lines of code in your
assignment or at least understand what the problem is. Surely you can
at least learn the definitions of the basics even if you can't figure
out how to use them.
You are like some valley girl who refuses to learn technical terms
like "steering wheel", "brake" and "ignition" as too difficult and
expects someone to teach her to drive.
See http://mindprod.com/jgloss/homework.html
That degree of learned helplessness usual only occurs in those who
parents give them names like "Bambi", "Brandi", "Missy", "Candi" or
"Snookums".
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
|
|
|
| Back to top |
|
 |
Roedy Green Guest
|
Posted: Thu Nov 03, 2005 5:05 am Post subject: Re: New to java -- help! |
|
|
On Wed, 2 Nov 2005 18:07:00 -0500, "Mike Cocker"
<mcocker (AT) swandust (DOT) com> wrote, quoted or indirectly quoted someone who
said :
| Quote: | Here's an idea,
if you didn't want to help him, don't reply to the message. With that said,
"musclemind", let me look at this a bit more and I'll post soon.
|
That is more cruel. He has no idea what he problem is then.
Have a look at this book:
http://mindprod.com/livinglove/methods/lifetraps.html
Called "Lifetraps". If a swift kick in the pants could shake him out
of that it would be the nicest thing anyone ever did to him in his
life.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
|
|
| Back to top |
|
 |
Roedy Green Guest
|
Posted: Thu Nov 03, 2005 5:33 am Post subject: Re: New to java -- help! |
|
|
On Thu, 03 Nov 2005 00:14:12 GMT, Mark Haase <mehaase (AT) gmail (DOT) com>
wrote, quoted or indirectly quoted someone who said :
| Quote: | BTW, Roedy and Andrew are two of the biggest contributors to this group
-- its like a 2nd job for them. I certainly don't blame them for
occasionally venting on a slacker.
|
My three main peeves are:
1. people who want others to do their homework for them without any
effort or involvement on their part. This bugs me for several
reasons:
a) it is a waste of money. Why pay a school large amounts of money to
teach you then do all in your power to subvert the process? When you
get out of school, and have credentials, they will be phony. What do
you do your first day on the job when it becomes clear you have no
clue how to program? You will never have better shot at learning Java
as now.
b) it is a waste of time. You might has well go on a trip around the
world or do something interesting if you don't want to learn Java.
Hanging around a school handing in fake papers has to be BORING. Later
in life you would give your eye teeth to have a chance to take a year
off to do nothing but study. The responsibilities of life will later
make that very difficult.
c) It is a form of malingering, feigning helplessness.
d) it is a type of criminal activity, asking other to help you forge
your documents of competency.
e) It pisses me off to pay taxes to subside this foolish activity.
Many students with less money than you could make much better use of
your subsidized seat.
2. People who keep asking the same questions over and over who don't
read the responses or the links to the material they have already been
given.
3. Self taught people who get huffy when you point out stylistic
problems and challenge your right to even point them at the common
idioms.
A long time ago I asked myself what I could do that would most
leverage my time to contribute to the planet as my health failed. The
answer is teach computer programming remotely, especially to people in
the third world. Peeves come with the territory.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
|
|
| Back to top |
|
 |
Mike Cocker Guest
|
Posted: Fri Nov 04, 2005 7:33 pm Post subject: Re: New to java -- help! |
|
|
| Quote: | BTW, Roedy and Andrew are two of the biggest contributors to this group
-- its like a 2nd job for them. I certainly don't blame them for
occasionally venting on a slacker.
|
That's too bad. I've never used this group until now. Reading replies to
posts like this makes me want to stay clear. I try not to judge people too
quickly. On the side I study psychology and I can't help but think that
these guys were picked on when they were younger. Venting through newsgroups
is where they get to fight back. It's all really sad.
"Musclemind", I hope the aids I sent you all work out.
|
|
| Back to top |
|
 |
Mike Cocker Guest
|
Posted: Fri Nov 04, 2005 8:11 pm Post subject: Re: New to java -- help! |
|
|
| Quote: |
1. people who want others to do their homework for them without any
effort or involvement on their part. This bugs me for several
reasons:
a) it is a waste of money. Why pay a school large amounts of money to
teach you then do all in your power to subvert the process? When you
get out of school, and have credentials, they will be phony. What do
you do your first day on the job when it becomes clear you have no
clue how to program? You will never have better shot at learning Java
as now.
|
Fair enough.
| Quote: | b) it is a waste of time. You might has well go on a trip around the
world or do something interesting if you don't want to learn Java.
Hanging around a school handing in fake papers has to be BORING. Later
in life you would give your eye teeth to have a chance to take a year
off to do nothing but study. The responsibilities of life will later
make that very difficult.
|
Ok.
| Quote: | c) It is a form of malingering, feigning helplessness.
|
You lost me here, but ok.
| Quote: | d) it is a type of criminal activity, asking other to help you forge
your documents of competency.
|
Criminal? Do you use Limewire or some other form of P2P? Of course you do.
Do you get help from this news group? When you get any form of help (be it a
book, workmate, the Internet), do you credit the source in your code? Sure
you do.
| Quote: | e) It pisses me off to pay taxes to subside this foolish activity.
Many students with less money than you could make much better use of
your subsidized seat.
|
Fair enough.
| Quote: | 2. People who keep asking the same questions over and over who don't
read the responses or the links to the material they have already been
given.
|
Ok.
| Quote: | 3. Self taught people who get huffy when you point out stylistic
problems and challenge your right to even point them at the common
idioms.
|
You must've had a question before? Math, English, Geography, etc.? Did you
ever show someone an assignment you were stuck on? Isn't that what
"musclemind" did? Thats how I took it anyway.
| Quote: | A long time ago I asked myself what I could do that would most
leverage my time to contribute to the planet as my health failed. The
answer is teach computer programming remotely, especially to people in
the third world. Peeves come with the territory.
|
I'm not sure if I should shake your hand or give you a hug. Seriously,
lighten up. It's a question. Don't make the person feel bad because they
asked one. You're a teacher? My wife is a teacher. It's a tough job I know.
Especially when you're teaching a subject that comes so naturally to you but
the person on the other end is clueless. I've read the posts. He didn't ask
you to do his homework. He just posted his assignment so that people could
point him in the right direction. If that is wrong, lesson learned.
|
|
| Back to top |
|
 |
Andrew Thompson Guest
|
Posted: Fri Nov 04, 2005 9:27 pm Post subject: Re: New to java -- help! |
|
|
Mike Cocker wrote:
| Quote: | "Musclemind", I hope the aids I sent you all work out.
|
(checkles) What a classic closing comment. I love it. ;-)
|
|
| Back to top |
|
 |
Tharpa Guest
|
Posted: Sun Nov 06, 2005 4:41 pm Post subject: Re: New to java -- help! |
|
|
"Mike Cocker" <mcocker (AT) swandust (DOT) com> wrote
| Quote: | Wow, tough crowd. I'd give my pay cheque to see what you guys were like
when you were learning programming. It's almost like you guys wait for
posts like this so you can gang up on the guy. I agree that he should
tackle it to some degree. Maybe he has. I think everyone needs to lighten
up. Here's an idea, if you didn't want to help him, don't reply to the
message. With that said, "musclemind", let me look at this a bit more and
I'll post soon.
I have seen the phenomenon you describe in many Usenet and IRC groups on |
many different subjects. Thanks for saying it. I think the worst comes out
in many people when they have anonymity.
Tharpa
| Quote: | "Roedy Green" <my_email_is_posted_on_my_website (AT) munged (DOT) invalid> wrote in
message news:9v9gm1928ijdaa20kdq1k6f0dcmnub669o (AT) 4ax (DOT) com...
On 1 Nov 2005 16:32:10 -0800, [email]MuscularMind (AT) comic (DOT) com[/email] wrote, quoted or
indirectly quoted someone who said :
, but I have no idea what one of my
assignments is asking for. Could someone help me.
How about you at least read your textbook pages that you have covered
so for even once over. You have put zero effort into this so far. Why
should we? You are malingering as helpless. How can anyone even talk
to you if you have not even taken the effort to learn a single word of
Java?
Surely you can learn enough to at least write 10 lines of code in your
assignment or at least understand what the problem is. Surely you can
at least learn the definitions of the basics even if you can't figure
out how to use them.
You are like some valley girl who refuses to learn technical terms
like "steering wheel", "brake" and "ignition" as too difficult and
expects someone to teach her to drive.
See http://mindprod.com/jgloss/homework.html
That degree of learned helplessness usual only occurs in those who
parents give them names like "Bambi", "Brandi", "Missy", "Candi" or
"Snookums".
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|