• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Heelllpppp! I'm sooo lost

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 539
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 539
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Stacey,
still the same problem:
You cant have the class called Excercise 9_1
rewrite it as Excercise9_1 and it should work.
 
Ranch Hand
Posts: 867
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
All that thinking. Doesn't it hurt? What do you think about this tiny ad?
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic