Results 1 to 5 of 5
Like Tree2Likes
  • 1 Post By Fubarable
  • 1 Post By JosAH

Thread: Programming exercise

  1. #1
    FOX427 is offline Member
    Join Date
    Jun 2011
    Posts
    54
    Rep Power
    0

    Smile Programming exercise

    Hi All! I am noob in programming so please don't get mad at me if it's too easy for you guys. I am practicing programming, this is not homework assignment and I am doing it because i want to learn Java, but i am stuck and I spend nearly 4 hours to try figuring out this and I don't want to move to the next step without finishing it. in short I have:

    public class ProgrammingOne {
    public static void main(String[] args)
    {
    Species s1 = new Species(), s2 = new Species();
    System.out.println("Enter data for the first species: ");
    s1.readInput();
    System.out.println("Enter data for the second species: ");
    s2.readInput();
    System.out.println("The first speciess are: ");
    s1.writeOutput();
    System.out.println("The second species are: ");
    s2.writeOutput();

    }
    }

    Exercise asks: "Your program will ask for the data on both species and will respond by telling how many years it will take for the species with the lower population to get a population that exceeds that of the species that starts with the higher population". basically it asks only 3 questions(readInput)-name, population and growth rate and gives values to screen (writeOutput), I did first part and it works perfectly, the next I have to compare and calculate it, I am planning to add:

    if (s1.population>s2.population)
    System.out.print("First population is bigger.");
    else
    System.out.println("Second population is bigger.");

    but the problem is I can't define method population(due to lack of knowledge:(). and after defining it I have to calculate in how many years I will exceed first one. If you can help me I would be very grateful, thank you in advance! regards.

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

    Default Re: Programming exercise

    This question has nothing to do with Eclipse and all to do with the poster being new to Java. Moving to the appropriate forum.
    FOX427 likes this.

  3. #3
    santa's Avatar
    santa is offline Senior Member
    Join Date
    Nov 2009
    Location
    Sweden
    Posts
    208
    Rep Power
    5

    Default Re: Programming exercise

    Well I don't see how I can help you with only the code you submitted ... I can't guess whats going on in the Species class ? There is lots of ways to compare objects ... I would suggest looking at the comparable interface =)

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,656
    Blog Entries
    7
    Rep Power
    21

    Default Re: Programming exercise

    A better name would be getPopulation() and that method would return, well the population of that particular Species. It'd simply be a method in the Species class.

    kind regards,

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

  5. #5
    FOX427 is offline Member
    Join Date
    Jun 2011
    Posts
    54
    Rep Power
    0

    Default Re: Programming exercise

    ok :) but first will try to finish myself...

Similar Threads

  1. Programming exercise help
    By atac57 in forum New To Java
    Replies: 4
    Last Post: 01-13-2012, 03:37 PM
  2. Having trouble with programming exercise, help?
    By atac57 in forum New To Java
    Replies: 1
    Last Post: 01-12-2012, 06:11 AM
  3. Programming exercise for beginners
    By FOX427 in forum New To Java
    Replies: 5
    Last Post: 07-16-2011, 07:43 AM
  4. Need help with a programming exercise
    By ararar in forum New To Java
    Replies: 9
    Last Post: 11-19-2010, 05:57 AM
  5. Have I done this exercise right?
    By ccie007 in forum New To Java
    Replies: 7
    Last Post: 09-28-2010, 05:54 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
  •