Saturday, 24 August 2013

Java - Grammar check not operating properly

Java - Grammar check not operating properly

I had a question earlier on a program I was writing to simulate plant
growth. It essentially uses a loop that counts up to a predetermined
limit.
I have since changed my code to the following:
/*
Java program: plant.java
This program runs a loop simulating plant growth.
The idea is that the plant will continue to have "repeated"
growth and that it will stop (or slow down to a crawl) at some point,
in this case at 100 branches.
*/
public class plant1
{
public static void main (String [] poop)
{
int current_growth = 0, limit = 100; //plant growth starts at ZERO
and is limited to 100
String word = "branches";
for(current_growth = 0; current_growth <= limit; ++current_growth)
{
//here, we are checking to see if the plant has grown just 1
inch.
//this is important just for grammatical purposes
if (current_growth == 1)
{
word = "branch"; //this changes the "word" to branch
instead of branches
}
if (current_growth < 100)
{
System.out.println("Your plant has grown " + current_growth +
" " + word);
}
else
{
System.out.println("Your plant will no longer grow.");
} // end else
} //end while loop
} //end main method
} //end class
The only problem is the following:
I added a grammatical check to check for singular and plural with regards
to the number of branches being printed.
However, when I run the code the check doesn't work so I have sentences
like Your plant has grown 97 branch when it should say Your plant has
grown 97 branches

No comments:

Post a Comment