# Writing Two Classes help Please!!!!

Show 40 post(s) from this thread on one page
Page 2 of 2 First 12
• 01-09-2012, 02:10 AM
Re: Writing Two Classes help Please!!!!
Quote:

why does this happen:

int i=10;

System.out.print((++i) + (++i))

print out 23?! I don't know where this comes from
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!

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, 10:29 PM
stuckonjava
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, 11:00 PM
stuckonjava
Re: Writing Two Classes help Please!!!!
noone? It would really help a confused individual in need.....please
• 01-10-2012, 11:22 PM
stuckonjava
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
• 01-10-2012, 11:28 PM
Fubarable
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-11-2012, 12:16 AM
stuckonjava
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.
• 01-11-2012, 12:28 AM
Fubarable
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-11-2012, 12:35 AM
stuckonjava
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.
• 01-11-2012, 12:52 AM
Fubarable
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, 01:30 AM
stuckonjava
Re: Writing Two Classes help Please!!!!
I got this so far:

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;         }```
How would I start the next class, the constructor and instance variables.
• 01-11-2012, 01:34 AM
Fubarable
Re: Writing Two Classes help Please!!!!
Quote:

Originally Posted by stuckonjava
I got this so far:

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.

Quote:

How would I start the next class, the constructor and instance variables.
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.
• 01-11-2012, 02:04 AM
stuckonjava
Re: Writing Two Classes help Please!!!!
But I don't know how to put the list in as it requires.
• 01-11-2012, 02:14 AM
Fubarable
Re: Writing Two Classes help Please!!!!
Quote:

Originally Posted by stuckonjava
But I don't know how to put the list in as it requires.

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, 02:23 AM
stuckonjava
Re: Writing Two Classes help Please!!!!
where do i put the array list?
• 01-11-2012, 02:25 AM
Fubarable
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, 04:19 AM
stuckonjava
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.