UNIVERSITY OF EDUCATION, WINNEBA
FACULTY OF SCIENCE EDUCATION
DEPARTMENT OF MATHEMATICS EDUCATION
COURSE CODE: ICTD 351
COURSE TITLE: INTRODUCTION TO PROGRAMMING FOR THE MATHEMATICS
TEACHER
CODES FOR CUBE AND CYLINDER
import java.awt.*;
import java.applet.*;
public class CubeandCylinder extends Applet
public void init()
//set the background color to cyan
setBackground(Color.cyan);
}
public void paint(Graphics g)
//set the size of the drawing area
setSize(800,600);
//CYLINDER
//Draw vertical lines showing the sides of the cylinder
g.drawLine(100,100,100,400);//left side of a cylinder
g.drawLine(200,100,200,400);//right side of a cylinder
//Draw the top base of the cylinder
g.drawArc(100,70,100,70,180,180);//top semi-circle
//Draw the bottom base of the cylinder
g.drawArc(100,370,100,70,180,180);//bottom semi-circle
//Draw the connecting arc for both ends of the cylinder
g.drawArc(100,70,100,70,0,180);//top circle completion
g.drawArc(100,370,100,70,0,180);//bottom circle completion
//CUBE
//Draw rectangles showing faces of a cube
g.drawRect(500,100,200,200);//the front face of cube
g.drawRect(450,200,200,200);//the back face of cube
//Drawing lines to connect corners to form three-dimensional shape of a cube
g.drawLine(500,100,450,200);//connect top left corners
g.drawLine(500,300,450,400);//connect down left corners
g.drawLine(700,100,650,200);//connect down right corners
g.drawLine(700,300,650,400);//connect top right corners