|
|
#1 | ||
|
Daemon Poster
Join Date: Dec 2008
Posts: 1,465
|
OK I am learning Java and am stuck...
![]() Here is the problem... create a class named CheckingAccount with data fields for an account number and a balance. Include a constructor that takes arguments for each field. The constructor sets the balance to 0 if it is below the required 200.00 mininum for an account. Also include a method that displays account details, including an explanation if the balance was reduced to 0. Write an application named TestCheckingAccount in which you instantiate two CheckingAccount objects, prompt the user for values for the account number and balance, and display the values of both accounts. OK first here is what I have for the constructors Please tell me if they are correct it compiles but I am not sure if they are correct for the question. Quote:
I have this but I can't seem to get it right no matter what I add or change: Quote:
__________________
Raidmax Smilodon Extreme Black Case -|-AMD Phenom II x4 955 BE @ 3829.50 Mhz (18.5 x 207, vcore 1.424, NB 2600 mhz, HT link 2200 mhz) -|- Xigmatek Dark Knight S1283V -|- Gigabyte MA790XT-UD4P Mobo -|- G. Skill 6Gb (3 x 2Gb) DDR3 1333 RAM 7-7-7-18-2t -|- WD Caviar 7200 RPM 1 TB HDD -|- OCZ GameXtreme 700W -|- Radeon 4870 1Gb @ 780/1050 -|- Asus VW202NR 20" wide-screen -|- Windows 7 Professional 64 Bit -|- Saitek Cyborg Keyboard -|- Razer Lachesis Mouse |
||
|
|
|
|
|
#2 |
|
Daemon Poster
Join Date: Dec 2008
Posts: 1,465
|
OK I figured it out on my own... I was trying to do too much with it and got lost along the way.....
![]() I think I misunderstood exactly what the question was asking...
__________________
Raidmax Smilodon Extreme Black Case -|-AMD Phenom II x4 955 BE @ 3829.50 Mhz (18.5 x 207, vcore 1.424, NB 2600 mhz, HT link 2200 mhz) -|- Xigmatek Dark Knight S1283V -|- Gigabyte MA790XT-UD4P Mobo -|- G. Skill 6Gb (3 x 2Gb) DDR3 1333 RAM 7-7-7-18-2t -|- WD Caviar 7200 RPM 1 TB HDD -|- OCZ GameXtreme 700W -|- Radeon 4870 1Gb @ 780/1050 -|- Asus VW202NR 20" wide-screen -|- Windows 7 Professional 64 Bit -|- Saitek Cyborg Keyboard -|- Razer Lachesis Mouse |
|
|
|
|
|
#3 |
|
Site Team
Join Date: Jul 2009
Posts: 2,627
|
Just for clarity (and for future reference in case anyone else sees this thread)
The things you're calling "constructors" in the class above aren't constructors at all, they're methods. A constructor would look like this: Code:
public CheckingAccount(int accountNumber, double balance) {
this.accountNumber = accountNumber;
this.balance = balance;
}
Hope that makes sense, feel free to ask if you've got any questions
__________________
Save the whales, feed the hungry, free the mallocs. |
|
|
|
|
|
#4 |
|
Daemon Poster
Join Date: Dec 2008
Posts: 1,465
|
Yes berry that makes perfect sense. That is where I think I went wrong because there was a constructor needed which would set the balance to $0 but it was only to set it "if" the balance entered was below $200. I was really not exactly sure how to use a constructor and got them mixed up with the get() and set() methods. all that I really had to do was use a constructor to give balance a default value of 0, and then use a setbalance() to set the balance to the amount given by a user if the balance was above 200.00
Thank you for the explanation of a constructor though because it makes more sense the way you put it.
__________________
Raidmax Smilodon Extreme Black Case -|-AMD Phenom II x4 955 BE @ 3829.50 Mhz (18.5 x 207, vcore 1.424, NB 2600 mhz, HT link 2200 mhz) -|- Xigmatek Dark Knight S1283V -|- Gigabyte MA790XT-UD4P Mobo -|- G. Skill 6Gb (3 x 2Gb) DDR3 1333 RAM 7-7-7-18-2t -|- WD Caviar 7200 RPM 1 TB HDD -|- OCZ GameXtreme 700W -|- Radeon 4870 1Gb @ 780/1050 -|- Asus VW202NR 20" wide-screen -|- Windows 7 Professional 64 Bit -|- Saitek Cyborg Keyboard -|- Razer Lachesis Mouse |
|
|
|
|
|
#5 |
|
Beta Member
Join Date: Jan 2011
Posts: 4
|
I am also having trouble with the same problem that you mentioned in your first post. The question states to create a constructor that accepts arguments for both the account number and balance. So, this is not right? I only need a constructor that sets the default to 0? Also, are there any get and set methods in the CheckingAccount class or are these in the TestCheckingAccount class? I am so confused, but I really want to write the classes on my own. Can you offer anymore help on this question without writing the applications out? Thanks.
|
|
|
|
|
|
#6 |
|
Site Team
Join Date: Jul 2009
Posts: 2,627
|
It's best to start a new thread posting full details of your problem, this one is rather old...
__________________
Save the whales, feed the hungry, free the mallocs. |
|
|
|
|
|
#7 |
|
Beta Member
Join Date: Jan 2011
Posts: 4
|
Thank you. I will. I only posted here because I am working on the exact same question.
|
|
|
|
|
|
#8 |
|
Site Team
Join Date: Jul 2009
Posts: 2,627
|
It's the same question so I see your logic. But just from the original question and your post I couldn't really understand what you're asking. It'll be a lot clearer if you start afresh, posting the same question but showing the things that you've tried and why you're stuck.
__________________
Save the whales, feed the hungry, free the mallocs. |
|
|
|
|
|
#9 |
|
Beta Member
Join Date: Jan 2011
Posts: 4
|
Thanks berry. I have reposted in a new thread.
|
|
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|