Hi, i have the following code in Java as you can see there are a lot of code repetition. I want to know how i can loop this part of code instead of writing it each time?
g.setColor( Color.black );
g.fillArc( 110, 80, 300, 300, 0, valint[0] );
g.drawString("BMW", 420, 80);
Rectangle2D BMW = new Rectangle2D.Double(400, 70, 10, 10);
gd.draw(BMW) ; gd.fill(BMW) ;
g.setColor( Color.red );
g.fillArc( 110, 80, 300, 300, valint[0], valint[1] );
g.drawString("Mercedes", 420, 100);
Rectangle2D mercedes = new Rectangle2D.Double(400, 90, 10, 10);
gd.draw(mercedes) ; gd.fill(mercedes) ;
g.setColor( Color.blue );
g.fillArc( 110, 80, 300, 300, valint[0]+valint[1], valint[2] );
g.drawString("Honda: 120", 420, 120);
Rectangle2D honda = new Rectangle2D.Double(400, 110, 10, 10);
gd.draw(honda) ; gd.fill(honda) ;
g.setColor( Color.green );
g.fillArc( 110, 80, 300, 300, valint[0]+valint[1]+valint[2], valint[3] );
g.drawString("Toyota: 130", 420, 140);
Rectangle2D toyota = new Rectangle2D.Double(400, 130, 10, 10);
gd.draw(toyota) ; gd.fill(toyota) ;
g.setColor( Color.white );
g.fillArc( 110, 80, 300, 300, valint[0]+valint[1]+valint[2]+valint[3], valint[4] );
g.drawString("Nissan: 150", 420, 160);
Rectangle2D nissan = new Rectangle2D.Double(400, 150, 10, 10);
gd.draw(nissan) ; gd.fill(nissan) ;