Results 1 to 5 of 5
  1. #1
    Markmywoods is offline Member
    Join Date
    Feb 2016
    Posts
    14
    Rep Power
    0

    Default instantiate, populate & view the contents of objects using the toString method?

    The instructions follow : Complete the Contact class, BudgetCategory class and Transaction class. You should create a
    main method that will instantiate, populate and view the contents of the objects using the toString method


    I have made the classes and never learned how to populate a object. I've researched and found to populate an object is to put values in the objects fields.


    If it helps I've provided the toString methods for each class.

    Contact class :

    @Override
    public String toString(){
    return homeAddress + "\n" + phone + "\n" + email;
    }

    BudgetCategory class :

    @Override
    public String toString(){
    return catName + "\n" + catDescription + "\n" + amount + "\n" + categoryType;
    }

    Transaction class :

    @Override
    public String toString(){
    return category + "\n" + date + "\n" + amount + "\n" + description;
    }

  2. #2
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,991
    Rep Power
    8

    Default Re: instantiate, populate & view the contents of objects using the toString method?

    As I can tell from the toString method, in the Contact class you (are supposed to) have fields homeAddress, phone and email. Do these fields exist? If not, create them. Then, to "populate" them, create setters (and getters for bonus points) so you can do this:
    Java Code:
    Contact boss = new Contact();
    boss.setHomeAddress("some address");
    Alternatively, or maybe even both, you can create a constructor that accepts all the different values for homeAddress, phone and email, and puts them in the corresponding fields. That allows for:
    Java Code:
    Contact boss = new Contact( "some address", "some phone" , "some mail");
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2ô © 2013

  3. #3
    Markmywoods is offline Member
    Join Date
    Feb 2016
    Posts
    14
    Rep Power
    0

    Default Re: instantiate, populate & view the contents of objects using the toString method?

    Yes they exist. I have made accessors and mutators for each class as the instructions said. I also have a constructor already so just put values in them as you did Contact boss = new Contact( "some address", "some phone" , "some mail"); ?

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: instantiate, populate & view the contents of objects using the toString method?

    When posting code Please wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,991
    Rep Power
    8

    Default Re: instantiate, populate & view the contents of objects using the toString method?

    Quote Originally Posted by Markmywoods View Post
    Yes they exist. I have made accessors and mutators for each class as the instructions said. I also have a constructor already so just put values in them as you did Contact boss = new Contact( "some address", "some phone" , "some mail"); ?
    Ok, good. So where are you stuck? Does it compile? Can you show some code that does or does not work? Any errors?
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2ô © 2013

Similar Threads

  1. How to View contents of .ISO file in java?
    By zakhilton in forum Advanced Java
    Replies: 4
    Last Post: 07-17-2014, 03:13 PM
  2. Replies: 0
    Last Post: 09-13-2013, 12:12 PM
  3. Printing the contents of an array of objects
    By Mr.Paplu in forum New To Java
    Replies: 1
    Last Post: 03-19-2009, 04:49 PM
  4. Replies: 1
    Last Post: 07-18-2007, 11:20 PM
  5. Replies: 0
    Last Post: 07-17-2007, 03:30 PM

Posting Permissions

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