Skip to content

Commit 5e6951f

Browse files
authored
Add files via upload
1 parent e63c3a0 commit 5e6951f

31 files changed

+1000
-53
lines changed

BtnDemo1.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//To demonstrate addition function using Button
2+
import java.awt.*;
3+
import java.awt.event.*;
4+
import java.applet.*;
5+
/*<applet code="BtnDemo1" width=100 height=100></applet>*/
6+
public class BtnDemo1 extends Applet implements ActionListener
7+
{
8+
TextField t1,t2,t3;
9+
Button b;
10+
public void init()
11+
{
12+
t1=new TextField(10);
13+
t2=new TextField(10);
14+
t3=new TextField(10);
15+
b=new Button("Add");
16+
17+
add(t1);
18+
add(t2);
19+
add(t3);
20+
add(b);
21+
22+
b.addActionListener(this); //registration
23+
}
24+
public void actionPerformed(ActionEvent ae)
25+
{
26+
int n1=Integer.parseInt(t1.getText());
27+
int n2=Integer.parseInt(t2.getText());
28+
int rs=n1+n2;
29+
t3.setText(" " +rs);
30+
}
31+
}

BtnDemo2.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//To calculate factorial using Button
2+
import java.awt.*;
3+
import java.awt.event.*;
4+
import java.applet.*;
5+
/*<applet code="BtnDemo2" width=100 height=100></applet>*/
6+
public class BtnDemo2 extends Applet implements ActionListener
7+
{
8+
TextField t1,t2;
9+
Button b;
10+
public void init()
11+
{
12+
t1=new TextField(10);
13+
t2=new TextField(10);
14+
b=new Button("Factorial");
15+
16+
add(t1);
17+
add(t2);
18+
add(b);
19+
20+
b.addActionListener(this);
21+
}
22+
public void actionPerformed(ActionEvent ae)
23+
{
24+
int n=Integer.parseInt(t1.getText());
25+
int fact=1;
26+
for(int i=1;i<=n;i++)
27+
{
28+
fact=fact*i;
29+
}
30+
t2.setText(" "+fact);
31+
}
32+
}

BtnDemo3.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//To find greatest of two numbers using button
2+
import java.awt.*;
3+
import java.awt.event.*;
4+
import java.applet.*;
5+
/*<applet code="BtnDemo3" width=100 height=100></applet>*/
6+
public class BtnDemo3 extends Applet implements ActionListener
7+
{
8+
Label l1,l2,l3;
9+
TextField t1,t2,t3;
10+
Button b;
11+
public void init()
12+
{
13+
l1=new Label("Number 1");
14+
l2=new Label("Number 2");
15+
l3=new Label("Greatest of two");
16+
t1=new TextField(10);
17+
t2=new TextField(10);
18+
t3=new TextField(10);
19+
b=new Button("Find greatest");
20+
add(l1);
21+
add(t1);
22+
add(l2);
23+
add(t2);
24+
add(l3);
25+
add(t3);
26+
add(b);
27+
b.addActionListener(this);
28+
}
29+
public void actionPerformed(ActionEvent ae)
30+
{
31+
int n1=Integer.parseInt(t1.getText());
32+
int n2=Integer.parseInt(t2.getText());
33+
int gr_no;
34+
if(n1>n2)
35+
gr_no=n1;
36+
else
37+
gr_no=n2;
38+
t3.setText(""+gr_no);
39+
}
40+
}

BtnDemo4.class

1.35 KB
Binary file not shown.

BtnDemo4.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//To setbackground color (0-255 values for red, green and blue)using Button
2+
import java.awt.*;
3+
import java.awt.event.*;
4+
import java.applet.*;
5+
/*<applet code="BtnDemo4" height=100 width=100></applet>*/
6+
public class BtnDemo4 extends Applet implements ActionListener
7+
{
8+
Label l1,l2,l3;
9+
TextField t1,t2,t3;
10+
Button b;
11+
public void init()
12+
{
13+
l1=new Label("Red");
14+
l2=new Label("Green");
15+
l3=new Label("Blue");
16+
t1=new TextField(5);
17+
t2=new TextField(5);
18+
t3=new TextField(5);
19+
b=new Button("Show resultant color");
20+
add(l1);
21+
add(t1);
22+
add(l2);
23+
add(t2);
24+
add(l3);
25+
add(t3);
26+
add(b);
27+
b.addActionListener(this);
28+
}
29+
public void actionPerformed(ActionEvent ae)
30+
{
31+
int r=Integer.parseInt(t1.getText());
32+
int g=Integer.parseInt(t2.getText());
33+
int b=Integer.parseInt(t3.getText());
34+
Color c=new Color(r,g,b);
35+
setBackground(c);
36+
}
37+
}

