Java Assigment
Java Assigment
ASSIGMENT-1
class Ex1
{
System.out.println("Bhavin Modi");
System.out.print("Ankleshwar");
}
}
ASSIGMENT-2
/**
1 2 3 1 2 3 = 1 4 9
4 5 0 * 1 2 3 = 4 10 0
6 7 8 1 2 3 = 6 14 24.
*/
import java.io.*;
class arr2mul
{
public static void main(String args[])
{
int i=0,j=0;
DataInputStream in = new
DataInputStream(System.in);
try
{
int n[][] = new int[3][3];
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
System.out.print("Enter n[" + i + "][" + j + "]: ");
n[i][j] = Integer.parseInt(in.readLine());
}
}
System.out.println();
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
System.out.print("Enter m[" + i + "][" + j + "]: ");
m[i][j] = Integer.parseInt(in.readLine());
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
mul[i][j] = n[i][j] * m[i][j];
}
}
Bhavin Modi Page 3
Java Assignment
System.out.println();
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
System.out.println();
}
}
catch (Exception e){}
ASSIGMENT-3
/*
import java.io.*;
import java.lang.*;
class fun
{
static float area(float x,float y)
{
return (x * y);
}
}
class rect
{
public static void main(String args[])
{
DataInputStream in = new
DataInputStream(System.in);
float l=0,b=0;
try
{
System.out.flush();
System.out.print("Enter Length: ");
l = Float.valueOf(in.readLine());
b = Float.valueOf(in.readLine());
}
catch (Exception e)
{
System.out.print("IO Error");
System.out.println();
ASSIGMENT-4
/*
class Hardware
char ch;
System.out.flush();
try
{
switch(ch =(char)System.in.read())
{
case 'F':
case 'f':
System.out.print("Floppy price is 15 Rs.");
break;
case 'C':
case 'c':
case 'P':
case 'p':
default:
System.out.print("Wrong choice");
}
catch (Exception e)
{
System.out.print("I/O Error");
}
}
}
ASSIGMENT-5
/*
Write a menu driven an Application program.
import java.io.*;
int n = 0;
void disp()
{
System.out.println();
}
void pn(int x)
n = x;
if ( n > 0)
System.out.print("Number is Positive");
else
System.out.print("Number is Negative");
void oe(int x)
{
n = x;
if ((n%2) == 1)
System.out.print("Number is Odd");
else
System.out.print("Number is Even");
}
void prime(int x)
{
int i=0,c=0;
n = x;
for(i=1;i<=n;i++)
{
if (n%i == 0)
c++;
}
if (c==0)
Bhavin Modi Page 13
Java Assignment
else
System.out.print("Not primary no");
}
void arms(int x)
{
n = x;
int a,b,c,sum=0;
a = n/100;
b = (n-(a*100))/10;
c = (n-(a*100))-(b*10);
if (sum == n)
else
System.out.print("Not Armstrong no");
void fibo(int x)
{
n = x;
int n1=1,n2=0,sum=0;
System.out.print("Fibonacci series is ");
while(n>0)
{
sum = n1+n2;
if (x==sum)
System.out.print("fibo");
n1 = n2;
n2 = sum;
n--;
System.out.print(sum + " ");
}
}
void exit()
{
System.out.print("Exit");
}
Bhavin Modi Page 15
Java Assignment
class Menu1
{
DataInputStream in = new
DataInputStream(System.in);
do
d1.disp();
System.out.print("Select your choice: ");
int ch = Integer.parseInt(in.readLine());
try
int n = Integer.parseInt(in.readLine());
switch(ch)
{
case 1:
d1.pn(n);
break;
case 2:
d1.oe(n);
break;
case 3:
d1.prime(n);
break;
case 5:
d1.arms(n);
break;
case 6:
d1.fibo(n);
break;
case 7:
Bhavin Modi Page 17
Java Assignment
d1.exit();
break;
default:
System.out.print("Wrong choice");
}
}
catch (Exception e)
{
System.out.print("I/O Error");
}
System.out.println();
ASSIGMENT-6
/**
*/
import java.io.*;
{
void get()
}
}
void get()
{
System.out.println("Car Maker is Honda");
}
void setprice(int x)
class car
DataInputStream in = new
DataInputStream(System.in);
System.out.print("Enter Car Price: ");
int cp = Integer.parseInt(in.readLine());
m.setprice(cp);
h.get();
h.setprice(cp);
}
ASSIGNMENT-7
/**
*/
import java.io.*;
class square
{
int height=0,width=0,surfaceArea=0;
square(int x,int y)
{
height=x;
width=y;
}
int sfa()
{
surfaceArea=height * width;
return surfaceArea;
}
}
int depth=0;
Cube(int x,int y,int z)
{
super(x,y);
depth=z;
int sfa()
{
class surfacearea
{
public static void main(String args[])
{
int h=0,w=0,d=0;
DataInputStream in = new
DataInputStream(System.in);
try
{
System.out.print("Enter height: ");
h = Integer.parseInt(in.readLine());
}
catch (Exception e){}
ASSIGNMENT-8
/**
class cmdvi
{
int invalid=0,valid=0,n;
for(int i=0;i<args.length;i++)
{
try
{
n = Integer.parseInt(args[i]);
}
catch(Exception e)
{
invalid++;
continue;
}
valid++;
}
}
ASSIGNMENT-9
Bhavin Modi Page 26
Java Assignment
/**
class ascending
{
public static void main(String args[])
{
int i=0,j=0,swap=0;
DataInputStream in = new
DataInputStream(System.in);
try
{
int n[] = new int[10];
for(i=0;i<10;i++)
{
System.out.print("Enter n[" + i + "]: ");
n[i] = Integer.parseInt(in.readLine());
}
System.out.println();
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
{
n[i] = n[j];
n[j] = swap;
}
}
for(i=0;i<10;i++)
{
System.out.print(n[i] + " ");
}
}
}
ASSIGNMENT-10
/**
for example.
1 2 3
------------
1| 1 2 3
2| 2 4 6
3| 3 6 9
Note: use command-line arguments(R C)
*/
class multitable
{
public static void main(String args[])
{
int i=0,j=0;
for(i=0;i<3;i++)
{
r[i]=Integer.parseInt(args[i]);
}
for(j=0;i<6;i++,j++)
{
c[j]=Integer.parseInt(args[i]);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
m[i][j] = r[i] * c[j];
}
System.out.print(" ");
for(i=0;i<3;i++)
{
System.out.print(" ------");
System.out.println();
for(i=0;i<3;i++)
{
System.out.print(c[i] + "| ");
for(j=0;j<3;j++)
{
Bhavin Modi Page 31
Java Assignment
}
System.out.println();
}
}
ASSIGNMENT-11
/**
*/
import java.io.*;
import java.lang.*;
class fun
{
System.out.print(s.charAt(i));
}
void sort(String s)
{
char s2[] = new char[s.length()];
for(i=0;i<s.length();i++)
{
Bhavin Modi Page 33
Java Assignment
s2[i] = s.charAt(i);
for(i=0;i<s.length();i++)
{
for(j=i+1;j<s.length();j++)
{
if(s2[j].compareTo(s2[i]) < 0)
{
temp = s2[i];
s2[i] = s2[j];
s2[j] = temp;
}
}
System.out.print(s2);
void uc(String s)
{
Bhavin Modi Page 34
Java Assignment
void lc(String s)
{
void exit()
{
System.out.println("Exit");
}
}
class strfun
DataInputStream in = new
DataInputStream(System.in);
int ch;
fun f = new fun();
System.out.println("1.Reverse a string");
System.out.println("2.Sorting a string");
System.out.println("5.Exit");
System.out.println();
System.out.print("Select your choice: ");
try
{
System.out.flush();
ch = Integer.parseInt(in.readLine());
s = in.readLine();
switch(ch)
{
case 1:
f.rev(s);
break;
case 2:
f.sort(s);
break;
case 3:
f.lc(s);
break;
case 4:
f.uc(s);
break;
case 5:
f.exit();
break;
default:
Bhavin Modi Page 37
Java Assignment
System.out.print("Wrong choice");
}
}
catch (Exception e)
{
System.out.print("I/O Error");
}
}
}
ASSIGNMENT-12
/**
You are given a sting str ="sardar patel university".
*/
import java.io.*;
import java.lang.*;
class fun
{
void len()
{
void rep()
{
void uc()
void ext()
void exit()
{
System.out.println("Exit");
}
class strfun
DataInputStream in = new
DataInputStream(System.in);
System.out.println();
System.out.println("e. Exit");
System.out.println();
try
char ch;
switch(ch = (char) System.in.read())
case 'a':
f.len();
break;
case 'b':
f.rep();
break;
case 'c':
f.uc();
break;
case 'd':
f.ext();
break;
case 'e':
f.exit();
break;
default:
System.out.print("Wrong choice");
}
catch (Exception e)
{
System.out.print("I/O Error");
}
}
}
ASSIGNMENT-13
/**
*/
class search
int c = args[0].length(),n;
char ch;
try
{
for( int i=0;i<c;i++)
{
ch = str.charAt(i);
else
System.out.print (ch);
}
catch(Exception e)
{
System.out.print("IO Error");
}
}
Bhavin Modi Page 44
Java Assignment
ASSIGNMENT-14
/**
*/
class fun
{
void max(int a,int b)
{
if(a>b)
if(a>b)
if(a>b)
System.out.println("\'"+a+"\'"+ " is greater");
else
class cmdmax
{
public static void main(String args[])
{
fun f = new fun();
Bhavin Modi Page 46
Java Assignment
try
if(args[0].indexOf('.')>=0 &&
args[0].indexOf('.')<=32000)
{
double t=Double.parseDouble(args[0]);
double t1=Double.parseDouble(args[1]);
f.max(t,t1);
else
{
int s=Integer.parseInt(args[0]);
int s1=Integer.parseInt(args[1]);
f.max(s,s1);
}
}
catch(NumberFormatException e)
{
char c=args[0].charAt(0);
char c2=args[1].charAt(0);
f.max(c,c2);
}
}
ASSIGNMENT-15
/**
- Average of numbers
- Maximum of numbers
- Minimum of numbers
- Exit
*/
import java.io.*;
class operation
{
DataInputStream in = new
DataInputStream(System.in);
System.out.println();
System.out.println("1. Display numbers entered");
System.out.println("6. Exit");
System.out.println();
int ch = Integer.parseInt(in.readLine());
System.out.println();
switch(ch)
{
case 1:
f.disp();
break;
case 2:
f.sum();
break;
case 3:
f.avg();
break;
case 4:
f.max();
break;
Bhavin Modi Page 50
Java Assignment
case 5:
f.min();
break;
case 6:
f.exit();
break;
default:
System.out.print("Wrong choice");
}
}
}
class read
{
DataInputStream in = new
DataInputStream(System.in);
{
try
for(int i=0;i<10;i++)
{
System.out.print("Enter a[" + (i+1) + "]: ");
a[i] = Integer.parseInt(in.readLine());
}
}
catch(Exception e){}
fun()
{
super();
}
int s=0;
void disp()
Bhavin Modi Page 52
Java Assignment
System.out.print("Array is ");
}
}
void sum()
{
}
System.out.print("Sum of Array is " + s);
void avg()
{
for (int i=0;i<10;i++)
Bhavin Modi Page 53
Java Assignment
s += a[i];
}
System.out.print("Average of Array is " + (s/10));
}
void max()
{
int m = a[0];
for (int i=1;i<10;i++)
{
if (m < a[i])
m = a[i];
}
void min()
{
int m = a[9];
{
if (m > a[i])
m = a[i];
}
void exit()
System.out.print("Exit");
}
}
ASSIGNMENT-16
/**
import java.io.*;
class election
{
DataInputStream in = new
DataInputStream(System.in);
int i,n,count=0,spoilt=0;
n = Integer.parseInt(in.readLine());
System.out.println();
a[i] = Integer.parseInt(in.readLine());
count++;
else
{
spoilt++;
}
ASSIENMENT-17
/**
*/
import java.io.*;
import java.lang.*;
class count
DataInputStream in = new
DataInputStream(System.in);
String s = new String();
char ch;
int c=0;
ch = (char) System.in.read();
for(int i=0;i<s.length();i++)
{
if (ch == s.charAt(i))
c++;
}
System.out.println();
}
}
ASSIGNMENT-18(1)
import java.io.*;
import java.lang.*;
class info
{
int no;
String name;
{
no = n;
name = nm;
void display()
{
System.out.println("Student No: " + no );
}
}
class stud
{
Bhavin Modi Page 60
Java Assignment
DataInputStream in = new
DataInputStream(System.in);
int std_no;
String std_name;
try
{
for(int i=0;i<2;i++)
{
std_no = Integer.parseInt(in.readLine());
std_name = in.readLine();
System.out.println();
st[i].getdata(std_no,std_name);
}
}
catch (Exception e){}
for(int i=0;i<2;i++)
{
st[i].display();
}
}
}
ASSIGNMENT-18(2)
/**
Write a menu driven an Application program to do
following.
Member variable:
std_no,std_name,std_sub1,std_sub2,std_sub3,total,per
*/
import java.io.*;
import java.lang.*;
class info
{
int no,sub1,sub2,sub3;
float total,per;
String name;
no = n;
name = s;
sub1 = s1;
sub2 = s2;
sub3 = s3;
System.out.print("New Entry");
}
void result(int n)
{
if(no == n)
{
total = sub1 + sub2 + sub3;
per = total / 3;
System.out.print("Result calculated");
}
else
{
}
}
void display(int n)
{
Bhavin Modi Page 64
Java Assignment
if ( no == n)
{
System.out.println("Student No: " + no);
System.out.println("Student Name: " + name);
System.out.println("---------------------------");
System.out.println("Student Subject1: " + sub1);
System.out.println("---------------------------");
System.out.println("total: " + total);
System.out.println("per: " + per);
}
else
{
void del(int n)
{
if(no == n)
{
Bhavin Modi Page 65
Java Assignment
no = '\0';
System.out.print("Entry Deleted");
}
else
{
System.out.print("std_no not exist");
}
}
class student
DataInputStream in = new
DataInputStream(System.in);
int std_no,std_sub1,std_sub2,std_sub3;
String std_name;
int c = 0,i,j;
do
{
System.out.println();
System.out.println("6. Exit");
System.out.println();
System.out.println();
switch(ch)
{
case 1:
{
System.out.print("Student No: ");
std_no = Integer.parseInt(in.readLine());
std_name = in.readLine();
std_sub1 = Integer.parseInt(in.readLine());
std_sub2 = Integer.parseInt(in.readLine());
std_sub3 = Integer.parseInt(in.readLine());
st[c].data(std_no,std_name,std_sub1,std_sub2,std_sub3)
;
c++;
break;
}
case 2:
{
System.out.print("Student No: ");
std_no = Integer.parseInt(in.readLine());
System.out.println();
for(i=0;i<c;i++)
{
st[i].result(std_no);
break;
}
case 3:
{
System.out.print("Student No: ");
std_no = Integer.parseInt(in.readLine());
System.out.println();
for(i=0;i<c;i++)
{
st[i].display(std_no);
}
break;
}
case 4:
{
System.out.print("Student No: ");
std_no = Integer.parseInt(in.readLine());
System.out.println();
for(i=0;i<c;i++)
{
st[i].del(std_no);
}
break;
}
default:
System.out.print("Wrong choice");
}
Bhavin Modi Page 70
Java Assignment
System.out.println("\n");
s = in.readLine();
}while ((s.charAt(0) == 'Y') || (s.charAt(0) == 'y'));
/*
class info
int no;
String name;
no = n;
name = nm;
void display()
{
System.out.println("Student No: " + no );
System.out.println("Student Name: " + name);
}
}
class stud
{
DataInputStream in = new
DataInputStream(System.in);
int std_no;
String std_name;
try
for(int i=0;i<2;i++)
{
System.out.print("Student No: ");
std_no = Integer.parseInt(in.readLine());
System.out.println();
st[i].getdata(std_no,std_name);
}
}
for(int i=0;i<2;i++)
{
st[i].display();
}
}
Bhavin Modi Page 73
Java Assignment
*/
ASSIGNMENT-19
/**
Define a class baby with the following attributes.
1. xname
2. date of birth
*/
import java.io.*;
class babyobject
int d,m,y,beg,polio;
babyobject()
{
DataInputStream in = new
DataInputStream(System.in);
try
System.out.println("Date of birth");
y = Integer.parseInt(in.readLine());
}
catch (Exception e){}
beg = d + 60 ;
polio = d + 45;
{
m = m + 1;
if(m == 2 && y%4 == 0)
{
beg = beg - 28;
polio = polio - 28;
m = m + 1;
}
else
{
beg = beg - 30;
}
if (m >= 12)
{
m = 1;
y = y + 1;
System.out.println();
}
}
class baby
ASSIGNMENT-20
/**
If basic<=5000 Then
If basic>=15000 Then
*/
import java.io.*;
class employee
DataInputStream in = new
DataInputStream(System.in);
int c = 0,i,j;
do
{
System.out.println();
System.out.print("emp_no: ");
emp_no[c] = Integer.parseInt(in.readLine());
System.out.print("emp_name: ");
emp_name[c] = in.readLine();
System.out.print("basic: ");
basic[c] = Integer.parseInt(in.readLine());
System.out.print("Des: ");
Des[c] = in.readLine();
c++;
System.out.println();
do
{
System.out.println();
System.out.print("emp_no: ");
j = Integer.parseInt(in.readLine());
for(i=0;i<c;i++)
{
if( emp_no[i] == j)
{
System.out.println("emp_no: EMP" +
emp_no[i]);
System.out.println("emp_name: " +
emp_name[i]);
else
{
}
}
System.out.println();
class Payslip
void netpay(float x)
{
float basic,da,hra,net;
basic = x;
da = (basic * 3)/100;
}
{
hra = (basic * 75)/1000;
da = (basic * 5)/100;
}
else
{
hra = (basic * 10)/100;
}
ASSIGNMENT-21
/*
*/
import java.lang.*;
class mulce
{
int b = 5;
try
{
}
// catch (Exception e)
// {
// System.out.print("IOException");
// }
catch (ArithmeticException e)
{
System.out.print("Division by Zero");
}
catch (ArrayIndexOutOfBoundsException e)
{
System.out.print("Array index error");
}
}
}
ASSIGNMENT-22
/**
Write a program that displays an invoice of several
items.
Use two classes. The first class contains the item data
and methods
import java.io.*;
import java.lang.*;
class item
{
DataInputStream in = new
DataInputStream(System.in);
String name = new String();
int quantity = 0;
name = in.readLine();
System.out.print("Quantity : ");
quantity = Integer.parseInt(in.readLine());
System.out.print("Price : ");
price = Float.valueOf(in.readLine()).floatValue();
i.get(name,quantity,price);
i.set();
}
}
class invoice
{
String n = new String();
int q;
float p,tc;
{
n = x;
q = y;
p = z;
Bhavin Modi Page 88
Java Assignment
void set()
{
System.out.println();
ASSIGNMENT-23
/**
Data members:
name, number, total no of books
Bhavin Modi Page 89
Java Assignment
Methods:
import java.io.*;
class book
{
no = x;
s = y;
tno = z;
}
void display()
{
System.out.println();
class library
{
DataInputStream in = new
DataInputStream(System.in);
String bname = new String();
int btno;
book b = new book();
bno = in.readLine();
System.out.print("Book Name : ");
bname = in.readLine();
btno = Integer.parseInt(in.readLine());
b.get(bno,bname,btno);
b.display();
}
}
ASSIGNMENT-24
/**
class circle
{
second s = new second(1.5,2.5,3.5);
s.disp();
class first
{
double x,y;
first(double a, double b)
{
x = a;
y = b;
}
void disp()
{
System.out.print(x + y);
super(a,b);
z = c;
}
void disp()
{
System.out.print(z);
}
ASSIGNMENT-25
/**
*/
import java.io.*;
class Time
{
DataInputStream in = new
DataInputStream(System.in);
for(i=0;i<2;i++)
{
System.out.print("Enter Hour: ");
hh[i] = Integer.parseInt(in.readLine());
ss[i] = Integer.parseInt(in.readLine());
}
for(i=0;i<2;i++)
{
h += hh[i];
m += mm[i];
s += ss[i];
if (m>60)
h++;
if (s>60)
m++;
Bhavin Modi Page 96
Java Assignment
if (h>24)
{
h=0;
m=0;
s=0;
}
System.out.print("Date: " + h + ":" + m + ":" + s);
}
}
ASSIGNMENT-26
/**
interface newshape
{
void draw();
{
public void draw()
{
int radius = 12;
System.out.print("Radius of circle is " + radius);
}
}
class shape
{
public static void main(String args[])
{
newshape nc = new circle();
nc.draw();
}
}
ASSIGNMENT-27
/**
*/
import java.io.*;
class DIOS
dos.writeInt(1999);
dos.writeDouble(375.85);
dos.writeBoolean(false);
dos.writeChar('X');
dos.close();
fos.close();
System.out.println(dis.readInt());
System.out.println(dis.readDouble());
System.out.println(dis.readBoolean());
System.out.println(dis.readChar());
dis.close();
fis.close();
}
}
ASSIGNMENT-29
import java.applet.*;
import java.awt.*;
/*
{
public void paint(Graphics g)
{
g.drawString("Hello World",10,100);
}
}
ASSIGNMENT-30
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
/*
*/
{
String msg=" ";
setBackground(Color.yellow);
setForeground(Color.blue);
addMouseMotionListener(this);
mouseY = me.getY();
msg = "JAVA";
repaint();
}
{
g.drawString(msg,mouseX,mouseY);
}
ASSIGNMENT-31
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
TextField n1,n2,r;
Choice op;
Button ok;
{
setBackground(Color.yellow);
setForeground(Color.red);
n1 = new TextField(10);
n2 = new TextField(10);
r = new TextField(10);
op = new Choice();
add(fno);
add(n1);
add(sno);
add(n2);
op.add("+");
op.add("-");
op.add("*");
op.add("/");
add(op);
add(res);
add(r);
Bhavin Modi Page 105
Java Assignment
ok = new Button("OK");
add(ok);
ok.addActionListener(this);
}
{
String str = ae.getActionCommand();
a = Integer.parseInt(n1.getText());
b = Integer.parseInt(n2.getText());
m = op.getSelectedItem();
if (str.equals("OK"))
if (m == "+")
ans = a + b;
else if (m == "-")
ans = a - b;
Bhavin Modi Page 106
Java Assignment
else if (m == "*")
ans = a * b;
else if (m == "/")
ans = a / b;
repaint();
}
{
r.setText(ans+"");
}
}
ASSIGNMENT-32(1)
import java.util.*;
class calendardemo
{
String months[] =
{"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep",
"Oct","Nov","Dec"};
Calendar calendar = Calendar.getInstance();
System.out.print("Date:" + date);
System.out.println("\nTime:" +
calendar.get(Calendar.HOUR));
// System.out.print("Date:" +
months[calendar.get(Calendar.MONTH)] + " " +
calendar.get(Calendar.DATE) + " " +
calendar.get(Calendar.YEAR));
// System.out.println("Time:" +
calendar.get(Calendar.HOUR) + ":" +
calendar.get(Calendar.MINUTE) + ":" +
calendar.get(Calendar.SECOND));
ASSIGNMENT-32(2)
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
{
Label l1;
TextField t1;
t1 = new TextField(10);
add(l1);
add(t1);
t1.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
repaint();
}
public void paint(Graphics g)
{
g.drawString("Date:" + t1.getText(),10,100);
}
}
ASSIGNMENT-33
import java.applet.*;
import java.awt.*;
/*
<applet code="good" width=200 height=200>
Bhavin Modi Page 110
Java Assignment
</applet>
*/
{
g.drawString('Time()',10,100);
}
}
ASSIGNMENT-34
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
{
Label l1,l2;
TextField t1,t2;
{
l1 = new Label("Email ID:");
t1 = new TextField(10);
l2 = new Label("Password:");
t2 = new TextField(10);
t2.setEchoChar('*');
add(l1);
add(t1);
add(l2);
add(t2);
t2.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
repaint();
}
public void paint(Graphics g)
{
g.drawString("Email ID: " + t1.getText(),10,100);
g.drawString("Password: " + t2.getText(),10,150);
}
}
ASSIGNMENT-37
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
TextField t1,t2;
Choice cty;
String msg= "";
int m1,m2;
{
l1 = new Label("Enter money to convert:");
t1 = new TextField(10);
cty.add("U.S.");
cty.add("U.K.");
cty.add("Ausralia");
add(l1);
add(t1);
add(cty);
add(l2);
add(t2);
cty.addItemListener(this);
}
public void actionPerformed(ActionEvent ae)
repaint();
}
msg = cty.getSelectedItem();
m1 = Integer.parseInt(t1.getText());
if (msg == "U.S.")
m2 = m1 * 37;
else if(msg == "U.K.")
m2 = m1 * 36;
else if(msg == "Ausralia")
m2 = m1 * 35;
else
m2 = 0;
repaint();
}
public void paint(Graphics g)
{
// g.drawString("money : " + t1.getText(),10,100);
t2.setText(String.valueOf(m2));
}
}
ASSIGNMENT-38
Bhavin Modi Page 116
Java Assignment
/*
*/
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
/*
</applet>
*/
{
String msg=" ";
Button click;
// setBackground(Color.blue);
// setForeground(Color.red);
add(click);
addMouseListener(this);
{
msg = "mouse clicked";
repaint();
repaint();
}
*/
{
g.drawString(msg,10,100);
}
}
Bhavin Modi Page 119
Java Assignment
ASSIGNMENT-39
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
c = new Choice();
c.add("Red");
c.add("Green");
c.add("Blue");
add(c);
c.addItemListener(this);
}
{
repaint();
}
msg = c.getSelectedItem();
g.drawString(msg,10,100);
if (msg == "Red")
setBackground(Color.red);
if (msg == "Green")
setBackground(Color.green);
Bhavin Modi Page 121
Java Assignment
if (msg == "Blue")
setBackground(Color.blue);
}
}
ASSIGNMENT-40
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
{
showStatus("Key Down");
}
public void keyReleased(KeyEvent ke)
{
showStatus("Key Up");
}
public void keyTyped(KeyEvent ke)
{
msg += ke.getKeyChar();
repaint();
}
public void paint(Graphics g)
{
g.drawString(msg,10,100);
Bhavin Modi Page 123
Java Assignment
}
ASSIGNMENT-41
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
Checkbox m,l,p;
TextField ch;
// setBackground(Color.green);
// setForeground(Color.red);
m = new Checkbox("Music",cbg,true);
l = new Checkbox("Listening",cbg,false);
p = new Checkbox("Painting",cbg,false);
add(m);
add(l);
add(p);
m.addItemListener(this);
l.addItemListener(this);
p.addItemListener(this);
ch = new TextField(12);
add(ch);
ch.addActionListener(this);
}
Bhavin Modi Page 125
Java Assignment
repaint();
}
// g.drawString(msg,10,100);
ch.setText(cbg.getSelectedCheckboxGroup().getLabel());
ASSIGNMENT-42
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
setBackground(Color.cyan);
setForeground(Color.red);
m = new Checkbox("Male",cbg,true);
f = new Checkbox("Female",cbg,false);
add(m);
add(f);
m.addItemListener(this);
f.addItemListener(this);
}
{
msg = "Male " + m.getState();
g.drawString(msg,10,100);
g.drawString(msg,10,150);
}
}
ASSIGNMENT-43
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
{
String msg=" ";
// setBackground(Color.yellow);
// setForeground(Color.red);
c.add("Anand");
c.add("Nadiad");
Bhavin Modi Page 130
Java Assignment
c.add("Baroda");
add(sno);
add(no);
add(snm);
add(nm);
Bhavin Modi Page 131
Java Assignment
add(add);
add(ad);
add(pin);
add(pc);
add(city);
add(c);
add(state);
add(s);
add(gen);
add(m);
add(f);
add(area);
add(com);
add(eng);
add(store);
add(text);
store.addActionListener(this);
}
{
repaint();
}
g.drawString(msg,300,100);
}
ASSIGNMENT-44
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
{
// setBackground(Color.yellow);
// setForeground(Color.red);
Label sno = new Label("Sno");
Label snm = new Label("Snm");
c.add("Nadiad");
c.add("Baroda");
s.add("Dehli");
s.add("MP");
add(sno);
add(no);
add(snm);
add(nm);
add(add);
add(ad);
add(pin);
add(pc);
Bhavin Modi Page 136
Java Assignment
add(city);
add(c);
add(state);
add(s);
add(gen);
add(m);
add(f);
add(area);
add(com);
add(eng);
add(store);
add(text);
store.addActionListener(this);
{
String str = ae.getActionCommand();
if (str.equals("Store"))
msg = "You pressed";
Bhavin Modi Page 137
Java Assignment
repaint();
g.drawString(msg,300,100);
}
}