0% found this document useful (0 votes)
142 views23 pages

Practical File - XII-K JAVA (Geet)

This is a practical file for JAVA class XII practicals if anyone needs it :)

Uploaded by

Geet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
142 views23 pages

Practical File - XII-K JAVA (Geet)

This is a practical file for JAVA class XII practicals if anyone needs it :)

Uploaded by

Geet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 23

DAV PUBLIC SCHOOL, SECTOR-14,

GURUGRAM

INFORMATION
TECHNOLOGY
PRACTICAL FILE
SUBJECT CODE: 802

Submitted By: Geet Mishra


Roll No. : 35
Session: 2024-2025
Class: XII
JAVA
TABLE OF CONTENT

S.NO. PROGRAM TEACHER’S


SIGNATURE

1 Write a Java program to find and print the biggest number from the
given three numbers.

2 Write a Java application to develop a discount calculator (using the


switch statement). Design the form as well.

3 Write a Java application to enter the sales and calculate the incentive of
a salesman depending on the choice of any one option of achievement:
Maximum Sales – 10% of sales, Customer feedback – 8% of sales,
Maximum Customers- 5% of Sales. (Implementing Button Group)

4 Write a Java program to find the average marks and percentage


obtained. Also, find and display the category of the student. (User
Input- marks in 3 subjects)

5 Write a Java program to check whether an input character is a vowel or


consonant (use switch case statement).

6 Write a Java program to check if the given year is a LEAP YEAR.

7 Write a Java program to display sum and product of SQUARES OF EVEN


NUMBERS till a user input number.

8 Write a Java program to display characters A to Z using for loop.

9 Write a Java program to print the MULTIPLICATION TABLE.

10 Write a Java program to print the FACTORIAL of an input number.

11 Write a Java program to print the FIBONACCI SERIES by getting the


input of number of terms in the series.

12 Write a Java program to print number of factors of a number and print


all the factors.

13 Write a Java program to check if given number is prime or not.

14 Write a Java program to generate reverse of a number.

15 Write a Java Program to input Sales figures of a product for 12 months.


Print the maximum and minimum Sales figure.

16 Write a Java program to input names of 10 students. User should be


able to search for a name and the program should display message
accordingly.

17 Write a Java program to calculate Simple Interest using user defined


function.

18 Write a Java program to get a string and perform the basic string
manipulation.

19 Write a Java program to calculate the area and perimeter of a square by


using a class with a constructors and methods.
1) Write a Java program to find and print the biggest number from the
given three numbers.

public class biggest_number


{
public static void main (String[] args) {
int a=10, b=20, c=30;
if (a>b && a> c)
System.out.println(“Largest no. is ” +
Integer.toString(a));

else if (b>a && b> c)


System.out.println(“Largest no. is ” +
Integer.toString(b));

else
System.out.println(“Largest no. is ” +
Integer.toString(c));
}
}

OUTPUT:
Largest no. is 30
2) Write a Java application to develop a discount calculator (using the
switch statement). Design the form as well.
SOURCE CODE:
private void
jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
double FinalAmount=0;
double BillAmount =
Double.parseDouble(jTextField1.getText());
switch(jComboBox1.getSelectedIndex())
{
case 0: FinalAmount=BillAmount; break;
//No Discount for new customer
case 1: FinalAmount=0.90*BillAmount; break;
//10% Discount for silver
case 2: FinalAmount=0.80*BillAmount; break;
//20% Discount for gold
case 3: FinalAmount=0.70*BillAmount; break;
//30% Discount for platinum
default:FinalAmount=BillAmount;
}
jTextField2.setText(Double.toString(FinalAmount));
}

private void
jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}

DESIGN (OUTPUT) :
3) Write a Java application to Enter the Sales and calculate the incentive of
a salesman depending on the choice of any one option of achievement:
Maximum Sales – 10% of sales, Customer feedback – 8% of sales,
Maximum Customers- 5% of Sales. (Implementing Button Group)
SOURCE CODE:
private void
jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
int sales=0;
sales=Integer.parseInt(jTextField1.getText());
double incentive=0.0;
if (jRadioButton1.isSelected())
incentive=0.1;
if (jRadioButton2.isSelected())
incentive=0.08;
if (jRadioButton3.isSelected())
incentive=0.05;
double t=(sales*incentive);
jTextField2.setText(Double.toString (t));
}

private void
jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}

DESIGN (OUTPUT) :
4) Write a Java program to find the average marks and percentage
obtained. Also, find and display the category of the student. (User Input-
marks in 3 subjects)
Percentage is to be calculated according to following criteria
90% and above - O category
80-89% - A category
70-79% - B category
below 70%- C category

