## Posted By

joshnunn on 08/02/09

# Tomatoes.java

/ 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.

`public class Tomatoes {     /**     * @param args the command line arguments     */    public static void main(String[] args) {        int plantCost = 93;        double xSide = 124.27473984;        double ySide = 332.236238764;        int plantsPerSquareMeter = 5;        int totalPlants;        int totalCost;         totalPlants = ((int) Math.floor(xSide * ySide)) * plantsPerSquareMeter;        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);    }}`