This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Still struggling with constructors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Still struggling with constructors " Watch "Still struggling with constructors " New topic
Author

Still struggling with constructors

Troy Johnson
Greenhorn

Joined: Sep 24, 2003
Posts: 20
Hello. I still seem to be struggling a bit getting this to work properly. I have made some modifications based upon previous suggestions and responses. I am tyring to modify the code by adding two additional constructors, one that takes the "annual interest rate" and "loan amount", and one that takes just the "loan amount". I need to use the keyword "this" to invoke new constructor. I am also to write a test program to test all constructors. Here is my original code and the modifications I have made. Please let me know if anyone has any suggestions or can help. Sorry, for the repetitive posts. I am new to Java. Thanks.

Here is my original code:

Here is the modification and solution I have so far

[ October 22, 2003: Message edited by: Troy Johnson ]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24168
    
  30

To call one constructor from another, you use "this()". In the parentheses, you put the arguments to pass to the other constructor. For example

Is that enough information?


[Jess in Action][AskingGoodQuestions]
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
I *think* I can see what you're trying to do now

(rest of code snipped)
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24168
    
  30


I *think* I can see what you're trying to do now

Well, indeed. We all could see that. I would hoping to give him enough information to work this out for himself. He won't learn anything at all from cutting and pasting your code into his assignment!
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
Ernest, my post was more of a correction to my post in his other thread.
As for him learning Vs not learning, that's for him to choose, not me.
Troy Johnson
Greenhorn

Joined: Sep 24, 2003
Posts: 20
Thanks everyone for all of your help. I greatly appreciate it. I think I finally got it figured out now. Thanks again.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24168
    
  30

Michael --
Sorry for the rebuke. I was annoyed with someone else and I took it out on you.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
Ernest, not a problem, and while I'm here, I would like to say thanks for a whole bunch of your code snippets that have turned many of my Java 'doubtful' areas into 'hey, light bulb's now on'.
Thanks again.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Still struggling with constructors
 
Similar Threads
Help with errors again
Help on Control Statement
Help with constructors
more help with java problem
last week of class last assignment. Any help is appreciated.