Results 1 to 5 of 5
Thread: Programming exercise
- 02-22-2012, 08:45 PM #1
Member
- Join Date
- Jun 2011
- Posts
- 54
- Rep Power
- 0
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.
- 02-22-2012, 11:02 PM #3
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 =)
- 02-22-2012, 11:03 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 28
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,
JosBuild a wall around Donald Trump; I'll pay for it.
- 02-22-2012, 11:09 PM #5
Member
- Join Date
- Jun 2011
- Posts
- 54
- Rep Power
- 0
Similar Threads
-
Programming exercise help
By atac57 in forum New To JavaReplies: 4Last Post: 01-13-2012, 04:37 PM -
Having trouble with programming exercise, help?
By atac57 in forum New To JavaReplies: 1Last Post: 01-12-2012, 07:11 AM -
Programming exercise for beginners
By FOX427 in forum New To JavaReplies: 5Last Post: 07-16-2011, 08:43 AM -
Need help with a programming exercise
By ararar in forum New To JavaReplies: 9Last Post: 11-19-2010, 06:57 AM -
Have I done this exercise right?
By ccie007 in forum New To JavaReplies: 7Last Post: 09-28-2010, 06:54 PM
Bookmarks