Question
do it by method which return the result(via parameter )to the main program which will print out the result This project calculate the cost of
do it by method which return the result(via parameter )to the main program which will print out the result
This project calculate the cost of putting a fence all the way around a rectangular yard AND
putting sod everywhere in the yard EXCEPT for a circular flower bed.Input is from the keyboard.
Input the length and width of the yard and the radius of the flower bed (all double and all in feet).
The cost of fencing (make this a constant) is $2.50 per foot and the cost of sod is $1.50 per square foot (another constant).
*/
package h3.ghurub;
import java.util.Scanner;
/**
*
* @author
*/
public class H3Ghurub {
public static void main(String[] args) {
//get input
Scanner K = new Scanner(System.in);
double length;
double width;
double radius;
//set constants
final double CostOFfencing = 2.50;//cost of fencing per foot
final double CostofSod = 1.50;//cost of sod per square foot
//get input
System.out.println("Enter the length :");
length = K.nextDouble(); // get input
System.out.println("Enter the width :");
width = K.nextDouble();//get input
System.out.println("Enter the radius :");
radius = K.nextDouble();//get input
//calculate rectangular area
double rectangularYardarea = length * width;
//calculate rectangular perimeter
double perimeterofyard = 2 * (length + width);
double circulaflowerbed = Math.PI * radius * radius; //calculate circle of flower
double totalcostofF = Math.ceil(perimeterofyard )* CostOFfencing;
System.out.println("cost of fence is "+"$"+totalcostofF);//output the total cost of fence
double areaofsod = rectangularYardarea - circulaflowerbed ;//calculate area of sod
double totalcostofsod = areaofsod * CostofSod;// calculate total cost of sod
System.out.println("cost of sod is "+"$"+Math.ceil(totalcostofsod));//output the cost of sod
double totalcost = Math.ceil(totalcostofsod )+ totalcostofF;
System.out.println("total cost is "+"$"+totalcost);//output total cost of fence and sod
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started