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 3 of 3

Thread: Beginner: Need help with making an object value equal another object value without using literals.

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Beginner: Need help with making an object value equal another object value without using literals.

    Hey everyone,

    I'm new to the programming world and I'm currently taking my first java programming course. I have to do an assignment which requires me adjust the altitude of two different balloons in a tester class. So far I believe I've done everything according to the professors instructions, but I'm stuck near the end. The question asks to "make the object you created in step 2 descend to the same altitude as the other object." He wants us to do this without just calculating the altitude ourselves and setting it as an int. I have no idea what to do here! Please help! My code so far looks like this:

    public class BalloonTester {
    public static void main(String[] args)
    {
    Balloon balloon = new Balloon("Balloon", 100);
    Balloon balloon2 = new Balloon ("Balloon2",-100);

    int Altitude ;
    String Name ;

    Name = balloon.getName() ;
    Altitude = balloon.getAltitude() ;
    System.out.println(Name);
    System.out.println(Altitude);

    Name = balloon2.getName() ;
    Altitude = balloon2.getAltitude();
    System.out.println(Name);
    System.out.println(Altitude);

    balloon.ascendTo(250) ;

    balloon2.adjustAltitude(+200) ;

    Name = balloon.getName() ;
    Altitude = balloon.getAltitude() ;
    System.out.println(Name);
    System.out.println(Altitude);

    Name = balloon2.getName() ;
    Altitude = balloon2.getAltitude();
    System.out.println(Name);
    System.out.println(Altitude);

    balloon.adjustAltitude(-100);

    --- Update ---

    the next line would be the step that he's asking us to complete. I feel its fairly simple, I just for the life of me can't figure it out.


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Beginner: Need help with making an object value equal another object value without using literals.

    Set the altitude of one object to the altitude of the other:

    balloon2.setAltitude( balloon1.getAltitude() );

    Or, if you have to use the adjustAltitude() method, then subtract one object's altitude from the other to get the adjustment:

    balloon2.adjustAltitude( balloon1.getAltitude() - balloon2.getAltitude() );

  3. #3
    Junior Member
    Join Date
    Sep 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Beginner: Need help with making an object value equal another object value without using literals.

    ahh okay thats so simple! thanks!

Similar Threads

  1. read & write object in object file
    By amirsarem in forum What's Wrong With My Code?
    Replies: 1
    Last Post: June 8th, 2013, 11:35 AM
  2. Making an object have a timer - needing help
    By Google me in forum Object Oriented Programming
    Replies: 1
    Last Post: June 1st, 2013, 10:01 PM
  3. Beginner : Using a loop to print object array
    By trancecommunity in forum What's Wrong With My Code?
    Replies: 6
    Last Post: February 5th, 2013, 06:31 PM
  4. Reading from ResultSet to Object and from object Object Array
    By anmaston in forum What's Wrong With My Code?
    Replies: 4
    Last Post: April 7th, 2011, 06:11 AM
  5. Replies: 2
    Last Post: February 25th, 2010, 04:17 PM