Page 2 of 2 FirstFirst 12
Results 21 to 37 of 37
Like Tree2Likes

Thread: Writing Two Classes help Please!!!!

  1. #21
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: Writing Two Classes help Please!!!!

    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.

  2. #22
    stuckonjava is offline Senior Member
    Join Date
    Jan 2012
    Posts
    151
    Rep Power
    3

    Default 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

  3. #23
    stuckonjava is offline Senior Member
    Join Date
    Jan 2012
    Posts
    151
    Rep Power
    3

    Default Re: Writing Two Classes help Please!!!!

    noone? It would really help a confused individual in need.....please

  4. #24
    stuckonjava is offline Senior Member
    Join Date
    Jan 2012
    Posts
    151
    Rep Power
    3

    Default 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

  5. #25
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default 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.

  6. #26
    stuckonjava is offline Senior Member
    Join Date
    Jan 2012
    Posts
    151
    Rep Power
    3

    Default 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.

  7. #27
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default 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.

  8. #28
    stuckonjava is offline Senior Member
    Join Date
    Jan 2012
    Posts
    151
    Rep Power
    3

    Default 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.

  9. #29
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default 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.

  10. #30
    stuckonjava is offline Senior Member
    Join Date
    Jan 2012
    Posts
    151
    Rep Power
    3

    Default Re: Writing Two Classes help Please!!!!

    I got this so far:

    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;
    	}
    How would I start the next class, the constructor and instance variables.
    Last edited by Fubarable; 01-11-2012 at 01:31 AM. Reason: code tags added

  11. #31
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Writing Two Classes help Please!!!!

    Quote Originally Posted by stuckonjava View Post
    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.

    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.
    Last edited by Fubarable; 01-11-2012 at 01:37 AM.

  12. #32
    stuckonjava is offline Senior Member
    Join Date
    Jan 2012
    Posts
    151
    Rep Power
    3

    Default Re: Writing Two Classes help Please!!!!

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

  13. #33
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Writing Two Classes help Please!!!!

    Quote Originally Posted by stuckonjava View Post
    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.

  14. #34
    stuckonjava is offline Senior Member
    Join Date
    Jan 2012
    Posts
    151
    Rep Power
    3

    Default Re: Writing Two Classes help Please!!!!

    where do i put the array list?

  15. #35
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default 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.

  16. #36
    stuckonjava is offline Senior Member
    Join Date
    Jan 2012
    Posts
    151
    Rep Power
    3

    Default 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

  17. #37
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: Writing Two Classes help Please!!!!

    Didn't we already explain this? Twice?

    Ooops! Wrong post window, sorry! I wasn't talking to you 'stunckonjava!'!

Page 2 of 2 FirstFirst 12

Similar Threads

  1. difficulty understanding writing classes
    By elecleoalune in forum New To Java
    Replies: 11
    Last Post: 04-18-2011, 04:06 PM
  2. Writing classes???
    By Bgreen7887 in forum New To Java
    Replies: 1
    Last Post: 11-04-2010, 09:06 AM
  3. Replies: 1
    Last Post: 02-27-2010, 02:29 AM
  4. Writing importable classes
    By Katsu in forum New To Java
    Replies: 6
    Last Post: 03-08-2009, 10:10 PM
  5. Writing classes in graphics
    By CyberFrog in forum Java Applets
    Replies: 2
    Last Post: 04-05-2008, 06:37 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •