Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

import java.text.

DecimalFormat;
import java.util.Scanner;

public class OxygenProduction {


private double floorArea;
private double plantArea;

public OxygenProduction(double floorArea, double plantArea) {


this.floorArea = floorArea;
this.plantArea = plantArea;
}

public int calculateTotalPlants() {


double totalPlants = (floorArea * 10000) / plantArea;
int roundedPlants = (int) Math.floor(totalPlants / 10) * 10;
return roundedPlants;
}

public double calculateTotalOxygen() {


int totalPlants = calculateTotalPlants();
double oxygenProduction = totalPlants * 0.9;
return oxygenProduction;
}

public static void main(String[] args) {


Scanner scanner = new Scanner(System.in);
DecimalFormat decimalFormat = new DecimalFormat("0.00");

System.out.println("Enter the floor area of the room (m*m):");


double floorArea = scanner.nextDouble();

System.out.println("Enter the plant area of a single plant (in cm2):");


double plantArea = scanner.nextDouble();
scanner.close();

OxygenProduction oxygenProduction = new OxygenProduction(floorArea,


plantArea);
int totalPlants = oxygenProduction.calculateTotalPlants();
double totalOxygen = oxygenProduction.calculateTotalOxygen();

System.out.println("Total plants placed on floor area " +


decimalFormat.format(floorArea) + "*" +
decimalFormat.format(floorArea) + " is " + totalPlants + " plants
produces " +
decimalFormat.format(totalOxygen) + " litres of oxygen in a day");
}
}

You might also like