import javax.swing.*; import java.awt.*; class PieChart extends Chart { float total = 0; public PieChart(int[] data) { super(data); //total up all the data so we can compute pie slices later for (int i=0; i< data.length; i++) { total+=data[i]; } } public void setData(int[] data) { super.setData(data); for (int i=0; i< data.length; i++) total+=data[i]; } public void draw(Graphics g) { float startangle=0, angle=0; for (int i=0; i< data.length; i++) { angle = (360f*data[i])/total; g.setColor(new Color((float)Math.random(),(float)Math.random(),(float)Math.random())); g.fillArc(0,0, width,height, (int)Math.floor(startangle),(int)Math.ceil(angle)); startangle += angle; } } }