Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Stack Push() Method Not Accepting Argument Paremeters

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I am trying to make a couple classes of a calculator for my college project. I have to make a stack class, entry class and have two enums TYPE and SYMBOL inherited to entry class. I have only included relevant code but essentially, my push method doesnt like the argument push(Entry i) and i cant work out why. i have a junit5 test for it that i'll also include, and the error i get is "The method push(Entry) in the type CalcStack is not applicable for the arguments (int)". If anyone can help i'd be over the moon! I've also included the UML if that helps

Screenshot-2020-10-17-at-18.21.21.png
UML of my classes
UML of my classes
 
Marshal
Posts: 70684
288
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Afraid you have fallen into a common pitfall. Your pop() method doesn't delete the top element; that is a potential memory leak. Since you are using a List, you can probably write return myList.remove(...); and get rid of the memory leak.
I would augment the stack class with an isEmpty() method.
 
Daniel Chivelly
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Carey Brown wrote:Line 31 is a closing paren, not a brace.



I might have accidentally added that whilst copying in the code, I was more questioning why my push(Entry i) method doesnt accept integers when testing the method.
 
Daniel Chivelly
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Afraid you have fallen into a common pitfall. Your pop() method doesn't delete the top element; that is a potential memory leak. Since you are using a List, you can probably write return myList.remove(...); and get rid of the memory leak.
I would augment the stack class with an isEmpty() method.



Could you explain how so? I have written the following test which passed the pop method before I made changes to the push method.

 
Bartender
Posts: 4109
156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your push method requires an Entry as argument, but you have a double.

And, when you pop, you do not adjust the size variable.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Piet Souris wrote:Your push method requires an Entry as argument, but you have a double.

And, when you pop, you do not adjust the size variable.



Yes, the method as you defined receives an object of type Entry, and then you are pushing a float instead of an object would this works?:
 
Campbell Ritchie
Marshal
Posts: 70684
288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Chivelly wrote:. . . Could you explain how so? . . .

Your pop() method allows the previous top element to remain in the List.
 
Campbell Ritchie
Marshal
Posts: 70684
288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wss I mistaken? Were you using remove() all along? If so, sorry.
 
Daniel Chivelly
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Eduardo Rod wrote:

Piet Souris wrote:Your push method requires an Entry as argument, but you have a double.

And, when you pop, you do not adjust the size variable.



Yes, the method as you defined receives an object of type Entry, and then you are pushing a float instead of an object would this works?:




Thank you so much how did I not get that? stress and fixations haha thank you!
 
Anderson gave himself the promotion. So I gave myself this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic