Music BGM

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 39

STUDENT MARK STATEMENT

import java.util.Scanner;

class Mark

Scanner s=new Scanner(System.in);

int regno;

String name;

int m []=new int[3];

double avg,total;

void getData()

System.out.println("Enter the register number");

regno=s.nextInt();

System.out.println("Enter the student name");

name=s.next();

System.out.println("Enter the student's 3 marks");

for(int i=0;i<3;i++)

m[i]=s.nextInt();

void calculate()

total=0;

for(int i=0;i<3;i++)

total +=m[i];

avg=total /3;
}

void putData()

System.out.println("student register number:"+regno);

System.out.println("student name:"+name);

for(int i=0;i<3;i++)

System.out.println("student mark 1:"+m[i]);

System.out.println("Total:"+total);

System.out.println("Average:"+avg);

class Student

public static void main(String[] args)

System.out.println("Student mark statement");

Mark m1=new Mark();

m1.getData();

m1.calculate();

m1.putData();

STUDENTGRADE

import java.util.Scanner;

class Mark

Scanner s=new Scanner(System.in);

int regno;
String name;

int m []=new int[3];

double avg,total;

char grade;

void getData()

System.out.println("Enter the register number");

regno=s.nextInt();

System.out.println("Enter the student name");

name=s.next();

System.out.println("Enter the student's 3 marks");

for(int i=0;i<3;i++)

m[i]=s.nextInt();

void calculate()

total=0;

for(int i=0;i<3;i++)

total +=m[i];

avg=total/3;

void grade()

//double percentage=((double)(total)/maxmark)*100;

if(avg>=90)
{

grade='O';

else if (avg>=80 &&avg<=89)

grade='A';

else if(avg>=70 && avg<=79)

grade='B';

else if (avg>=60 && avg<=69)

grade='C';

else if(avg>=50 && avg<=59)

grade='D';

else

grade='F';

void putData()

System.out.println("Student register number:"+regno);


System.out.println("Student name:"+name);

for(int i=0;i<3;i++)

System.out.println("Student mark 1:"+m[i]);

System.out.println("Total:"+total);

System.out.println("Average:"+avg);

System.out.println("Grade:"+grade);

class StudentGrade

public static void main(String []args)

System.out.println("Student mark Grade");

Mark m1=new Mark();

m1.getData();

m1.calculate();

m1.grade();

m1.putData();

TEXTILES

import java.io.*;

class Textiles

public static void main(String [] args)

int no,price,total,ch;
try

DataInputStream in=new DataInputStream(System.in);

do

System.out.println("1. saree section");

System.out.println("2. kids wear");

System.out.println("3. Exit");

System.out.println("Enter your choice:");

ch=Integer.parseInt(in.readLine());

switch(ch)

case 1 :

System.out.println(" Saree section");

System.out.println("Enter a number of saree");

no=Integer.parseInt(in.readLine());

System.out.println("one saree price:");

price=Integer.parseInt(in.readLine());

total=no*price;

System.out.println("Totalprice:"+total);

break;

case 2 :

System.out.println("kids wear");

System.out.println("Enter Number of kids wear");

no=Integer.parseInt(in.readLine());

System.out.println("one kids wear price");

price=Integer.parseInt(in.readLine());
total=no*price;

System.out.println("Total price:"+total);

case 3 :

System.out.println("Exit");

while(ch!=3);

catch (Exception e)

{}

OUT PUT:

1.saree section

2.kidswear

3.exit

enter your choice:

saree section

enter a number of saree

one saree price:299

total price:598

1. saree section

2.kids wear

3. exit

enter your choice


2

kids wear

enter number of kidswear

one kids wear price

50

total price:150

1. saree section

2. kids wear

3. exit

enter your choice:

exit

DISPLAYING

import java.io.*;

class Displaying

public static void main(String args[])

System.out.println("screen Display");

for(int i=1;i<=9;i++)

for(int j=1;j<=i;j++)

System.out.print(" ");

System.out.print(i);

System.out.print("\n");
}

System.out.println("screen Display Done");

OUT PUT:

Screen Displaying

22

333

4444

55555

666666

7777777

88888888

999999999

Screen displaying is done

TESTMYEXCEPTION

import java.io.*;

import java.lang.Exception;

class MyException extends Exception

