Starting from:
$18.99

$12.99

Graphics Description Solution

Write a Java program that inputs sales amounts from five regions of a company and displays a pie chart as a percentage of sales.

Implementation:

Write the following classes:

class PieChart

Write a class PieChart that extends JFrame and provides the following:

·       Five private int variables for holding sales amounts from five regions: North, South, East, West, and Midwest.

·       A public constructor with five parameters that initializes the sales amounts for the five regions.

·       The method paint() that overrides the paint method in the parent class.  In the paint method, convert the sales amounts into percentages and display them as a pie chart as shown below.  Also show a legend at the bottom of the pie chart.

class TestPieChart

Write a class TestPieChart that contains the method main().  In the main method, provide the following:

·       Prompt the user to input sales amounts for the five regions.

·       Create a PieChart object and pass it the sales amounts of the five regions.

·       Set the size of the PieChart object to 500,500.

·       Set the PieChart object to be visible.

Implementation

In the class PieChart that extends JFrame, provide the paint method as shown below. In the paint method, use the Graphics object to do the drawing.

public void paint (Graphics g)

{

}

Test Data

Use the following test data in millions of dollars:

North: 20

South: 25

East: 15

West: 30

Midwest 10

 

More products