Blog Page 2

Write a Java applet that draws a circle divided in 6 equal parts

/*Write a Java applet that draws a circle divided in 6 equal parts.*/ import java.awt.*; import java.applet.*; /* <applet code="A.class" width=400 height=450></applet> */ public class A extends Applet { public void paint(Graphics g) { /*g.setColor(Color.magenta); g.drawOval(50,10,220,220); g.drawOval(70,30,180,180); g.drawOval(90,50,140,140); g.drawOval(110,70,100,100); g.drawOval(1300,90,60,60); g.drawOval(150,110,20,20);*/ g.setColor(Color.magenta); g.fillArc(50,50,10,10,5,60); g.setColor(Color.black); g.fillArc(60,100,10,10,65,120); g.setColor(Color.yellow); g.fillArc(110,150,10,10,125,180); g.setColor(Color.green); g.fillArc(160,200,10,10,185,240); g.setColor(Color.blue); g.fillArc(210,250,10,10,245,300); g.setColor(Color.red); g.fillArc(260,300,10,10,305,360); } }

Write a java program that creates two threads using Runnable interface. One thread should...

/*Write a java program that creates two threads using Runnable interface. One thread should display “Thread 1” at every 1000 Milliseconds and other should display “Thread 2” at every 3000 milliseconds.*/ //thread sleep ...

Write a Java applet that draws a circle centered in the center of the...

/*. Write a Java applet that draws a circle centered in the center of the applet and filled with random color.*/ import java.awt.*; import java.applet.*; /* &lt;applet code=&quot;A.class&quot; width=400 height=450&gt;&lt;/applet&gt; */ public class A extends Applet { public void paint(Graphics g) { g.setColor(Color.magenta); g.fillOval(160,150,100,100); } }

Write a program to display the sum of digits of given numbers with exception...

/*Write a program to display the sum of digits of given numbers with exception handling.*/ import java.io.*; import javax.swing.JOptionPane; class A { public void set(int a,int b,int c) { ...

Define User Define Function (UDF) Exception which calculate the sqaure oaf value.

/*Define UDF Exception which calculate the sqaure oaf value.*/ import javax.swing.JOptionPane; class myexception extends Exception { public myexception() { } } class square { public void sq(int r) throws myexception { int sqr; sqr=r*r; try { if(sqr<100) { System.out.println("less than 100"+sqr); } else { throw new myexception(); } } catch(myexception e) { System.out.println("more than 100"+e); } } } class ass4_14 { public static void main(String args) throws...

Write a java program using Wrapper class.

/*Write a java program using Wrapper class.*/ import java.lang.*; import javax.swing.JOptionPane; public class A { public static void main(String args) { int v; v=Integer.parseInt(JOptionPane.showInputDialog(null,"Enter int")); System.out.println("Int is : "+v); Integer i=new Integer(v); System.out.println("Integer object is : "+i); String s=i.toString(); System.out.println("String object is : "+s); } }

Write a java program using StringBuffer Class and its methods.

/*Write a java program using String Buffer Class and its methods.*/ import java.lang.*; import javax.swing.JOptionPane; public class ass4_12 { public static void main(String args) { char ch; String n1; n1=JOptionPane.showInputDialog(null,"Enter string"); System.out.println("Normal string is : "+n1); StringBuffer name=new StringBuffer(n1); System.out.println(name.capacity()); name.replace(3,5,"java"); System.out.println("Replace name is : "+name); name.setCharAt(3, 'L'); System.out.println("Char at...

Write a program to calculate arithmetic mean in the supperclass and standard deviation in...

/*Write a program to calculate arithmetic mean in the supperclass and standard deviation in the subclass.*/ import javax.swing.JOptionPane; import java.util.*; class arithmeticmean { public void am() { int n, i, sum=0, armean,a; a=Integer.parseInt(JOptionPane.showInputDialog(null,"enter a")); ...

Write a class with a method to find their area of a rectangle. Create...

/*Write a class with a method to find their area of a rectangle. Create a subclass to find the volume of a rectangular shaped box.*/ import javax.swing.JOptionPane; import javax.swing.JOptionPane; class area_r { int length,breadth,area,height; public void get() { length=Integer.parseInt(JOptionPane.showInputDialog(null,&quot;Enter length&quot;)); breadth=Integer.parseInt(JOptionPane.showInputDialog(null,&quot;Enter breadth&quot;)); height=Integer.parseInt(JOptionPane.showInputDialog(null,&quot;Enter height&quot;)); } public void...

Consider an employee class, which contains fields such as name and designation. And a...

/* Consider an employee class, which contains fields such as name and designation. And a subclass, which contains a field salary. Write a program for inheriting this relation.*/ import javax.swing.JOptionPane; class inheritance { String designation; String name; public void get() { designation=JOptionPane.showInputDialog(null,"Enter designation"); name=JOptionPane.showInputDialog(null,"Enter name"); } } public...