Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

During each summer John and Jessica grow vegetables in their back yard and buy seeds and fertilizer from a local nursery. The nursery carries different

During each summer John and Jessica grow vegetables in their back yard and buy seeds and fertilizer from a local nursery. The nursery carries different types of vegetable fertilizers in various bag sizes. When buying a particular fertilizer, they want to know the price of the fertilizer per pound and the cost of fertilizing per square foot. The following program prompts the user to enter the size of the fertilizer bag, in pounds, the cost of the bag, and the area, in square feet, that can be covered by the bag. The program should output the desired result. However, the program contains logic errors. Find and correct the logic errors so that the program works properly.

//Logic errors. import java.util.*;

public class Ch3_PrExercise4

{

static Scanner console = new Scanner(System.in);

public static void main(String[] args) { double cost; double area; double bagSize; System.out.print("Enter the amount of fertilizer, " + "in pounds, in one bag: "); bagSize = console.nextDouble(); System.out.println(); System.out.print("Enter the cost of the " + bagSize + " pound fertilizer bag: "); cost = console.nextDouble(); System.out.println(); System.out.print("Enter the area, in square feet, that " + "can be fertilized by one bag: "); area = console.nextDouble(); System.out.println(); System.out.printf("The cost of the fertilizer per pound is: " + "$%.2f%n", bagSize / cost); System.out.printf("The cost of fertilizing per square " + "foot is: $%.4f%n", area / cost);

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Principles Of Database Systems With Internet And Java Applications

Authors: Greg Riccardi

1st Edition

020161247X, 978-0201612479

More Books

Students also viewed these Databases questions