Java File 2021
Java File 2021
Java File 2021
2021
JAVA
LAB FILE
Semester: - 3rd
import java.util.Scanner;
num = in.nextInt();
do {
double a,c;
Scanner sc=new Scanner(System.in);
System.out.println("Enter Fahrenheit temperature");
a=sc.nextDouble();
System.out.println("Celsius temperature is = "+celsius(a));
}
static double celsius(double f)
{
return (f-32)*5/9;
}
case 2:
int sub;
sub = x - y;
System.out.println("SUBTRACTION Result : "+sub);
break;
case 3:
int mul;
mul = x * y;
System.out.println("MULTIPLICATION Result : "+mul);
break;
case 4:
float div;
div = (float) x / y;
System.out.print("DIVISION Result : "+div);
break;
case 5:
int mod;
mod = x % y;
System.out.println("MOD Result : "+mod);
break;
case 6:
System.out.println("Operation EXIT");
System.exit(0);
}
}
}
class ComplexNumber {
int real, image;
public ComplexNumber(int r, int i)
{
this.real = r;
this.image = i;
}
int i=0;
Scanner sc=new Scanner(System.in);
System.out.println("Enter a character : ");
char ch=sc.next( ).charAt(0);
switch(ch)
{
case 'a' :
case 'e' :
case 'i' :
case 'o' :
case 'u' :
case 'A' :
case 'E' :
case 'I' :
case 'O' :
case 'U' :i++;
}
if(i==1)
System.out.println("Entered character "+ch+" is Vowel");
else
if((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z'))
System.out.println("Entered character "+ch+" is
Consonent");
else
System.out.println("Not an alphabet");
armean = sum/n;
WAP to calculate the total marks of student and find the result using Swing.*
package javaSchool;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
Simple()
setSize(400,500);
setTitle("STUDENT MARKS");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(null);
JButton btn = new JButton("PERCENTAGE");
btn.addActionListener(this);
lblPrinciple.setBounds(50,20,600,20);
lblTime.setBounds(50,50,60,20);
lblRate.setBounds(50,80,60,20);
lblResult.setBounds(50,110,600,20);
lblResul.setBounds(50,130,700,20);
lblResu.setBounds(50,150,800,20);
lblRes.setBounds(50,180,900,20);
lblRe.setBounds(50,200,900,20);
txtPrinciple.setBounds(150,20,100,20);
txtTime.setBounds(150,50,100,20);
txtRate.setBounds(150,80,100,20);
txtResult.setBounds(150,110,100,20);
txtResul.setBounds(150,130,100,20);
txtResu.setBounds(150,150,100,20);
txtRes.setBounds(150,180,100,20);
txtRe.setBounds(150,200,100,20);
btn.setBounds(50,230,200,20);
add(lblPrinciple);
add(lblTime);
add(lblRate);
add(lblResult);
add(lblResul);
add(lblResu);
add(lblRes);
add(lblRe);
add(txtPrinciple);
add(txtTime);
add(txtRate);
add(txtResult);
add(txtResul);
add(txtResu);
add(txtRes);
add(txtRe);
add(btn);
setVisible(true);
int p,t,r;
float res;
p = Integer.parseInt(txtResult.getText());
t = Integer.parseInt(txtResul.getText());
r = Integer.parseInt(txtResu.getText());
res=(p+t+r)/3;
txtRes.setText(String.valueOf(res));
if(res>=50)
{ txtRe.setText(String.valueOf("Pass"));
else
txtRe.setText(String.valueOf("Fail"));
}}
{
new Simple();
import java.awt.event.*;
Calculator()
l1.setBounds(50,100,100,20);
l2.setBounds(50,140,100,20);
l3.setBounds(50,180,100,20);
t1.setBounds(200,100,100,20);
t2.setBounds(200,140,100,20);
t3.setBounds(200,180,100,20);
b1.setBounds(50,250,50,20);
b2.setBounds(110,250,50,20);
b3.setBounds(170,250,50,20);
b4.setBounds(230,250,50,20);
f.add(l1);
f.add(l2);
f.add(l3);
f.add(t1);
f.add(t2);
f.add(t3);
f.add(b1);
f.add(b2);
f.add(b3);
f.add(b4);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
f.setLayout(null);
f.setVisible(true);
f.setSize(400,350);
float n1=Integer.parseInt(t1.getText());
float n2=Integer.parseInt(t2.getText());
if(e.getSource()==b1)
t3.setText(String.valueOf(n1+n2));
if(e.getSource()==b2)
{
t3.setText(String.valueOf(n1-n2));
if(e.getSource()==b3)
t3.setText(String.valueOf(n1*n2));
if(e.getSource()==b4)
t3.setText(String.valueOf(n1/n2));
}}
{new Calculator();}}
import java.awt.*;
import java.awt.event.*;
public class Simple extends JFrame implements ActionListener
{
Simple()
{
setSize(400,500);
setTitle("Simple Intrest");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(null);
lblPrinciple.setBounds(50,20,60,20);
lblTime.setBounds(50,50,60,20);
lblRate.setBounds(50,80,60,20);
lblResult.setBounds(50,110,60,20);
txtPrinciple.setBounds(150,20,100,20);
txtTime.setBounds(150,50,100,20);
txtRate.setBounds(150,80,100,20);
txtResult.setBounds(150,110,100,20);
btn.setBounds(150,140,100,20);
add(lblPrinciple);
add(lblTime);
add(lblRate);
add(lblResult);
add(txtPrinciple);
add(txtTime);
add(txtRate);
add(txtResult);
add(btn);
setVisible(true);
}