-
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.
-
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.
-
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 =)
-
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
-
Re: Programming exercise
ok :) but first will try to finish myself...