• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Daniel Stallard
Ranch Hand
Posts: 39
Java ME Oracle
  • 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



 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 36659
475
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: 39
Java ME Oracle
  • 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: 39
Java ME Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I figured it out.Thanks for the help guys.
 
Campbell Ritchie
Sheriff
Posts: 54076
130
  • 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: 39
Java ME Oracle
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!