import java.util.Scanner;
public class percentage {
public static void main (String[]args)
{
Scanner S=new Scanner(System.in);
int m1, m2, m3;
System.out.println("Enter marks for first subject: ");
m1=S.nextInt();
System.out.println("Enter marks for second subject:
");
m2=S.nextInt();
System.out.println("Enter marks for third subject: ");
m3=S.nextInt();
float p=(m1+m2+m3)/3;
if (p>=90)
System.out.println("Grade O");
else if (p>=80)
System.out.println("Grade A");
else if (p>=70)
System.out.println("Grade B");
else
System.out.println("Grade C");
}
}

OUTPUT:
Enter marks for first subject: 95
Enter marks for second subject: 81
Enter marks for third subject: 45
Grade B
5) Write a Java program to Check whether an input character is a vowel
or consonant (use switch case statement).

import java.util.Scanner;
public class vowel_consonent {
public static void main (String[]args)
{
Scanner S=new Scanner(System.in);
char c=S.next().charAt(0);
char c1=Character.toLowerCase(c);
if (c1>='a' && c1<='z')
{
switch (c1)
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u': System.out.println("Vowel"); break;
default: System.out.println("Consonent");
break;
}
}
else System.out.println("Invalid Value");
}
}

OUTPUT:
Enter a letter:
A
Vowel
6) Write a Java program to check if the given year is a LEAP YEAR.

import java.util.Scanner;
public class leap2 {
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);
System.out.println("Enter The Year: ");
int y=s.nextInt();
if
(y%400==0 || y%100!=0 && y%4==0)
System.out.println("Leap Year");
else
System.out.println("Not Leap Year");
}
}
}

OUTPUT:
Enter The Year:
2016
Leap Year
-----------------
Enter The Year:
2007
Not Leap Year
7) Write a Java program to display sum and product of SQUARES OF
EVEN NUMBERS till a user input number.

import java.util.Scanner;
public class squares {
public static void main (String[]args)
{
Scanner S=new Scanner(System.in);
System.out.println("Enter The Number: ");
int n=S.nextInt();
int s=0, p=1;
int i=2;
while (i<=n);
{
s=s+i*i;
p=p*i*i;
i=i+2;
}
System.out.println(“Sum of squares of even numbers= ” +
s);
System.out.println(“Sum of squares of even numbers=” + p);
}
}

OUTPUT:
Enter The Number: 5
Sum of squares of even numbers= 20
Sum of squares of even numbers= 64
8) Write a Java program to display characters A to Z using for loop.

import java.util.Scanner;
public class char_loop_for {
public static void main (String[]args)
{
Scanner S=new Scanner(System.in);
for (char i='A'; i<='Z'; ++i)
{
System.out.print(i+" ");
}
}
}

OUTPUT:
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
9) Write a Java program to print the MULTIPLICATION TABLE.

import java.util.Scanner;
public class multiplication_5 {
public static void main(String[] args)
{
Scanner s1=new Scanner(System.in);
System.out.println("Enter The Number: ");
int n= s1.nextInt();
System.out.println("Enter number of multiples: ");
int m= s1.nextInt();
int i=1;
while (i<=m)
{
System.out.println(“Multiplication Table= ” +
n*i);
i++;
}
}
}

OUTPUT:
Enter The Number: 5
Enter number of multiples: 10
Multiplication Table=
5
10
15
20
25
30
35
40
45
50
10) Write a Java program to print the FACTORIAL of an input number.

import java.util.Scanner;
public class factorial {
public static void main(String[] args)
{
Scanner S=new Scanner(System.in);
System.out.println("Enter The Number: ");
int n=S.nextInt();
int p=1;
int i=1;
while (i<=n)
{
p=p*i;
i++;
}
System.out.println(“Factorial= ” + p);
}
}
}

OUTPUT:
Enter The Number: 5
Factorial= 120
11) Write a Java program to print the FIBONACCI SERIES by getting the
input of number of terms in the series.

import java.util.Scanner;
public class fibonacci {
public static void main (String[]args)
{
Scanner S=new Scanner(System.in);
System.out.println("Enter First term: ");
int n1=S.nextInt();
System.out.println("Enter Second term: ");
int n2=S.nextInt();
System.out.println("Enter no. of terms: ");
int t=S.nextInt();
System.out.println(n1);
System.out.println(n2);
int i=3, n;
while (i<=t)
{
n=n1+n2;
System.out.println(“Fibonacci Series= ” + n);
n1=n2;
n2=n;
i++;
}
}

OUTPUT:
Enter First term: 1
Enter Second term: 1
Enter no. of terms: 10
Fibonacci Series=
1
1
2
3
5
8
13
21
34
55
12) Write a Java program to print number of factors of a number and print
all the factors.

import java.util.Scanner;
public class factors {
public static void main (String[]args)
{
Scanner S=new Scanner(System.in);
System.out.println("Enter a Number: ");
int n=S.nextInt();
int i=2;
while (i<=n/2)
{
if (n%i==0)
System.out.println(“Factors= ” + i);
i++;
}
}
}

OUTPUT:
Enter a Number: 6
Factors=
2
3
13) Write a Java program to check if given number is prime or not.

import java.util.Scanner;
public class prime
{
public static void main(String[] args) {
System.out.println ("Enter no for factor: ");
Scanner s=new Scanner (System.in);
int n= s.nextInt(), c=0;
if (n==1)
System.out.println ("No entered is 1, i.e, neither
Prime nor Composite enter valid no.");
else if (n<=0)
System.out.println("Enter valid no ");
else
{
for (int i=2;i<=n/2;++i)
{
if (n%i==0)
{
++c; // increment count of
factors
System.out.println(“Factors= ”i); // print the
factor
}
}
if (c==0)
System.out.println("Prime");
else
System.out.println("Composite");
}
}
}

OUTPUT:
Enter no for factor: 5
Factors= 1
Prime
-------------------
Enter no for factor: 6
Factors= 1 2 3
Composite
14) Write a Java program to generate reverse of a number.

import java.util.Scanner;
public class reverse {
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);
System.out.println("Enter number to be reversed: ");
int n=s.nextInt();
int rev=0, d;
while (n!=0)
{
d=n%10;
n=n/10;
rev=rev*10+d;
}
System.out.println(“Reversed number= ” + rev);
}
}

OUTPUT:
Enter number to be reversed: 127
Reversed number= 721
15) Write a Java Program to input Sales figures of a product for 12 months.
Print the maximum and minimum Sales figure.

import java.util.Arrays;
public class sales {
public static void main(String[] args)
{
double[]sales={20, 50, 55, 60, 45, 37, 70, 65, 40, 30, 60,
75};
Arrays.sort(sales);
System.out.println(“Minimum sales figure= ” + sales[0]);
System.out.println((“Maximum sales figure= ” +
sales[sales.length-1]);
}
}

OUTPUT:
Minimum sales figure= 20.0
Maximum sales figure= 75.0
16) Write a Java program to input names of 10 students. User should be
able to search for a name and the program should display message
accordingly.

import java.util.Arrays;
import java.util.Scanner;
public class binary_srch {
public static void main (String[]args)
{
Scanner s1=new Scanner(System.in);
String name[]={"a", "b", "c", "d", "e", "f", "g", "h",
"i", "j"};
System.out.println("Enter name to search: ");
String x=s1.next();
int index= Arrays.binarySearch(name, x);
if (index!= -1)
System.out.println("name is at position " +
(index+1));
else
System.out.println("name not found");
}
}

OUTPUT:
Enter name to search:
d
name is at position 4
-----------------------
Enter name to search:
x
name not found
17) Write a Java program to calculate Simple Interest using user defined
function.

import java.util.Scanner;
public class simple_interest {
static double si(double p, double r, double t){
double s=(p*r*t)/100;
return(s);
}
public static void main(String[] args){
Scanner S=new Scanner(System.in);
System.out.println("enter principle: ”);
double p=S.nextDouble();
System.out.println(“enter rate of interest: ”);
double r=S.nextDouble();
System.out.println(“enter time: ”);
double t=S.nextDouble();
double s=si(p,r,t);
System.out.println("Simple Interest= "
+Double.toString(s));
}
}

OUTPUT:
enter principle: 2000
rate of interest: 5
time: 2
Simple Interest= 200.0
18) Write a Java program to get a string and perform the basic string
manipulation.

import java.lang.String;
public class string_functions {
public static void main (String[]args)
{
String s= "Hi Everyone!";
System.out.println(s);
System.out.println(s.charAt(7));
System.out.println(s.concat(" How are y'all?"));
System.out.println(s.contains("Every"));
System.out.println(s.endsWith("one!"));
System.out.println(s.equals("Bye Everyone"));
System.out.println(s.equalsIgnoreCase("hi
everyone!"));
System.out.println(s.indexOf("v")); //char
System.out.println(s.indexOf("Ev")); //string
System.out.println(s.isEmpty());
System.out.println(s.length());
System.out.println(s.replace("!", "."));
System.out.println(s.toLowerCase());
System.out.println(s.toUpperCase());
}
}

OUTPUT:
Hi Everyone!
y
Hi Everyone! How are y'all?
true
true
false
true
4
3
false
12
Hi Everyone.
hi everyone!
HI EVERYONE!
19) Write a Java program to calculate the area and perimeter of a
square by using a class with a constructors and methods.

JCLASS 1:
import java.util.Scanner;
public class area_perimeter {
double s;
area_perimeter(){
s=0.0;
}
area_perimeter(double x){
s=x;
}
double area(){
double a=s*s;
return(a);
}
double perimeter(){
double p=4*s;
return(p);
}
}

JCLASS 2:
public class area_perimeter2 {
public static void main(String[] args){
area_perimeter s1= new area_perimeter(7.5);
System.out.println("area=" +s1.area());
System.out.println("perimeter=" +s1.perimeter());
}
}

OUTPUT:
area=56.25
perimeter=30.0

You might also like