• 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Need an advice how to call a method from constructor  RSS feed

 
Ranch Hand
Posts: 90
Java ME MySQL Database PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone to start i want to say imm new to java and i am also new to this site. That being said ill probably have errors in my post and ask alot of noob questions.

Okay i need to call a method in my constructor. it is a setter i need it  to figure up the cost of my rental fee. i have to follow a uml diagram so i cant change anything as var as making void a double or anything like that. any help or advice would be awsome.  all the code s the same as this post except variable names.



this is my setter



 
author & internet detective
Sheriff
Posts: 38569
659
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Daniel,
Welcome to CodeRanch!

This line is incorrect. If you were calling a static method, it would look like that:


Instead you need to write either of these:


That calls an instance method in the same class.
 
Daniel Stallard
Ranch Hand
Posts: 90
Java ME MySQL Database PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes and thank you i figured out last night but thanks for the reply. i do have another question though im having problems with it printing a line





this string has to print based on the discount.
 
Daniel Stallard
Ranch Hand
Posts: 90
Java ME MySQL Database PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I figured it out.Thanks for the help guys.
 
Marshal
Posts: 60136
188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done
Please show us the solution, or tell us about it.
 
Daniel Stallard
Ranch Hand
Posts: 90
Java ME MySQL Database PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well what happened is i was overlooking the fact that i did not set the discount code in my setRentalCost() method. so once i did that the switch new what the variable discount meant  in the toString() method. So java wa basically saying here is a variable i don't know what it means so i do not know what case to print.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!