/ Published in: Java
A farmer has a small field that is 124 metres by 332 metres. The farmer wants to plant tomatoes in his field. It is possible to put 5 plants in every square metre. Each plant costs 95cents. Write a small program that calculates the number of plants that will go into the field and the resulting cost.
Expand |
Embed | Plain Text
public class Tomatoes { /** * @param args the command line arguments */ int plantCost = 93; double xSide = 124.27473984; double ySide = 332.236238764; int plantsPerSquareMeter = 5; int totalPlants; int totalCost; totalCost = totalPlants * plantCost; System.out.println("You need to plant " + totalPlants + " plants to fill up a " + xSide + " by " + ySide + " field."); System.out.println("At $" + (double)plantCost/100 + " per plant the cost will be: $" + (double)totalCost/100); } }
You need to login to post a comment.
