Question: Please help in Java: You need to use a Circle (for the flower bed) and a Rectangle (for the yard). This program calculates the cost

Please help in Java:

You need to use a Circle (for the flower bed) and a Rectangle (for the yard).

This program calculates 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 consists of the length and width of the yard and the radius of the flower bed (all double and all in feet). The cost of fencing (a constant) is $2.50 per foot and the cost of sod is $1.50 per square foot (another constant). Fencing can only be purchased in one foot sections, and sod can only be purchased by the square foot. (Remember to use ceil)

If you use this input: length 6.2, width 3.4, radius 1.2 Then cost of fence is $50, cost of sod is $25.5, total cost is $75.5

This is what I have so far:

public static class Rectangle{

private double length;

private double width;

public void setLength(double l){

length=l;

}

public void setWidth(double w){

width=w;

}

public double areaRectangle(){

return length*width;

}

}

public static class Circle{

private double radius;

public Circle(){

radius=0.0;

}

public Circle(double r){

radius=r;

}

public void setRadius(double r){

radius=r;

}

public double areaCircle(){

return Math.PI*radius*radius;

}

}

public static void main(String[] args) {

//declare Scanner

Scanner scnr =new Scanner (System.in);

//prompt user for length,width,radius

System.out.println("Please enter the length of the yard: ");

double length = scnr.nextDouble();

System.out.println("Please enter the width of the yard: ");

double width = scnr.nextDouble();

System.out.println("Please enter the radius of the flower bed: ");

double radius = scnr.nextDouble();

//System.out.println(calc(length,width,radius));

}

public static double calc (int a, int b, int c, double areaCircle, double areaRectangle){

double fCost = 2.50;

double sCost = 1.50;

/*declare pi

//double pi = 3.14159;

//calc area of circle and rectangle

double area = a * b;

double areaofCircle = Math.pow(c, 2) * pi;*/

//calc fence cost

fCost = Math.ceil(fCost * ( 2 * a) + (2 * b));

//calc sod cost

sCost = Math.ceil(sCost * (areaRectangle - areaCircle));

//calc total cost

double tCost = sCost + fCost;

//results

//System.out.println("The cost of the fence is: " + fCost);

//System.out.println("The cost of sod is: " + sCost);

//System.out.println("The total cost is: " + tCost);

return tCost;

}

}

Thanks!!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!