BtnDemo5.java

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//To find greatest of three numbers using button
2+
import java.awt.*;
3+
import java.awt.event.*;
4+
import java.applet.*;
5+
/*<applet code="BtnDemo5" width=100 height=100></applet>*/
6+
public class BtnDemo5 extends Applet implements ActionListener
7+
{
8+
Label l1,l2,l3,l4;
9+
TextField t1,t2,t3,t4;
10+
Button b;
11+
public void init()
12+
{
13+
l1=new Label("Number 1");
14+
l2=new Label("Number 2");
15+
l3=new Label("Number 3");
16+
l4=new Label("Greatest of three");
17+
t1=new TextField(10);
18+
t2=new TextField(10);
19+
t3=new TextField(10);
20+
t4=new TextField(10);
21+
b=new Button("Find greatest");
22+
add(l1);
23+
add(t1);
24+
add(l2);
25+
add(t2);
26+
add(l3);
27+
add(t3);
28+
add(l4);
29+
add(t4);
30+
add(b);
31+
b.addActionListener(this);
32+
}
33+
public void actionPerformed(ActionEvent ae)
34+
{
35+
int n1=Integer.parseInt(t1.getText());
36+
int n2=Integer.parseInt(t2.getText());
37+
int n3=Integer.parseInt(t3.getText());
38+
int gr_no;
39+
if(n1>n2)
40+
{
41+
if(n1>n3)
42+
gr_no=n1;
43+
else
44+
gr_no=n3;
45+
}
46+
else
47+
{
48+
if(n2>n3)
49+
gr_no=n2;
50+
else
51+
gr_no=n3;
52+
}
53+
t4.setText(""+gr_no);
54+
}
55+
}

ChoiceDemo.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import java.awt.*;
2+
import java.awt.event.*;
3+
import java.applet.*;
4+
/*<applet code="ChoiceDemo" width=100 height=100></applet>*/
5+
public class ChoiceDemo extends Applet implements ItemListener
6+
{
7+
Label l1,l2,l3;
8+
TextField t1,t2,t3;
9+
Choice c;
10+
int rs;
11+
public void init()
12+
{
13+
c=new Choice();
14+
c.add("Addition");
15+
c.add("Subtraction");
16+
c.add("Multiplication");
17+
c.add("Division");
18+
c.add("Modulo Division");
19+
l1=new Label("Number 1");
20+
l2=new Label("Number 2");
21+
l3=new Label("Result");
22+
t1=new TextField(10);
23+
t2=new TextField(10);
24+
t3=new TextField(10);
25+
add(l1); add(t1);
26+
add(l2); add(t2);
27+
add(c);
28+
add(l3); add(t3);
29+
c.addItemListener(this);
30+
}
31+
public void itemStateChanged(ItemEvent ie)
32+
{
33+
int n1=Integer.parseInt(t1.getText());
34+
int n2=Integer.parseInt(t2.getText());
35+
rs=0;
36+
int idx=c.getSelectedIndex();
37+
if(idx==0)
38+
rs=n1+n2;
39+
else if(idx==1)
40+
rs=n1-n2;
41+
else if(idx==2)
42+
rs=n1*n2;
43+
else if(idx==3)
44+
rs=n1/n2;
45+
else if(idx==4)
46+
rs=n1%n2;
47+
48+
t3.setText(""+rs);
49+
}
50+
}

Circle.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//To calculate area and circumference of circle
2+
import java.util.*;
3+
class Circle
4+
{
5+
public static void main(String args[])
6+
{
7+
final float PI=3.14f;
8+
float r,a,c;
9+
System.out.print("Enter radius: ");
10+
Scanner sc=new Scanner(System.in);
11+
r=sc.nextFloat();
12+
a=PI*r*r;
13+
c=2*PI*r;
14+
System.out.println("Area: "+a);
15+
System.out.println("Circumference: "+c);
16+
}
17+
}
18+

CompareStrings.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class CompareStrings
2+
{
3+
public static void main(String args[])
4+
{
5+
String s1="core";
6+
String s2="java";
7+
String s3="core";
8+
System.out.println("Result 1: "+s1.compareTo(s2));
9+
System.out.println("Result 2: "+s1.compareTo(s3));
10+
}
11+
}

ConditionalOp1.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//To find greatest of two numbers using conditional operator.
2+
import java.lang.*;
3+
class ConditionalOp1
4+
{
5+
public static void main(String args[])
6+
{
7+
int a=Integer.parseInt(args[0]);
8+
int b=Integer.parseInt(args[1]);
9+
int max=a>b ? a : b;
10+
System.out.println("Greatest= "+max);
11+
}
12+
}

Cricket.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//To find cricket score and run rate
2+
import java.lang.*;
3+
import java.util.*;
4+
class Cricket
5+
{
6+
public static void main(String args[])
7+
{
8+
Scanner sc=new Scanner(System.in);
9+
System.out.println("ODI MATCH SCORECARD");
10+
System.out.println("Enter the name of team batting first: ");
11+
String team1=sc.next();
12+
int score1=0;
13+
float rr1=0;
14+
for(int i=1;i<=11;i++) //Assuming that all 11 players batted
15+
{
16+
System.out.print("Enter player name: ");
17+
String nm1=sc.next();
18+
System.out.print("Enter runs scored by player: ");
19+
int runs1=sc.nextInt();
20+
score1=runs1+score1;
21+
rr1=(float)((score1))/50;
22+
}
23+
System.out.println("Total runs: "+score1);
24+
System.out.println("Run rate: "+rr1);
25+
System.out.println(team1+" scored "+score1+" runs at run rate "+rr1);
26+
27+
}
28+
}
29+
30+
31+
32+
33+
34+
35+
36+
37+
38+
39+
40+
41+
42+
43+
44+
45+
46+
47+
48+
49+
50+
51+

0 commit comments

Comments
 (0)