Question

In: Computer Science

/** * Chapter 6 * Programming Challenge 1: Area Class * This program demonstrates the Area...

/**
 * Chapter 6
 * Programming Challenge 1: Area Class
 * This program demonstrates the Area class.
 */

public class AreaDemo
{
   public static void main(String[] args)
   {
      // Get the area of a circle with a radius of 20.0.
      System.out.println("The area of a circle with a " +
                         "radius of 20.0 is " + 
                         Area.getArea(20.0));

      // Get the area of a rectangle with a length of 10
      // and a width of 20.
      System.out.println("The area of a rectangle with a " +
                         "length of 10 and a width of 20 is " + 
                         Area.getArea(10, 20));

      // Get the area of a cylinder with a radius of 10.0
      // and a height of 15.0.
      System.out.println("The area of a cylinder with a " +
                         "radius of 10.0 and a height" +
                         "of 15.0 is " + 
                         Area.getArea(10.0, 15.0));
   }
}

Solutions

Expert Solution

SOURCE CODE:

*Please follow the comments to better understand the code.

**Please look at the Screenshot below and use this code to copy-paste.

***The code in the below screenshot is neatly indented for better understanding.

Area class

/* 
This class demonstrates the concept of OVERLOADING methods.
 */
 
public class Area
{
    // only one parameter, CIRCLE
    public static double getArea(double radius)
    {
        return Math.PI * radius * radius;
    }

    // TWO parameters (int,int), it's a RECTANGLE
    public static double getArea(int length, int width)
    {
        return length*width;
    }

    // TWO parameters (double,double), it's a CYLINDER
    public static double getArea(double radius, double height)
    {
        return (2*Math.PI*radius) * (radius + height);
    }
}

====================

AREA DEMO

/**
 * Chapter 6
 * Programming Challenge 1: Area Class
 * This program demonstrates the Area class.
 */

public class AreaDemo
{
    public static void main(String[] args)
    {
        // Get the area of a circle with a radius of 20.0.
        System.out.println("The area of a circle with a " +
                "radius of 20.0 is " +
                Area.getArea(20.0));

        // Get the area of a rectangle with a length of 10
        // and a width of 20.
        System.out.println("The area of a rectangle with a " +
                "length of 10 and a width of 20 is " +
                Area.getArea(10, 20));

        // Get the area of a cylinder with a radius of 10.0
        // and a height of 15.0.
        System.out.println("The area of a cylinder with a " +
                "radius of 10.0 and a height" +
                "of 15.0 is " +
                Area.getArea(10.0, 15.0));
    }
}

===============

OUTPUT:


Related Solutions

1. Chapter 5, Programming Challenge #8, Conversion Program (page 314). Program Name: FinalExamConversion. Write a program...
1. Chapter 5, Programming Challenge #8, Conversion Program (page 314). Program Name: FinalExamConversion. Write a program that asks the user to enter a distance in meters. The program will then present the following menu of selection: 1. Convert to Kilometers 2. Convert to Inches 3. Convert to Feet 4. Quit the Program The program will convert the distance to kilometers, inches or feet, depending on the user’s selection. Write the following methods: • getInput: This method prompts user to enter...
In Programming Challenge 12 of Chapter 3, you were asked to write a program that converts...
In Programming Challenge 12 of Chapter 3, you were asked to write a program that converts a Celsius temperature to Fahrenheit. Modify that program so it uses a loop to display a table of the Celsius temperatures 0–20, and their Fahrenheit equivalents. Display table on screen and it a .txt file. c++
This assignment assumes you have completed Programming Challenge 1 of Chapter 9 ( Employee and ProductionWorker...
This assignment assumes you have completed Programming Challenge 1 of Chapter 9 ( Employee and ProductionWorker Classes). Modify the Employee and ProductionWorker classes so they throw exceptions when the following errors occur: ● The Employee class should throw an exception named InvalidEmployeeNumber when it receives an employee number that is less than 0 or greater than 9999. ● The ProductionWorker class should throw an exception named InvalidShift when it receives an invalid shift. ● The ProductionWorker class should throw an...
Make in c++ this Programming Challenge 1. Design your own linked list class to hold a...
Make in c++ this Programming Challenge 1. Design your own linked list class to hold a series of integers. The class should have member functions for appending, inserting, and deleting nodes. Don’t forget to add a destructor that destroys the list. Demonstrate the class with a driver program. 2. List Print Modify the linked list class you created in Programming Challenge 1 to add a print member function. The function should display all the values in the linked list. Test...
JAVA 1 PROGRAMMING QUESTION In this program you will be writing a class that will contain...
JAVA 1 PROGRAMMING QUESTION In this program you will be writing a class that will contain some methods. These will be regular methods (not static methods), so the class will have to be instantiated in order to use them. The class containing the main method will be provided and you will write the required methods and run the supplied class in order to test those methods. ? Specifications There are two separate files in this program. The class containing the...
Intro C++ Programming Chapter 6 Functions You have been tasked to write a new program for...
Intro C++ Programming Chapter 6 Functions You have been tasked to write a new program for the Research Center's shipping department. The shipping charges for the center are as follows: Weight of Package (in kilograms)                Rate per mile Shipped 2 kg or less                                                      $0.05 Over 2 kg but no more than 6 kg    $0.09 Over 6 kg but not more than 10 kg    $0.12 Over 10 kg    $0.20 Write a function in a program that asks for...
Chapter 8 Programming exercise 6 "Days of each month" Original Exercise: Design a program that displays...
Chapter 8 Programming exercise 6 "Days of each month" Original Exercise: Design a program that displays the number of days in each month. The program’s output should be similar to this: January has 31 days. February has 28 days. March has 31 days. April has 30 days. May has 31 days. June has 30 days. July has 31 days. August has 31 days. September has 30 days. October has 31 days. November has 30 days. December has 31 days. The...
In this programming challenge you are to create two Python programs: randomwrite.py and randomread.py. One program,...
In this programming challenge you are to create two Python programs: randomwrite.py and randomread.py. One program, randomwrite.py, is to write a set of random numbers to a file. The second program, randomread.py, is to read a set of random numbers from a file, counts how many were read, displays the random numbers, and displays the total count of random numbers. Random Number File Writer (randomwrite.py) Create a program called randomwrite.py that writes a series of random integers to a file....
Integer Programming Problem (Chapter 6) A manufacturer can sell product 1 at a price of $30...
Integer Programming Problem (Chapter 6) A manufacturer can sell product 1 at a price of $30 per unit and product 2 at a price of $40 per unit. Three units of raw material and 1.5 labor hours are needed to manufacturer one unit of product 1. Six units of raw material and 2 labor hours are need to manufacture one unit of product 2. The unit variable cost for product 1 is $20, and for product 2 is $20. A...
java from control structures through objects 6th edition, programming challenge 5 on chapter 16 Write a...
java from control structures through objects 6th edition, programming challenge 5 on chapter 16 Write a boolean method that uses recursion to determine whether a string argument is a palindrome. the method should return true if the argument reads the same forward amd backword. Demonstrate the method in a program, use comments in the code for better understanding. there must be a demo class and method class also .. generate javadocs through eclipse compiler. And make a UML diagram with...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT