Skip to main content

Develop a program to draw any 2 of the following shapes: a) Cone b) Cylinder c) Cube


a.  Cone

import java.applet.*;
import java.awt.*;
public class Cone extends Applet
{
public void paint(Graphics g)
{
g.drawOval(80,280,320,100);
g.drawLine(240,50,82,320);
g.drawLine(240,50,398,320);
g.drawLine(240,330,398,330);
g.drawLine(240,50,240,330);
g.drawString("Radius",260,360);
g.drawString("Height",246,255);
g.drawString("Slant Height",340,210);
g.drawString("Cone",220,420);
}
}
/*
<applet code="Cone.class" height=500 width=700>
</applet>
*/









b.      Cylinder

import java.applet.*;
import java.awt.*;
public class Cylinder extends Applet
{
public void paint(Graphics g)
{
g.drawString("Cylinder",80,50);
g.drawOval(50,60,100,50);
g.drawLine(50,80,50,200);
g.drawLine(150,80,150,200);
g.drawOval(50,180,100,50);
}
}
/*
<applet code="Cylinder.class"
width=300 height=300>
</applet>
*/














c.       Cube

import java.applet.*;
import java.awt.*;
public class Cube extends Applet
{
public void paint(Graphics g)
{
g.drawString("Cube",95,110);
g.drawRect(80,10,50,50);
g.drawRect(95,25,50,50);
g.drawLine(80,10,95,25);
g.drawLine(130,10,145,25);
g.drawLine(80,60,95,75);
g.drawLine(130,60,145,75);
}
}
/*
<applet code="Cube.class" width=300 height=300>
</applet>
*/













Comments

Popular posts from this blog

Program to calculate the room area and volume to illustrate the concept of single inheritance.

CODE: class Roomarea   { protected double l, b; Roomarea(double len, double br) { l=len; b=br; } void putdata() { System.out.println("Area of Room: "+(l*b)); } } class Roomvol extends Roomarea   { double h; Roomvol(double len, double br, double he) { super(len, br); h=he;   } void putdata() { super.putdata(); System.out.println("Volume of Room: "+(l*b*h)); } } public class EXP18Q4 { public static void main(String[] args) { Roomvol r1 = new Roomvol(10, 20, 10); r1.putdata();   } }

Define an exception called ‘NotMatchexception’ that is thrown when a string is not equal to ‘India’. Write a java program that uses this exception.

Code: import java.util.Scanner; class NotMatchException extends Exception {   public NotMatchException (String str)   {     System.out.println(str);   } } public class StringExc {    public static void main(String[] args)    {      Scanner scan = new Scanner(System.in);      System.out.print("Enter the string : ");      String input = scan.nextLine();      try      {        if(input.equalsIgnoreCase("India"))          System.out.println("String matched !!!");        else          throw new NotMatchException ("String not matched !!!");     }     catch (NotMatchException s)     {       System.out.println(s);     }   } } Output:

Develop a program using control loops in applets.

Code: import java.awt.*; import java.applet.*; public class Control extends Applet {      public void paint(Graphics g)      {      for(int i=1;i<=4;i++)     {          if(i%2==0)         {            g.fillOval(90,i*50+10,50,50);           g.setColor(Color.black);        }        else       {          g.fillOval(90,i*50+10,50,50);          g.setColor(Color.red);       }    }   } } /* <applet code=Control width=300 height=300> </applet> */ Output: