Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Ron bought several acres of farm to grow and sell vegetables. Suppose that Ron w

ID: 3768144 • Letter: R

Question

Ron bought several acres of farm to grow and sell vegetables. Suppose that Ron wants to grow a maximum of two types of vegetables. Write a program that prompts Ron or the user to do the following:

1. Enter the total farm area in acres. 2. The number of vegetables ( one or two) that the user wants to grow. 3. If the user wants to grow two types of vegetables, then specify the portion, as a percentage, of the farm land used for each type of vegetable. 4. Enter the seed cost, plantation cost, fertilizing coat, labor cost, for each acre. 5. Enter vegetables selling price per acre. 6. Output the total revenue. 7. Output the profit/loss.

Explanation / Answer

import java.util.Scanner;

public class Farm {
  
   public static void main(String[] args) {
       Scanner scanner = new Scanner(System.in);
       System.out.println("Enter the total farm area in acres");
       double farmArea = scanner.nextDouble();
       System.out.println("Enter the number of vegetables ( one or two) that you want to grow");
       int numberOfVegetables = scanner.nextInt();
       if (numberOfVegetables == 2) {
           System.out.println("Enter percentage of 1st vegetable");
           double veg1Portion = scanner.nextDouble();
           double veg2Portion = 100 - veg1Portion;
           System.out.println("Enter seed cost of 1st vegetable");
           double veg1SeedCost = scanner.nextDouble();
           System.out.println("Enter seed cost of 2nd vegetable");
           double veg2SeedCost = scanner.nextDouble();
           System.out.println("Enter plantation cost of 1st vegetable");
           double veg1PlantCost = scanner.nextDouble();
           System.out.println("Enter plantation cost of 2nd vegetable");
           double veg2PlantCost = scanner.nextDouble();
           System.out.println("Enter fertilizint cost");
           double fertilizingCost = scanner.nextDouble();
           System.out.println("Enter labor cost");
           double laborCost = scanner.nextDouble();
           System.out.println("Enter selling price of 1st vegetable");
           double veg1SP = scanner.nextDouble();
           System.out.println("Enter selling price of 2nd vegetable");
           double veg2SP = scanner.nextDouble();
           double revenue = (veg1SP*veg1Portion + veg2SP*veg2Portion)*farmArea/100;
           System.out.println("Revenue = " + revenue);
           double totalCost = ((veg1SeedCost + veg1PlantCost)*veg1Portion/100 + (veg2SeedCost + veg2PlantCost)*veg2Portion/100 + fertilizingCost + laborCost)*farmArea;
           if (revenue >= totalCost) {
               System.out.println("Profit = " + (revenue - totalCost));
           }
           else {
               System.out.println("Loss = " + (totalCost - revenue));
           }
       }
       else {
           System.out.println("Enter seed cost of vegetable");
           double seedCost = scanner.nextDouble();
           System.out.println("Enter plantation cost vegetable");
           double plantCost = scanner.nextDouble();
           System.out.println("Enter fertilizint cost");
           double fertilizingCost = scanner.nextDouble();
           System.out.println("Enter labor cost");
           double laborCost = scanner.nextDouble();
           System.out.println("Enter selling price vegetable");
           double sp = scanner.nextDouble();
           double revenue = sp*farmArea;
           System.out.println("Revenue = " + revenue);
           double totalCost = (seedCost + plantCost + fertilizingCost + laborCost)*farmArea;
           if (revenue >= totalCost) {
               System.out.println("Profit = " + (revenue - totalCost));
           }
           else {
               System.out.println("Loss = " + (totalCost - revenue));
           }
       }
   }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote