Page 5 of 5 FirstFirst ... 345
Results 81 to 93 of 93
Like Tree4Likes

Thread: adding an object to an array in another class

  1. #81
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,029
    Rep Power
    6

    Default Re: adding an object to an array in another class

    I'll give you a hint: there is a big difference between data and the presentation of that data.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  2. #82
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,616
    Rep Power
    5

    Default Re: adding an object to an array in another class

    Well, you did say "show" only two places. When the number is not being displayed you don't usually care what it looks like. When you finally are ready to display it as a string, the you can format it with String.format. Also, be careful when doing monetary calculations with double as they can lead to inaccuracies due to rounding errors.

    Regards,
    Jim
    Last edited by jim829; 08-02-2013 at 05:52 PM. Reason: YAT
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #83
    jwood is offline Senior Member
    Join Date
    Jun 2013
    Posts
    136
    Rep Power
    0

    Default Re: adding an object to an array in another class

    Hmmm.....this is how it is being displayed....

    Java Code:
    System.out.print('\n' + "Number of two door cars rented: " + newCompany.get2DoorCount() + '\n' +
    			"Number of four door cars rented: " + newCompany.get4DoorCount() + '\n' +
    			"Average days rented out is: " + newCompany.getAvgDays() + '\n' +
    			"Average rate is: $" + newCompany.getAvgRate() + '\n' +
    			"Total rental income is: $" + newCompany.getTotalRentalSales() + '\n' + '\n');

  4. #84
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,616
    Rep Power
    5

    Default Re: adding an object to an array in another class

    The return values in the methods are simply returning decimal values (I guess) and are being converted to Strings. So use either String.format or System.out.printf() and write a few test programs to see how to format numbers.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  5. #85
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: adding an object to an array in another class

    String.format() API.
    It formats the given data using the given format and turns it into a String.
    You have a double, which you want to represent as a String in a certain way...that's what this method is for.

    It uses the following format syntax.
    Once you've read the intro for that you'll want the section on float and double.

    ETA: And, of course, I forgot to check if there was a second page...DOH!
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #86
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,242
    Rep Power
    19

    Default Re: adding an object to an array in another class

    Quote Originally Posted by Tolls View Post
    ETA: And, of course, I forgot to check if there was a second page...DOH!
    Second?
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  7. #87
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: adding an object to an array in another class

    Quote Originally Posted by DarrylBurke View Post
    Second?
    OK, "another"...

    It's Friday, leave me alone!
    :P
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  8. #88
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,526
    Blog Entries
    7
    Rep Power
    20

    Default Re: adding an object to an array in another class

    Quote Originally Posted by Tolls View Post
    OK, "another"...

    It's Friday, leave me alone!
    :P
    My calculations show that the probability that an arbitrary day is a Friday is 0.1428571429 (which is +/- 1/7); extensive tests have shown that the probability P(Friday & x) where x is any other day except Friday is about 0. Question: P(Friday | x) equals 1 where x is any other day, except Friday?

    kindest regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  9. #89
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: adding an object to an array in another class

    Wibble...
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  10. #90
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,029
    Rep Power
    6

    Default Re: adding an object to an array in another class

    extreme heat (35 degrees) seems to make Jos go into a Math loop.

    On that note: anyone know of any dinner recipes involving ice cream?
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  11. #91
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,242
    Rep Power
    19

    Default Re: adding an object to an array in another class

    Baked or fried?
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  12. #92
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,526
    Blog Entries
    7
    Rep Power
    20

    Default Re: adding an object to an array in another class

    Quote Originally Posted by DarrylBurke View Post
    Baked or fried?
    Both, but I'm trying to keep the inside cool enough with ample supplies of Grolsch.

    kind regards,

    Jos
    DarrylBurke likes this.
    cenosillicaphobia: the fear for an empty beer glass

  13. #93
    jwood is offline Senior Member
    Join Date
    Jun 2013
    Posts
    136
    Rep Power
    0

    Default Re: adding an object to an array in another class

    got the decimal thing

    import java.text.DecimalFormat;

    DecimalFormat fmt = new DecimalFormat("0.00");

    fmt.format(theRooms[i].getRoomRate())
    DarrylBurke likes this.

Page 5 of 5 FirstFirst ... 345

Similar Threads

  1. null pointer when adding object into an array
    By NoobieCode in forum New To Java
    Replies: 6
    Last Post: 07-24-2013, 11:58 PM
  2. Replies: 15
    Last Post: 08-19-2011, 03:08 AM
  3. help adding to array from another class
    By Grid_iso in forum New To Java
    Replies: 0
    Last Post: 05-09-2011, 10:00 AM
  4. Replies: 1
    Last Post: 05-04-2010, 11:00 AM
  5. Adding elements to an Object Array
    By aneesahamedaa in forum New To Java
    Replies: 4
    Last Post: 09-07-2008, 03:55 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
  •