Question

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


Question 4.2: Write a void function named area with 1 double parameter to calculate the area of circle. You must declare doub
0 0
Add a comment Improve this question Transcribed image text
Answer #1

4.3]

void area(float a,float b,float c)

{

float ar=a*b*c; //calculates area of triangle and store it in ar

System.out.println("The area of triangle is:"+ar); // prints out area of triangle

}

4.4]

import java.io.*;

import java.util.Scanner;

public static void main(String args[])throws IOException

{

Scanner sc = new Scanner(System.in);

System.out.println("please enter (r) for rectangle , (t) for triangle , (c) for circle ");

char s=sc.next();

switch(s)

{

case 'r':

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

double l=sc.nextDouble();

System.out.println("enter the breadth of the rectangle:");

double b=sc.nextDouble();

sc.area(l,b);

break;

case 't':

System.out.println("enter sides of a triangle");

float a=sc.nextFloat();

float b=sc.nextFloat();

float c=sc.nextFloat();

sc.area(a,b,c);

break;

case 'c':

System.out.println("enter radius of circle");

double r=sc.nextDouble();

sc.area(r);

break;

}

}

Add a comment
Know the answer?
Add Answer to:
Question 4.4: Write an overloaded function of function area with 3 (float) parameters. This function should...
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
  • 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...

  • 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)...

  • Using the c++ language 1) Create a function that calculates the area of a circle "circeArea...

    Using the c++ language 1) Create a function that calculates the area of a circle "circeArea ()". The function should take a single float parameter radius and return a float area. 2) Create a function to calculate the area of a rectangle. 3) Creat a function to calculate the area of a triangle when given base and height as parameters provided by the user.

  • Write a program to implement template function on member function name area() which should be able...

    Write a program to implement template function on member function name area() which should be able to find the area of circle, rectangle, triangle and square for both integer and floating point values. 1.Area of Circle 2.Area of Rectangle 3.Area of Triangle 4. Area of Square C++ Languages

  • I am trying to write a Geometry.java program but Dr.Java is giving me errors and I...

    I am trying to write a Geometry.java program but Dr.Java is giving me errors and I dont know what I am doing wrong. import java.util.Scanner; /** This program demonstrates static methods */ public class Geometry { public static void main(String[] args) { int choice; // The user's choice double value = 0; // The method's return value char letter; // The user's Y or N decision double radius; // The radius of the circle double length; // The length of...

  • Project Objectives: To develop ability to write void and value returning methods and to call them...

    Project Objectives: To develop ability to write void and value returning methods and to call them -- Introduction: Methods are commonly used to break a problem down into small manageable pieces. A large task can be broken down into smaller tasks (methods) that contain the details of how to complete that small task. The larger problem is then solved by implementing the smaller tasks (calling the methods) in the correct order. This also allows for efficiencies, since the method can...

  • 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....

  • Write a C program named assignment04.cpp that will ask for and read in a float for...

    Write a C program named assignment04.cpp that will ask for and read in a float for a radius ask for and read in a float for the height each of the following functions will calculate some property of a shape (area, volume, circumference, etc) The functions will accept one or two parameters (radius and/or height) and return the proper calculation. There is no input/output (cin or cout) in the function – just the calculation write the following functions float areaCircle(float...

  • /4 Question An area of square, drea ofa rectangle and triangle can be calculated by using...

    /4 Question An area of square, drea ofa rectangle and triangle can be calculated by using the given formula: sqareaa (renww value from the functioi area is reciabgle-(retrn valwe from the function is area int) ceouatre -D-(return value fromtheneion e s double t and s s formula must be use when the values for the sides of the triangle are whether you want to calculate the area of square or a. b and c are the sides of the triangle...

  • Write a Java application to find the area of 1) rectangle 2) Triangle 3) Circle using...

    Write a Java application to find the area of 1) rectangle 2) Triangle 3) Circle using runtime polymorphism concept. Shape Area rectangle length*width Triangle 0.5*length*width Circle PI*radius*radius. I am confused as to what polymorphism is and would really appreciate some help. This is in Java as well.

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