Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: The getAccount method returns the reference to the Account object.

  1. #1
    Junior Member
    Join Date
    Mar 2019
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question The getAccount method returns the reference to the Account object.

    Hello Everyone.
    I am refreshing my Java programing as I took a course back to 2007. So, I started from scratch. There is a project and I got stack in one statement. "The getAccount method returns the reference to the Account object. return account"

    This is a fragment of the Customer class

    Customer Class
    -accounts : Account = new Account()
    -city = String
    -address = String
    -firstName = String
    -lastName = String
    -
    -
    ------------------------
    -getAddress(): String
    -getAccount(): Account
    -
    -

    So, I was doing my programing until I got the getAccount

    public class Customer
    {
        String firstName;
        String lastName;
        String streetAddress;
        String cityName;
        String zipOrPostalCode;
     
        public String getAddress()
        {
            return streetAddress + cityName + zipOrPostalCode;
        }
     
        public String getName()
        {
            return lastName + ',' + firstName;
        }
     
    }

    I have another class called Account

    public class Account
    {
        char acctType;
        double balance; 
        String acctId;
     
        public void setBalance(double amount) 
        { 
           balance = amount;   // assigns the value of amount to the object attribute balance.
        }
     
         public void setId(String id)
        {
            acctId = id;
        }
     
        public void setAcctType(char type)
        {
            acctType = type;
        }
     
            public String getID() 
        { 
            return acctId;  // note the use of the return keyword to return a value
        }  
     
        public char getAcctType()
        {
            return acctType; 
        }
     
        public double getBalance()
        {
            return balance;
        }
     
    }

    On top of that, how I set up the setAccount according to this statement
    The setAccount method receives a reference to an Account object. Assign this to the account field of the object: account = acct.

    I appreciated if someone there would like to give me a help with that getAccount method in the Customer Class Please. Thank you

    Hector
    Last edited by Hoota79; March 2nd, 2019 at 06:28 AM.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,322
    Thanks
    53
    Thanked 2,393 Times in 2,347 Posts

    Default Re: The getAccount method returns the reference to the Account object.

    help with that getAccount method
    Can you explain what problems you are having?
    What is that method supposed to do?
    What have you tried?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Mar 2019
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: The getAccount method returns the reference to the Account object.

    Quote Originally Posted by Norm View Post
    Can you explain what problems you are having?
    What is that method supposed to do?
    What have you tried?
    The class has these attributes:
    Customer class
    - custID: int
    - account: Account
    - firstName: String
    - lastName: String
    and so on
    ------------
    as methods it has
    + getName();
    + setName(fName: String, lname: String): void
    + getAccount(): Account;
    and so on

    It supposed that a teller class has the void main().

    So setting up the methods, How do I do with the getAccount. How do I reference and code this.
    By the way, I just got my notes from 11 years ago and I am actually learning from scratch all over again and this is a Java Bank demo app. I am entering chapter 3 at the moment reading references so I am still a little puzzle with this but I can get there. I just mentioned on the forum to have a better approach from the experts. Sometimes books get a little to deep with the words.

    regards,

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,322
    Thanks
    53
    Thanked 2,393 Times in 2,347 Posts

    Default Re: The getAccount method returns the reference to the Account object.

    How do I do with the getAccount.
    I assume that the getAccount method would return the reference to the instance of the Account class held in the class.
    For an example from the posted code, the getBalance method returns the value held in the balance variable.

    Here is a link to the Java Tutorial: https://docs.oracle.com/javase/tutorial/index.html
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 2
    Last Post: May 27th, 2014, 12:36 PM
  2. Can an object change it's own reference?
    By Cereno in forum Java Theory & Questions
    Replies: 3
    Last Post: December 5th, 2012, 12:29 PM
  3. Creating Method that returns a casted object type
    By aussiemcgr in forum Java Theory & Questions
    Replies: 2
    Last Post: October 31st, 2012, 01:23 PM
  4. Replies: 1
    Last Post: February 14th, 2012, 06:42 AM
  5. Object Reference
    By Mr.777 in forum Object Oriented Programming
    Replies: 2
    Last Post: June 13th, 2011, 03:03 AM