Question: Estimate the time it will take to cut the grass of five clients. Given the length and width (in meters) of a rectangular yard and the length and width of a rectangular house situated in the yard, compute the time required (in minutes) to cut the grass at a rate of 2.3 square meters per second.

import javax.swing.*;

public class Gard

 { 
 	public static void main(String[]args)
  
  {
  	// Variable declarations
  	
  	String gd;
  	Double st, st2, st3, st4, time;
  	
  	 for(int i=1; i<=5; i++)	
  	 {
  	 	
  	// Get user input
  	 	

  	gd = JOptionPane.showInputDialog("Enter the length of yard");
  	st = Double.parseDouble(gd);
  	st2 = Double.parseDouble(JOptionPane.showInputDialog("Enter the width of yard"));
	st3 = Double.parseDouble(JOptionPane.showInputDialog("Enter the length of house"));
  	st4 = Double.parseDouble(JOptionPane.showInputDialog("Enter the width of house"));
  	
  	
  	//Calculate
   	
   	time=(st * st2 - st3 * st4)/2.3;
   	
  	
  	// Display the result
  	System.out.println("The time required (in minutes) to cut the grass: "+time);
  	
	} // end of loop

  } // end of main

} // end of class

I'm not sure if i have everything done...

I don't see why you need a DecimalFormat, I don't think it is necessary. And what is your question?

I don't see why you need a DecimalFormat, I don't think it is necessary. And what is your question?

I actually wanted to round off in two decimal places. I know it has to do with float Math.pow

My question is am i on the right track here with what is being asked as "Question".


-I'm a noob btw..

time=(st * st2 - st3 * st4)/2.3;

One obvious mistake is that the above will calculate the area of the yard minus the length of the house, then times the width of the house. What you want to do is the area of the yard minus the area of the house. Then you want to divide that by 2.3, but you still aren't done. Consider your units. Area is in meters, your speed is in m/s, so the final units will be in s. In other words, your time variable will hold the number of seconds to cut the yard... but the problem asks for minutes, not seconds. Do the conversion.

But you still might have problems. After you make those changes, try out your code and if you experience problems, tell us what those problems are.

Ok this is my final work...could you tell me if i'm missing anything or need anymore work? and i was wondering what code can i use to round off

import javax.swing.*;

public class GardeningX

 { 
 	public static void main(String[]args)
  
  {
  	// Variable declarations
  	String biz;
  	double h_len, h_wid, h_area, yd_len, yd_wid, 
  	yd_area, grs_area, time_req, time_counter=0, ft_counter=0;
	  
	// Welcome heading
  	System.out.println("WELCOME TO GARDENING PROGRAMMING");
	
	// for loop 
  	for(int i=1; i<=5;i++)
	    {
	    	
  	// Prompt user for Input 
  	biz = JOptionPane.showInputDialog("Enter the length (in meters) of house # "+i);
  	h_len = Double.parseDouble(biz);
  	h_wid = Double.parseDouble(JOptionPane.showInputDialog("Enter the width (in meters) of house # "+i));
  	yd_len = Double.parseDouble(JOptionPane.showInputDialog("Enter the length (in meters) of yard # "+i));
  	yd_wid = Double.parseDouble(JOptionPane.showInputDialog("Enter the width (in meters) of yard # "+i));
	
	// Calculation 
  	h_area= h_len * h_wid;
  	yd_area= yd_len * yd_wid;
  	grs_area= yd_area - h_area;
		
  	time_req=grs_area / 2.3;
		
  	
  	// Time conversion
  	if( time_req > 59)
  	{
  	time_req = time_req / 60;
  	}
	
	// Time counter	
  	time_counter = time_counter + time_req;
  	ft_counter = ft_counter + grs_area;
  	
  	// Display the result
  	System.out.println("The grass area is: " + ft_counter * 3);
	   	  
  	System.out.println("The time required: " + time_counter);
		
  	
  	} // end of for loop
	      
  	System.exit(0);

	
	} // end of main
	
} // end of class
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.