Results 21 to 37 of 37
- 01-09-2012, 01:10 AM #21
Re: Writing Two Classes help Please!!!!
So, i starts as 10. Java evals left to right. So, we start with ++i, which gives us 11. At the same time, i has been incremented to 11. Then we hit ++i again, which increments i (which was 11, and is now 12). 11+12 = 23!why does this happen:
int i=10;
System.out.print((++i) + (++i))
print out 23?! I don't know where this comes from
For the second case, we start with the value of i (10), and then increment. Since i++ is read first, increment later, it is still 10 until we get outside the current set of ()'s. We then hit ++i which takes the current value of i (which is now 11) and increments it. This gives use 12. 10 + 12 = 22.
- 01-10-2012, 09:29 PM #22
Senior Member
- Join Date
- Jan 2012
- Posts
- 142
- Rep Power
- 0
Re: Writing Two Classes help Please!!!!
Can someone help me with the Bank question in the initial post, just need a skeleton for the two classes please!!!
thanks so much
- 01-10-2012, 10:00 PM #23
Senior Member
- Join Date
- Jan 2012
- Posts
- 142
- Rep Power
- 0
Re: Writing Two Classes help Please!!!!
noone? It would really help a confused individual in need.....please
- 01-10-2012, 10:22 PM #24
Senior Member
- Join Date
- Jan 2012
- Posts
- 142
- Rep Power
- 0
Re: Writing Two Classes help Please!!!!
Could you please help me with the bank question in the first post of the thread, I don't understand it. Could you just explain the skeleton of the classes please.
Thanks alot
-
Re: Writing Two Classes help Please!!!!
I think you would be best served by talking to your teacher. You need to get a quick leg up on Java, which is more than we're able to do here.
- 01-10-2012, 11:16 PM #26
Senior Member
- Join Date
- Jan 2012
- Posts
- 142
- Rep Power
- 0
Re: Writing Two Classes help Please!!!!
but if someone wrote the skeleton for the two classes, you don't understand how much information I'd pick up of that. For me it is honestly the bet way to learn.
-
Re: Writing Two Classes help Please!!!!
No, you need to stop asking others to do your work for you, even to write a skeleton of a class, and instead start reading your book and a tutorials to see the structure of a class and try writing the skeleton yourself. Yes, you'll make mistakes, but you correct it and try and try again, and again, until it works. Otherwise you'll never learn Java, but more importantly, you won't learn how to learn.
- 01-10-2012, 11:35 PM #28
Senior Member
- Join Date
- Jan 2012
- Posts
- 142
- Rep Power
- 0
Re: Writing Two Classes help Please!!!!
I need help with the second class, I don't know how to get the list of accounts in. I've attempted to fully write out both classes, just the concept of the second class is confusing me, and as before mentioned it doesn't require inheritance and my book doesn't show how to do it, it only shows single classes.
-
Re: Writing Two Classes help Please!!!!
The only way we can help you is if you ask concrete specific questions. What about the second class, the Bank class, confuses you? Again, give as much detail as possible if we're to have a chance.
- 01-11-2012, 12:30 AM #30
Senior Member
- Join Date
- Jan 2012
- Posts
- 142
- Rep Power
- 0
Re: Writing Two Classes help Please!!!!
I got this so far:
How would I start the next class, the constructor and instance variables.Java Code:public class account{ private String account; private double quant; public account(String account, double quant){ this.account = account; this.quant = quant; } public String getOwner(){ return this.account; } public double getBalance(){ return this.quant; } public double depositmoney(double x){ return this.quant = this.quant + x; } public double withdrawmoney(double y){ if(y>this.quant){ System.out.println("INSUFFICIENT FUNDS"); } else{ this.quant = this.quant - y; } return this.quant; }Last edited by Fubarable; 01-11-2012 at 12:31 AM. Reason: code tags added
-
Re: Writing Two Classes help Please!!!!
I have added [code] [/code] tags to your post above so that the code retains its formatting. We'll be better able to help if you do this yourself in future posts -- thanks.
Also, Account class name and constructor should be capitalized. The owner String variable shouldn't have the same name as the class, but instead you should choose another name. "owner" has a nice ring to it and works well for me. Also, the depostMoney method shouldn't return anything, but instead should just deposit money.
Again, try to do it first yourself and show us what you've tried. You've got to stretch your brain cells to the limit and beyond to learn this stuff.How would I start the next class, the constructor and instance variables.Last edited by Fubarable; 01-11-2012 at 12:37 AM.
- 01-11-2012, 01:04 AM #32
Senior Member
- Join Date
- Jan 2012
- Posts
- 142
- Rep Power
- 0
Re: Writing Two Classes help Please!!!!
But I don't know how to put the list in as it requires.
-
Re: Writing Two Classes help Please!!!!
OK, the way I see it, you can do one of two options:
- You could create an empty array and fill it with Accounts as you get them realizing that the array will be filled with nulls until you add an Account object in. You will have to keep track of how many Accounts have been added so you don't add more than the array can hold.
- Easier by far would be to use an ArrayList variable and add Accounts to this. Think of this like an array that can change size when necessary and without your having to tell it to. You simply keep adding Accounts to this.
- 01-11-2012, 01:23 AM #34
Senior Member
- Join Date
- Jan 2012
- Posts
- 142
- Rep Power
- 0
Re: Writing Two Classes help Please!!!!
where do i put the array list?
-
Re: Writing Two Classes help Please!!!!
It would be a class field, a variable declared near the top of the Bank class, similar to how you have declared quant in your Account class.
- 01-11-2012, 03:19 AM #36
Senior Member
- Join Date
- Jan 2012
- Posts
- 142
- Rep Power
- 0
Re: Writing Two Classes help Please!!!!
ok i declared it as an instance variable, but what do i do with it now. I just don't understand what the purpose of it is and what I will use it for.
I appreciate your help,
thanks
- 01-11-2012, 04:36 AM #37
Similar Threads
-
difficulty understanding writing classes
By elecleoalune in forum New To JavaReplies: 11Last Post: 04-18-2011, 03:06 PM -
Writing classes???
By Bgreen7887 in forum New To JavaReplies: 1Last Post: 11-04-2010, 08:06 AM -
Im writing to a file and i want to skip lines while writing to a text file.
By Broden_McDonald in forum New To JavaReplies: 1Last Post: 02-27-2010, 01:29 AM -
Writing importable classes
By Katsu in forum New To JavaReplies: 6Last Post: 03-08-2009, 09:10 PM -
Writing classes in graphics
By CyberFrog in forum Java AppletsReplies: 2Last Post: 04-05-2008, 05:37 PM


2Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks