This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Building Blockchain Apps and have Michael Yuan on-line!
See this thread for details.
Win a copy of Building Blockchain Apps this week in the Cloud/Virtualization 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
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

method is undefined for the type

 
Ranch Hand
Posts: 274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I am writing a program that is to calculate the cost to install carpet in a room, get user input for price per square foot, length, and width of the room. Then output all the default values results, user input results, as well as a pre scheduled results.

I am stuck  line 29 - 31 in the first segment of code, I receive the error
 
" The method displayResults(Measure) is undefined for the type CarpetCalcDemo "

However, I do have a displayResults method 78 - 85 in the second segment of code,

is their a better way to output all of these results???





 
Marshal
Posts: 68156
258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are calling the display method on the wrong thing.
You also shouldn't call the method display; you should override the toString method, then you can simply say
System.out.println(myMeasure);
and get a sensible output.

Why have you got all those comments which don't tell anybody anything that isn't obvious from reading the code?
Why have you got that repeated code in the setXXX methods? That should be refactored into a method of its own.
 
Bartender
Posts: 3785
154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What will be the outcome of 'calcCarpetCost' if 'calcArea' has not been invoked? Where is totalCost calculated?
 
Rancher
Posts: 3656
34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another item: use variable names that describe what the variable contains:

When measure1 is used in the code, what do you know about its contents?
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi kennith

your error is because you want call the method "displayResults" locally on the class "CarpetCalcDemo", but doesn't exist.

this method is declared on the "Measure" class

I hope I've helped.
 
kennith stomps
Ranch Hand
Posts: 274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cleaned it up a bit, When I run the program, totalCost stays 0 no matter what values are entered, can you spot any reason why this is?




 
Norm Radder
Rancher
Posts: 3656
34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

reason why this is?


What are the values of the variables used to compute totalCost?  Add a print statement after line 73 that prints their values so you can see.
 
The longest recorded flight time of a chicken is 13 seconds. But that was done without this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!