MyException(String Message)

super(Message);

public class TestMyException


{

public static void main(String args[])

int x=5,y=1000;

try

float z=(float)x/(float)y;

if(z<0.01)

throw new MyException("Number is too small");

catch(MyException e)

System.out.println("caught MyException");

System.out.println(e.getMessage());

finally

System.out.println("I am always here");

OUT PUT:

caught myexception

number is too small

i am always here
THREAD METHOD

import java.io.*;

class A extends Thread

public void run()

for(int i=1;i<=5;i++)

if(i==1)yield();

System.out.println("\t From Thread A:i="+i);

System.out.println("exit from A");

class B extends Thread

public void run()

for(int j=1;j<=5;j++)

System.out.println("\t from thread B"+j);

if(j==3)stop();

System.out.println("Exit fromB");

class C extends Thread


{

public void run()

for(int k=1;k<=5;k++)

System.out.println("\t from Thread C");

if(k==1)

try

sleep(1000);

catch(Exception e)

System.out.println(" Exit from c");

class ThreadMethod

public static void main (String [] Args)

A a=new A ();

B b=new B();

C c=new C();

System.out.println("Start thread A");

a.start();
System.out.println("Start thread B");

b.start();

System.out.println("Start thread C");

c.start();

System.out.println("End of main thread");

} OUT PUT:

Start thread A

start thread B

from threade A:i=1

from threade A:i=2

from threade A:i=3

from threade A:i=4

from threade A:i=5

exit from B

from thread B1

from thread B2

frome thread B3

start thread C

end of main thread

from thread C

from thread C

from thread C

from thread C

from thread C

exit from C
EVENT HANDLING

import java.awt.Graphics;

import java.awt.Frame;

import java.awt.event.WindowEvent;

import java.awt.event.WindowListener;

class Myframe extends Frame implements WindowListener

String txt1="";

String txt2="";

String txt3="";

Myframe(String title)

super(title);

setSize(200,150);

addWindowListener(this);

public void windowActivated(WindowEvent we)

txt1="Window activated";

public void windowClosed(WindowEvent we)

;
}

public void windowClosing(WindowEvent we)

System.exit(0);

public void windowDeactivated(WindowEvent we)

txt2="Window dectivated";

public void windowDeiconified (WindowEvent we)

txt3="Window deiconified";

public void windowIconified (WindowEvent we)

public void windowOpened(WindowEvent we)

public void paint(Graphics gp)

