Question

Java... Write a class that has three overloaded static methods for calculating the areas of the...

Java...

Write a class that has three overloaded static methods for calculating the areas of the
following geometric shapes:

• circles -- area = π*radius^2 (format the answer to have two decimal places)
• rectangles -- area = width * length
• trapezoid -- area = (base1 + base2) * height/2

Because the three methods are to be overloaded, they should each have the same name, but
different parameters (for example, the method to be used with circles should only take
one parameter, the radius of the circle).

Demonstrate the methods in a program that prints out the following areas, each on a
separate line:

• the area of a circle with radius 3
• the area of a rectangle with length 2 and width 4
• the area of a trapezoid with base lengths 3 and 5 and height 5

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Java Program:

class Main {

public static double Area(double radius){

return 3.14*radius*radius;

}

public static double Area(double width, double length){

return width*length;

}

public static double Area(double base1,double base2,double height){

return (base1+base2)*height/2;

}

public static void main(String[] args) {

System.out.println("the area of a circle with radius 3 is "+Area(3));

System.out.println("the area of a rectangle with length 2 and width 4 is "+Area(2,4));

System.out.println("the area of a trapezoid with base lengths 3 and 5 and height 5 is "+Area(3,5,5));

}

}

https://DependentCoarse Services.kunlstudy.repl.run Open JDK Runtime Environment (build 10.0.2+13-Ubuntu-lubuntu.18 .04.4) >

if you like the answer please provide a thumbs up.

Add a comment
Know the answer?
Add Answer to:
Java... Write a class that has three overloaded static methods for calculating the areas of the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Need Help a Intro to Java Programming assignment Design a Area class that has three overloaded...

    Need Help a Intro to Java Programming assignment Design a Area class that has three overloaded static methods areaComputing to calculate the areas of circles, rectangles, and cylinders. Assume that data for circles and cylinders are all doubles and data for rectangles are integers. Code a test program AreaApp by creating at least two objects for each geometric shapes with different hard coded data at your choice for testing.

  • Using Python Write the following well-documented (commented) program. Create a class called Shape that has a...

    Using Python Write the following well-documented (commented) program. Create a class called Shape that has a method for printing the area and the perimeter. Create three classes (Square, Rectangle, and Circle) which inherit from it. Square will have one instance variable for the length. Rectangle will have two instance variables for the width and height. Circle will have one instance variable for the radius. The three classes will have methods for computing the area and perimeter of its corresponding shape....

  • Using C++, Write a program that will provide the user a menu from which the user...

    Using C++, Write a program that will provide the user a menu from which the user may select to calculate the area of one of four geometric shapes: a circle, a rectangle, a triangle, and a trapezoid. You should use the most appropriate SWITCH block for this program. The user will input all data needed to calculate the area. The program should output all data input by the user, the calculated area, and the geometric shape selected. Run this program...

  • C++ Develop a Circle class that, like the Rectangle class above, provides methods to compute perimeter...

    C++ Develop a Circle class that, like the Rectangle class above, provides methods to compute perimeter and area. The Rectangle instance variables are not appropriate for circles; specifically, circles do have corners, and there is no need to specify a width and height. A center point and a radius more naturally describe a circle. Build your Circle class appropriately.

  • (NEED FULL CODE PLEASE)write a java program class to calculate and display the areas of 10 rectan...

    (NEED FULL CODE PLEASE)write a java program class to calculate and display the areas of 10 rectangles using arrays. * input validation sizes must be between 0-50 inches output to be displayed on the screen and send to an output file. *the output must appear in the following format. rectangle length width area 1    2.0    3.0    6.0 2 - - - - 10 display the rectangle with largest area. rectangle1 area= display the rectangle with smallest area. rectangle2 area=

  • In Java Exercise #2: (Java) Design and implement a program (name it ComputeAreas) that defines four...

    In Java Exercise #2: (Java) Design and implement a program (name it ComputeAreas) that defines four methods as follows: Method squareArea (double side) returns the area of a square. Method rectangleArea (double width, double length) returns the area of a rectangle. Method circleArea (double radius) returns the area of a circle. Method triangleArea (double base, double height) returns the area of a triangle. In the main method, test all methods with different input value read from the user. Document your...

  • Menu-driven programs will display the menu options to the user and then prompt them for a...

    Menu-driven programs will display the menu options to the user and then prompt them for a menu choice. This program will display the following menu in the following format: Calculator Options: Calculate the area of a circle Calculate the area of a rectangle Calculate the area of a triangle Calculate the area of a trapezoid Calculate the area of a sphere Exit Enter your choice (1-6) Once the user enters a choice for the menu, the program should use a...

  • Question 4.4: Write an overloaded function of function area with 3 (float) parameters. This function should...

    Question 4.4: Write an overloaded function of function area with 3 (float) parameters. This function should calculate and print out the product of the 3 parameters. Question 4.4: Write the main function to test question 4.1, 4.2, 4.3, 4.4. Your main function should ask if the user want to calculate the area of a rectangle or a circle or a triangle then print out the result accordingly. (Use switch structure). For example: Please enter (r) for rectangle, (t) for triangle,...

  • java language Problem 3: Shape (10 points) (Software Design) Create an abstract class that represents a Shape and contains abstract method: area and perimeter. Create concrete classes: Circle, Rectang...

    java language Problem 3: Shape (10 points) (Software Design) Create an abstract class that represents a Shape and contains abstract method: area and perimeter. Create concrete classes: Circle, Rectangle, Triangle which extend the Shape class and implements the abstract methods. A circle has a radius, a rectangle has width and height, and a triangle has three sides. Software Architecture: The Shape class is the abstract super class and must be instantiated by one of its concrete subclasses: Circle, Rectangle, or...

  • matlab The Homework should be submitted as a script (.m) file Write a script areaMenu that...

    matlab The Homework should be submitted as a script (.m) file Write a script areaMenu that will print a menu consisting of "Cylinder," "Circle," and "Rectangle." It waits for the user to choose from the menu then call the corresponding function of each choice as follows: 1- Cylinder will call the function (cyl) which prompts the user for the radius and height of the cylinder, then calculates and prints area of the cylinder. 2- Circle will call the function (cir)...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT