aspose file tools*
The moose likes Beginning Java and the fly likes Heelllpppp! I'm sooo lost Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Heelllpppp! I Watch "Heelllpppp! I New topic
Author

Heelllpppp! I'm sooo lost

Stacey Johnson
Ranch Hand

Joined: Jan 11, 2004
Posts: 55
Hi everyone,
I'm working on my rational problem still of having my program output:
1/1 + 1/2 + 1/3 + ...+ 1/n
1/1 + 1/2 + 1/2^2 +...+ 1/2^n
Below is my code, I'm getting 7 errors and I don't get why. Can someone please explain?

Here are a couple of the errors to start:

cannot resolve symbol
symbol : constructor Rtnl (int,int)
location: class Rtnl
Rtnl sum = new Rtnl(0,1);
^
cannot resolve symbol
symbol : constructor Rtnl (int,double)
location: class Rtnl
Rtnl x1 = new Rtnl(1,x);
^


My brain hurts
Stacey
Tim West
Ranch Hand

Joined: Mar 15, 2004
Posts: 539
The first error there mean "I can't find a constructor for class Rtnl that takes two int parameters".
Looking through your class, I can't find one either...so you probably want to add one. It will have this form:

Unfortunately, you can't fill in the body yet - the Rtnl class is missing something else.
So, what is it missing?
Well, I'm assuming that when you say "Rtnl foo = new Rtnl(1, 2)", you want a Rtnl class that represents the fraction 1/2, right? So, you'll need to add 'numerator' and 'denominator' fields (or whatever names you want to give the fields) to the class.
Then, when you write body of the contructor above, you can assign the parameters to the fields (that is, assign instance field 'numerator' the value 'aNumerator').
I'm being intentionally vague here, but if you can't work out where to go from here, post back. I imagine others might provide corrected code, but there's lots to learn from doing it yourself
On a side note, indenting your code makes it much easier to read
Cheers,
--Tim
Stacey Johnson
Ranch Hand

Joined: Jan 11, 2004
Posts: 55
I'm soo confused I really don't know what to do. First of all I'm not even sure where to place the constructor. I"m soo lost.
Stacey
Tim West
Ranch Hand

Joined: Mar 15, 2004
Posts: 539
I'm guessing that this is an assignment. If I'm right, then it's likely that at some point you'll be having an exam on Java too.
If that's the case, it would be well worth your while to read through some basics on classes and objects and other Java fundamentals - you'll have to learn them for the exam anyway.
One place to start on this is Bruce Eckel's "Thinking In Java", an excellent Java textbook that is available online. This book has good material on all basic Java subjects including constructors.
I think this is the best way forward given your circumstances. Of course, people here will be happy to answer any questions that the book or your work raise.
If my detective work at the top of this post is wrong, though, feel free to ignore everything I said

Cheers,

--Tim
Stacey Johnson
Ranch Hand

Joined: Jan 11, 2004
Posts: 55
Hi there,
Yes Tim you are right this is an exercise, I have to admit I've been away for a bit and trying to get back into it. I find it very difficult. I've fixed up my code a bit but now I'm getting different errors. I didn't add the constructor as you will see but I'm only getting 3 errors now and I don't know why:

My errors are as follows:

Exercise 9.1.java:53: '{' expected
public class Exercise 9.1 {
^
Exercise 9.1.java:87: '}' expected
}
^
class Exercise is public, should be declared in a file named Exercise.java
public class Exercise 9.1 {
^

Just a little background on me, I'm taking this course via correspondence and working full time. I know better now than to try and do intro programming (that I've never done before) on my own. I'm feeling quite overwhelmed. But I have to say I've had lots of help from everyone on this site and lots of explanation and good leads which is what I need. I'm trying to get past this one program so I can move on and but I feel soo stuck.
Stacey
C. Nimo
Ranch Hand

Joined: Mar 23, 2004
Posts: 82
Hi.
Your three problems are actually one.
See, when you write a public class in Java, you are supposed to put it in
a file that has the same name as that public class.
So, if you want to write a class named 'Nimo' (which is a very nice name) - you should put it in a file named Nimo.java.
You do not give the name of the file that you put your code in, but you named your class 'Excercise 9.1' - which you can't really do. What you
get is that you are trying to declare a class named Excercise, and then
the compiler expects something - perhaps a '{' character, but it gets
the '9.1' string instead, which it can not parse to anything that makes sense at these settings.
You probably want to name your class something like Excercise9_1 or simply Excercise or whatever. Just make sure that you put it in a file that has the correct name.
I saw that someone told you about Bruce Eckel's 'Thinking in Java' - doesn't matter what correspondence course you're taking - this book can make your study a lot easier. You can download it from the web (I think from www.bruceeckel.com, but if not - a little google-search will help)
Nimo.
Stacey Johnson
Ranch Hand

Joined: Jan 11, 2004
Posts: 55
Thanks for the advise, I forgot about the no "." thing in the file name. Stupid error. So I now have that fixed but I am still getting two errors. My code is the same (accept it is now its public class Exercise 9_2) I don't understand the errors I'm getting because I have what they are asking for. I'll post the code below again and the errors, can someone help me, I'm just plain puzzled now:

The errors are:
java:53: '{' expected
public class Exercise 9_1{
^
java:88: '}' expected
^
I've put the tow line numbers in bold so you can easily find what line the errrors are refering too.
Thanks
Stacey
Ben Buchli
Ranch Hand

Joined: Mar 26, 2004
Posts: 83
Hey Stacey,
still the same problem:
You cant have the class called Excercise 9_1
rewrite it as Excercise9_1 and it should work.
Francis Siu
Ranch Hand

Joined: Jan 04, 2003
Posts: 867
hi Stacey Johnson
Do you think that the object can be assigned a value?
sum = sum.add(x1);
And do you have the class of Rtnl,the related method and the constructor as well?
Rtnl x1 = new Rtnl(1,x);
HTH


Francis Siu
SCJP, MCDBA
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Heelllpppp! I'm sooo lost