{
gp.drawRoundRect(15, 25, 90, 20, 10, 5);

gp.drawString("Window Event", 20, 40);

gp.drawString("Click x in the window to close", 20, 60);

gp.drawString(txt1, 20, 80);

gp.drawString(txt2, 20, 100);

gp.drawString(txt3, 20, 120);

public class Winevent

public static void main(String args [])

Myframe mframe=new Myframe("Window Events");

mframe.setVisible(true);

Out Put:

Click x in the window to close


Window activated

Window deactivated

Window deiconified

KEYEVENT HANDLING

import java.applet.Applet;

import java.awt.Graphics;

import java.awt.event.KeyEvent;

import java.awt.event.KeyListener;

public class Kie extends Applet implements KeyListener

String txt="";

String txt1="";

String txt2="";

String txt3="";

int kcode;

char ch;

int drawnnumber;

public void init()

addKeyListener(this);

requestFocus();

public void keyTyped(KeyEvent ke)

ch=ke.getKeyChar();
txt1 +=ch;

if (txt1.length()>25)

txt1="";

txt="Key Typed";

repaint();

public void keyPressed(KeyEvent ke)

kcode=ke.getKeyCode();

if (kcode == ke.VK_F1)

txt2="You have typed F1 key";

if (kcode == ke.VK_SHIFT)

txt3="You have typed shift key";

txt="Key Pressed";

repaint();

public void keyReleased(KeyEvent ke)

txt="Key Released";

repaint();

public void paint(Graphics gp)

gp.drawString(txt, 20, 20);

gp.drawString(txt1, 20, 40);

gp.drawString(txt2, 20, 60);

gp.drawString(txt3, 20,80);
showStatus("Key events");

/*<applet code="Kie.class" width=1000 height=1000></applet>*/

Out put:

Key presed

Key relesed

MOUSE EVENT HANDLING

import java.applet.*;

import java.applet.Applet;

import java.awt.Color;

import java.awt.Graphics;

import java.awt.event.*;

public class Mou1 extends Applet implements MouseListener,MouseMotionListener

String txt="Nothing";

int x=10, y=10;

public void init()


{

addMouseListener(this);

addMouseMotionListener(this);

public void mouseClicked(MouseEvent me)

txt="mouse clicked";

repaint();

public void mouseEntered(MouseEvent me)

txt="mouse Exicted";

repaint();

public void mouseExited(MouseEvent me)

txt="mouse Exited";

repaint();

public void mousePressed(MouseEvent me)

txt="mouse pressed";

setForeground(Color.cyan);

repaint();

public void mouseReleased(MouseEvent me)

{
txt="mouse released";

setForeground(Color.cyan);

repaint();

public void mouseDragged(MouseEvent me)

txt="mouse Dragged";

setForeground(Color.red);

repaint();

public void mouseMoved(MouseEvent me)

txt="mouse Moved";

setForeground(Color.red);

repaint();

public void paint(Graphics gp)

gp.drawString(txt,20,40);

showStatus ("mouse event handling");

/*<applet code="Mou1.java" width=200 height =100></applet>*/


Out Put:

Nothing

Mouse Exited

Mouse Presed

Mouse Dragged

Mouse clicked

Mouse Moved

JAVA APPLET

import java.awt.*;

import java.applet.*;

public class House extends Applet

public void paint(Graphics g)

g.drawLine(500, 40,350,140);

g.drawLine(500, 40,650,140);

g.drawRect(350,140,300,100);

/*<applet code="House.java" width=1000

height=1000></applet>*/
Out put:

ANIMATION AND IMAGES

import java.awt.*;

import java.applet.*;

public class Animation extends Applet

Image picture;

public void init()

picture =getImage(getDocumentBase(),"Rabbit.jpeg");

public void paint(Graphics g)

for(int i=0;i<500;i++)

g.drawImage(picture, i,30, this);

try

Thread.sleep(100);

catch(Exception e)
{}

/*<applet code="Animation.java" width=1000

height=1000></applet>*/

Out Put:

Arithmetic operations using java script


<!DOCTYPE html>

<html>

<head>

<title>Javascript Arithmetic Operators</title>

<script>

// Arithmetic operation Function

function p() {

var a, b,op,c;

var addition, subtraction, multiplication, division, modulus;

// Getting the value form text

// field using DOM

a= document.myform.a.value;
a = parseInt(a)

b = document.myform.b.value;

b = parseInt(b)

op = document.myform.op.value;

op = parseInt(op)

if (op == 1) {

c=a+b

alert(" Addition of A & B is"+c);

else if (op == 2){

c=a-b

alert("Subraction of A & B is"+c);

else if (op == 3){

c=a*b

alert("Multiplication of A & B is"+c);

else if (op == 4){

c=a/b

alert(" Division of A & B is"+c);

else if (op == 5) {

c=a % b

alert(" Modulus of A & B is"+c);


}

</script>

</head>

<body>

<h1>Performing Arithmetic Operations </h1>

<center>

<h1>Arithmetic Operations</h1>

<hr color="Green">

<form name="myform">

<h4>1.Addition </h4>

<h4>2.Subtraction</h4>

<h4>3.Multiplication</h4>

<h4>4.Division </h4>

<h4>5.Modulus</h4>

Enter A value:

<input type="text" name=a value="">

<br><br>
Enter B value:

<input type="text" name=b value="">

<br><br>

Enter Your Choice:

<input type="text" name=op value="">

<br><br>

<input type="button" value="Check" onClick="p()">

<br>

</form>

</center>

</body>

</html>

Out put:

窗体顶端

1.Addition

2.Subtraction

3.Multiplication

4.Division
5.Modulus

Enter A value: 76

Enter B value: 88

Enter Your Choice:1

Addition of A&B is 164

Palindrome
<html>

<head><title> JavaScript Palindrome </title>

</head>

<body>

<!-- Use JavaScript programming code to validate the Palindrome numbers or strings. -->

<script>

function validatePalin(str) {

// get the total length of the words

const len = string.length;

// Use for loop to divide the words into 2 half

for (let i = 0; i < len / 2; i++) {

// validate the first and last characters are same

if (string[i] !== string[len - 1 - i]) {

alert( 'It is not a palindrome');

}
}

alert( 'It is a palindrome');

// accept the string or number from the prompt

const string = prompt('Enter a string or number: ');

const value = validatePalin(string);

console.log(value);

</script>

</body>

</html>

Out Put:

Enter the string or number: Anna

Anna is a palindrome

Prime or not using java script


<!DOCTYPE html>

<html>

<head>

<title>

Check a number is Prime or

not using JavaScript

</title>

<script type="text/javascript">

// Function to check prime number

function p() {

var n, i, flag = true;

// Getting the value form text

// field using DOM

n = document.myform.n.value;

n = parseInt(n)

for(i = 2; i <= n - 1; i++)

if (n % i == 0) {

flag = false;

break;

// Check and display alert message


if (flag == true)

alert(n + " is prime");

else

alert(n + " is not prime");

</script>

</head>

<body>

<center>

<h1>GeeksforGeeks</h1>

<h4>check number is prime or not</h4>

<hr color="Green">

<form name="myform">

Enter the number:

<input type="text" name=n value="">

<br><br>

<input type="button" value="Check" onClick="p()">

<br>

</form>

</center>

</body>
</html>

Out put:

Check the number is prime or not: 7

7 is a prime

Largest number using java script


<!DOCTYPE html>

<html>

<body>

<script>

var myArr = [340, 25, 530, 299];

var max = myArr.reduce(function(a,b){

return (a > b) ? a : b;

});

document.write("Largest number in the array: "+max);

</script>

</body>

</html>
Out put:

Largest number in the array=530

Gui components
import java.awt.*;

import java.applet.*;

public class Application extends Applet

public void paint(Graphics g)

Font f1=new Font("Times new Romen",Font.BOLD,20);

Label l1=new Label("Application form");

Label l2=new Label("Enter Applicant Name:");

TextField t1=new TextField(8);

Font f2=new Font("Times new Romen",Font.BOLD,30);

Label l3=new Label("Enter Nationality");

Checkbox c1=new Checkbox("Indian");

Checkbox c2=new Checkbox("Fone giner");

Label l4=new Label("course to join");

Choice ch1=new Choice();

Button b1=new Button("Submit");

l1.setFont(f1);

add(t1);

add(l1);

add(l2);

add(l3);

add(l4);
add(c1);

add(c2);

add(ch1);

add(b1);

ch1.add("UG");

ch1.add("PG");

setLayout(null);

l1.setBounds(500,20,200,40);

t1.setBounds(500,60,100,20);

l2.setBounds(200,60,200,40);

l3.setBounds(200,100,200,40);

l4.setBounds(200,140,200,40);

c1.setBounds(500,90,200,50);

c2.setBounds(700,90,200,50);

ch1.setBounds(500,140,200,40);

b1.setBounds(500,300,80,40);

/* <applet code="Application.class" width=1000

height=1000></applet>*/

Out Put:

Application form
Enter Applicant name: R.kiruthika

Enter Nationality: Indian Foreign

Course to join : Ug ^

Submit

FILE MANAGEMENT
import java.io.*;

class CopyCharacter

public static void main(String args[])

File inFile=new File("input.txt");

File outFile=new File("output.txt");

FileReader ins=null;

FileWriter outs=null;

try

ins = new FileReader(inFile);

outs = new FileWriter(outFile);

int ch;

while( (ch=ins.read())!=-1)

outs.write(ch);

}
catch(IOException e)

System.out.println(e);

System.exit(- 1);

finally

try

ins.close();

outs.close();

catch (IOException e){}

Out Put:

FLOW LAYOUT DEMO


Import java.awt.*;

Import javax.swing.*;

Public class FlowLayoutDemo

JFrame f;

FlowLayoutDemo()
{

f=new Jframe();

JLabel l1=new Jlabel(“Enter Name”);

JTextField tf1=new JTextField(10);

JButton b1= new JButton(“SUBMIT”);

f.add(l1);

f.add(tf1);

f.add(b1);

f.SetLayout(new Flow Layout(FlowLayout.RIGHT));

f.SetSize(300,300);

f.SetVisible(true);

Public Static void main (String args[])

New FlowLayoutDemo()

Output:

Enter Name SUBMIT

You might also like