This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Not picking up Method..  RSS feed

 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok here is my driver class and main class...




Now, for some reason, the main class is not recognizing "plus(LongInt,LongInt) as a method, says it can't find symbol...

why is that?...

can someone plz help...

thanks,
Justin
 
Peter MacMillan
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
all that code and the answer is:


Well there are other problems, but that's the one central to your question.

plus is a method of the LongInt class. f is an instance of the LongInt class, so in order to call the plus method you write f.plus(...); which tells java to call the plus method of the object referred to by f.

Hope that helps a bit.
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so after i call f.plus(a,b);

the LongInt Object f with hold the value of a + b;?

thanks,
Justin
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok, i did...



but when it was running i got this error

////////////////////////////////////////////////
* C:\Documents and Settings\Fox\Desktop\Actual Program>java LongIntImple
12343 245

23436 7Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
///////////////////////////////////////////////

I don't understand what's happening,

thanks,
Justin
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at this method.



Will the condition ever change?
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ohhhh.....

i need to make it like this then huh

public void addtoHead(LongInt A, int count)
{}

thanks,
Justin
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That won't change count.
 
Campbell Ritchie
Marshal
Posts: 55680
161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. . . and in your plus method where you set carry = 1, you have missed out the "else" after it.
 
Campbell Ritchie
Marshal
Posts: 55680
161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a much easier way to work out your count. It would have to go into the Node class.
[edit]I was thinking of a static count variable in the Node class, but if you have two series of Nodes, that won't work.[/edit]

And I have already told you there are easier ways to get from char to int and vice versa than all these switch blocks.
[ June 28, 2006: Message edited by: Campbell Ritchie ]
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i dont need to change count.

im just using an int initialized to 0, and comparing it to count to see

how many zeros i need to add.

the int is incre = 0;

and for the else, i fixed that...

ok for some reason in the line of code...

r = toChar(answer);

its just printing

LongInt contains a non - Integer character over and over again....

like i hit an infinite loop, but i have the while loop restrictions....

wait...

maybe i should put || instead of &&...

thanks,
Justin
 
fred rosenberger
lowercase baba
Bartender
Posts: 12542
48
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

just glanced at your code, but when will you ever break out of this loop?
[ June 28, 2006: Message edited by: fred rosenberger ]
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


But you still have a fundamental problem here.

Notice that incre doesn't change and count doesn't change.

So there is no way that the loop ends.
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok i got it to add now, but now im on multiplying...

ok so my multiply method uses another method called timeInt(LongInt A,int B).

now the TimeInt method just multiplies the LongInt A by the int B.

and then returns another LongInt containing the result of the multiplication.

my multiply(LongInt A, LongInt B) method // LongInt A = new LongInt("500");
// LongInt B = new LongInt ("525");
// say its multiply(A,B);

so it just calls timesInt(A,toInt(curr.value));
// where curr points to the first node in B.
// so it would really just do
// 500 * 5
// and return the LongInt("2500").


then calls shiftLeft(LongInt A)
// then the returned LongInt would be come "25000".
// where shiftLeft just adds a node containing '0' to the tail of the list.

and then adds the shifted left list("25000") to timesInt(A,toInt(curr.value));
// where curr.value is now incremented and is pointing at the second
// node(which is 2);
Exampe: // plus(25000,timesInt(5000,2));





but my question is...

how do i get it to keep plus()'ing when I need two LongInt parameters, but
can only grab one at a time?

thx,
Justin
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!