• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Back to rational problem

 
Stacey Johnson
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all!
Well I had to take a break for a bit but now I'm back and working on my rationals problem. I'm suppose to have an output like the following:
1/1 + 1/2 + 1/3 + ...+ 1/n
1/1 + 1/2 + 1/2^2 +...+ 1/2^n
I think I've got my constructor mostly cleaned up but I'm still getting a few errors that I"m not sure what to do. Below is my code then the errors:

Some of my errors are:

cannot resolve symbol
symbol : constructor Rtnl (int,int)
location: class Rtnl
Rtnl sum = new Rtnl(0,1);
^
java:61: cannot resolve symbol
symbol : constructor Rtnl (int,int)
location: class Rtnl
Rtnl x1 = new Rtnl(1,x);
^
java:62: cannot resolve symbol
symbol : method add (Rtnl)
location: class Rtnl
sum = sum.add(x1);
^

I'm sure you can see a theme of my errors, but I just don't know what to do. Can anyone help?
Stacey
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your constructor needs round braces '( )'.

similiar it is with the methods:

but since you don't call them, you may delete them.
Reread about the syntax of methods.
about initialising variables.
I would go a few steps back in the Excercises, since you missed a lot of points. (When solving your errors, new ones which where hidden occur - and I can't even see what you're trying to do...
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have multiple problems here, and you confused the compiler. The good news is, all of your problem are of the same nature, such as in this segment of your code:

This is not how a method is defined in Java. Perhaps what you meant was the code below?
 
Stacey Johnson
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Okay I've fixed the stupid error regarding the () but what does the following error mean?
java:62: cannot resolve symbol
symbol : method add (Rtnl)
location: class Rtnl
sum = sum.add(x1);
^

Stacey
 
C. Nimo
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sum is an Rtn1 object.
you are trying to invoke a method called add() on this object.
however, your Rtn1 class has no method definition for add()
 
Stacey Johnson
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm completely lost. I don't know what to do anymore. Do I need constructors in this code to get my end result or have I been led down the wrong path. I am sooo close to quitting my course because I just don't know what to do with this program anymore. I don't even know where to look to find answers to my questions and errors. Is there anyone out there to shed some light on this for me? I feel like I'm beating my head against the wall.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic