Computer Project Class X
Computer Project Class X
2021-2022
PROJECT
Submitted by Submitted to
Soham Ma’am Ganga Devi
ACKNOWLEDGEMENT
• Platform Independent −Unlike many other programming languages including C and C++,
when Java is compiled, it is not compiled into platform specific machine, rather into
platform independent byte code. This byte code is distributed over the web and interpreted
by the Virtual Machine (JVM) on whichever platform it is being run on.
• Simple − Java is designed to be easy to learn. If you understand the basic concept of OOP
Java, it would be easy to master.
• Secure − With Java's secure feature it enables to develop virus-free, tamper free systems.
Authentication techniques are based on public-key encryption.
• Robust − Java makes an effort to eliminate error prone situations by emphasizing mainly
on compile time error checking and runtime checking.
INTRODUCTION TO BLUEJ
import java.util.Scanner;
class great
{public static void main( )
{ int a, b, c;
System.out.println(“Input three numbers”);
a=sc.nextInt(); b=sc.nextInt(); c= sc.nextInt( );
if ((a>b)&&(a>c))
System.out.println(a + “is the greatest number “);
else
if ((b>a)&&(b>c))
System.out.println(b + “is the greatest number “);
else
System.out.println(c + “is the greatest number “);
if ((a<b)&&(a<c))
System.out.println(a + “is the smallest number “);
else if ((b<a)&&(b<c))
System.out.println(b + “is the smallest number “);
else
System.out.println(c + “is the smallest number “);}}
List of Variables
Variable Data Type Purpose
a int To input first
number
b int To input second
number
c int To input third
number
Q2. A cloth showroom has announced the following festival discounts on the
purchase of items based on the total cost of the items purchased :
Write a program to input the total cost and to compute and display the
amount to be paid by the customer availing the discount.
import java.util.Scanner;
class ClothDiscount
double amt;
else
class triangle
{
public static void main(int a, int b, int c);
{
if ((a==b)&&(a==c))
System.out.println(“Eqilateral triangle”);
else if (a==b)||(a==c)||(b==c)
System.out.println(“Isosceles triangle”);
else
System.out.println(“Scalene triangle”); } }
LIST OF VARIABLES
Variable Data Type Purpose
List of Variables
LIST OF VARIABLES
LIST OF VARIABLES
else
class number
{
public static void main(String[] args)
{
int sum = 0;
int n = 1000;
for (int i = 1; i <= n; ++i)
{ sum += i; }
System.out.println("Sum = " + sum);
}
}
ASSIGNMENT 3
While and Do While Loop
Q 1.Write a program to input a number and find
the sum of digit and average.
//To find the sum and average of a number
class sum
{public static void main (int a);
{int y = a; int r,s,c = 0; double av=0.0;
while (a>0)
{ r = a%10;
a=a/10;
c=c+1;
s=s+r;
av = s/c; }
System.out.printnin("sum is"+s);
System.out.println("average is"+av);
}
LIST OF VARIABLES
LIST OF VARIABLES
VARIABLE DATA TYPE PURPOSE
a int to input a number
x int to store the
quotient
r int to find remainder
Q 3. Write a program to input a number and check
whether number is palindrome or not.
A number is said to be palindrome if the number after
reversing is same as the original number , e.g:-535 )
9*9=81 8+1=9 )
class pattern i j
1 1 number
{ 2 2 numbers
public static void main() 3 3 numbers
4 4 numbers
{ 5 5 numbers
int a=1;
for( int i=1; i<=5; i++)
{
for(int j =1; j<=I; j++)
{
System.out.print(a); a+=1;
}
System.out.println();
}
}
Q 2. Write a program to print the following loop :-
number of rows = 5
class pattern number of rows = 5
{
public static void main()
{ Numbers in Sum of the
int s=0; pattern numbers
for(int i=1; i<=5; i++) 1 1
{ 12 3
s=0
123 6
for( int j=1; j<=i; j++)
1234 10
{
s = s+j; 12345 15
System.out.println(j) ;
}
System.out.println(s) ;
}
ASSIGNMENT 5
String Programs
Q 2.Write a program to display each letter of a word entered by the user.
Sample Output :
import java.util.Scanner ;
public.static.void.main(sting args[]);
int a,b;
String st;
Strin.next();
b=st.length();
System.out.println("The pattern");
for(a=0;a<b;a++){
System.out.println(st.charAt)(a));
}
Q 2.Write a program to accept a String in lower case and
import.java.util. Scanner;
int a,p;
String st;
Char chr;
System.out.println("Enter a String");
string.nextLine();
p=st.length();
For(a=0;a<p;a++);
if(chr=='e');
chr='*';
System.out.print(chr);
System.out.println();
}
Q 3.Write a program to accept a string and change a
case of each letter of the string. Display the newstring.
Sample Input: WelComE TO School
Sample Output: wELcOMe to sCHOOL
FUNCTION PROGRAMS
import java.util.Scanner;
class maxx
if (a>b)
return(a);
else
return(b);}
int a =sc.nextInt();
int b =sc.nextInt();
ob.maximum(a,b);
}
Q 2.Write a program to find the sum of the given series to n terms
by using a function named sum(int n) . Write the main program to
display the sum of the series
import java.util.Scanner;
class series
{int sum(int n)
{ int s =0;
{ s=s+(i *(i+1); }
return (s); }
int n =sc.nextInt();
int p =ob.sum(n);
}
Q 3. Write a program to calculate the monthly electricity bill of a
consumer according to units consumed. The tariff is given below
import java.util.Scanner;
class Electricity
if(unit<=100)
amt=unit*1.25;
amt=(100*1.25) +(unit-100)*1.50;
else
return (amt ); }
public static void main()
double amt;
cn = sc.nextInt();
prev = sc.nextInt();
present = sc.nextInt();
unit =present-prev;
amt=ob.cal(unit);
import java.util.Scanner;
class sum
{int fact(int n)
{ int f=1;
{ f=f*i ; }
return (f); }
int a =sc.nextInt();
int b =sc.nextInt();
int g=a-b;
int x=ob.fact(a);
int y=ob.fact(b);
int z=ob.fact(g);
double p =x/(y*z);
System.out.println(“Sum”+ p); }}
ASSIGNMENT 7
CONSTRUCTOR PROGRAMS
Write a main() method to create an object of the class and call the above
member methods.
import java.util.Scanner;
class showroom
showroom()
{ name =“ “; mobno = 0; cost =0; dis=0; amount =0; }
void input()
{ Scanner sc=new Scanner(System.in);
name =sc.nextLine();
mobno = sc.nextLong();
cost =sc.nextDouble(); }
void calculate()
dis =cost*5/100;
dis=cost*10/100;
else if ((cost>20000)&&(cost<=35000))
else
dis= cost*35/1000;
amount=cost-dis; }
void display()
{ System.out.println(“Name of customer”+name);
System.out.println(“Cost “+cost);
System.out.println(“Discount”+dis);
System.out.println(“Amount to be paid”+amount); }
Fruitjuice()
{ product_code =0 ; flavour= “ “ ; pack _type=“ “ ;
pack_size=0; product_price=0; }
void input()
{ Scanner sc = new Scanner(System.in);
System.out.println(“Input product code flavour , price);
product_code = sc.nextInt();
flavour=sc.nextLine();
void discount()
{product_price =product_price-10;}
void display()
{ System.out.println(“product code “+product_code);
System.out.println(“flavour “+flavour);
System.out.println(“Pack Type” +pack_type);
System.out.println(Packsize “+pack_size);
System.out.println(“Price “+product_price); }
void display() - To display the name and price of the book after
discount.
Write a main method to create an object of the class and call the
above member methods.
BookFair( )
{ Bname =n;
price= p; }
void input( )
{ Scanner sc =new Scanner(System.in);
System.out.println(“Input details “);
bname =sc.nextLine();
price= sc.nextDouble; }
void calculate()
{ double discount;
if (price<=1000)
discount =price*2/100;
else if ((price>1000) &&(price <=3000))
discount =price *10/100;
else
discount =price *15/100;
price =price-discount;
}
void display()
{ System.out.println(“Bookname“+ bname);
System.out.println(“Price “+price);
}
public static void main()
{ BookFair ob = new BookFair( );
ob.input();
ob. calculate();
ob.display(); }}
ASSIGNMENT 8
ARRAY FROGRAMS
import java.util.Scanner;
class area
{
int length;
int breadth;
area(int a, int b)
{
length = a;
breadth = b;
}
public int areareturn()
{
return length * breadth;
}
}
public class Rectangle4
{
public static void main(String[] args)
{
Scanner obj = new Scanner(System.in);
int a,b;
System.out.println("Enter the lenght of
Recatangle");
a = obj.nextInt();
obj.nextLine();
System.out.println("Enter the breadth of
Recatangle");
b = obj.nextInt();
area ob1 = new area(a,b);
System.out.println("Area = "+ ob1.areareturn());
}
}
Q 2 Define a class Student described as below:
Data members/instance variables :-
String name
int age,m1,m2,m3 (marks in 3 subjects), maximum
double average
Member metods :-
Student() : Constructor to initialize the variables
void input() : To input the name of student age and
marks or three subject
void compute() : To compute the average and the
maximum out of three marks.
void display() : To display the name, age, marks in
three subjects, maximum and average.
Write a main method to create an object of a class
and call the above
member methods.
void compute()
{ if((m1>m2) &&(m1>m3))
maximum =m1;
else if((m2>m1) &&(m2>m3))
maximum =m2;
else
maximum =m3;
average =(m1+m2+m3)/3; }
void display()
{ System.out.println( “Name “+name);
System.out.println(“Age “+age);
System.out.println(“ Maximum marks “+maximum);
System.out.println(“Average “+average); }
public static void main()
{ student ob=new student();
ob.input();
ob.calculate();
ob.display(); }}
Q 3.Define a class Employee described as below:
Data members/instance variables :
String name
double basic,da,hra,total,pf,netsalary
Member metods :
Employee() : Constructor to initialize the variables
void input() : To input the name of employee and
basic salary
void calculate() : To calculate allowances and salary
as per the given criteria.
da=45%of basic
hra =15%of basic
pf =8.33% of basic
total =basic+da+hra
netsalary = total -pf
void display() : To display the name, basic pay, da,
hra total and netsalary
Write a main method to create an object of a class
and call the above member methods.
import java.util.Scanner;
class employee
{ String name;
double basic,da,hra,total,pf,netsalary , average;
employee()
{
name = “ ”;
basic=0.0;da= 0.0,hra =0,total =0,netsalary=0,
average=0; }
void input()
{Scanner sc=new Scanner(System.in);
System.out.println(“Input the name and basic pay”);
name=sc.nextLine();
basic=sc.nextInt(); }
void calculate()
{ da=basic*45/100;
hra=basic*15/100;
pf=basic* 8.33
total = basic+da+hra;
netsalary=total-pf;
}
void display()
{ System.out.println( “Name “+name);
System.out.println(“basic”+basic);
System.out.println(“Hra is “hra”);
System.out.println (“Pf is “+pf);
System.out.println(“ total=“total);
System.out.println(“netsalary =netsalary); }
public static void main()
{ employee ob = new employee();
ob.input();
ob.calculate();
ob.display(); }}
BIBLIOGRAPHY
For completing this project, I have taken help
from the following :-
My Classmates