0% found this document useful (0 votes)
224 views46 pages

Computer Project Class X

This document appears to be a student's computer science project submission for their ICSE coursework. It includes an acknowledgements section thanking their teacher and parents for their support. The document then lists assignments completed using Java and BlueJ including programs using if/else if statements, switch case statements, for loops, while loops and functions. It provides examples of programs to find the greatest of three numbers, calculate discounts based on purchase amount, and determine triangle type. The document serves to demonstrate the student's understanding of basic Java programming concepts.

Uploaded by

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

Computer Project Class X

This document appears to be a student's computer science project submission for their ICSE coursework. It includes an acknowledgements section thanking their teacher and parents for their support. The document then lists assignments completed using Java and BlueJ including programs using if/else if statements, switch case statements, for loops, while loops and functions. It provides examples of programs to find the greatest of three numbers, calculate discounts based on purchase amount, and determine triangle type. The document serves to demonstrate the student's understanding of basic Java programming concepts.

Uploaded by

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

ICSE COMPUTER APPLICATIONS

2021-2022
PROJECT

Submitted by Submitted to
Soham Ma’am Ganga Devi
ACKNOWLEDGEMENT

I would like to give special thanks and gratitude to my


teacher Ma’am Ganga Devi who gave me the golden
opportunity for making this educative project. I would
also like to give thanks to my parents because I would
not be able to complete this project without their help.
I expect that I would get these opportunities in future
also.
Thank You!
INDEX
S. NO. TITLE
01 INTRODUCTION TO
JAVA
02 INTRODUCTION TO
BLUEJ
03 ASSIGNMENT 1
IF ELSE IF PROGRAMS
04 ASSIGNMENT 2
SWITCH CASE
PROGRAMS
05 ASSIGNMENT 3
FOR LOOP PROGRAMS
06 ASSIGNMENT 4
WHILE AND DO WHILE
LOOP PROGRAMS
07 ASSIGNMENT 5
NESTED FOR LOOP
PROGRAMS
08 ASSIGNMENT 6
STRING PROGRAMS
09 ASSIGNMENT 7
FUNCTION PROGRAMS
10 ASSIGNMENT 8
ARRAY PROGRAMS
11 ASSIGNMENT 9
CLASS PROGRAMS
INTRODUCTION TO JAVA
Java is a high-level programming language originally developed by Sun
Microsystems and released in 1995. Java runs on a variety of platforms, such as
Windows, Mac OS, and the various versions of UNIX. This tutorial gives a
complete understanding of Java. This reference will take you through simple
and practical approaches while learning Java Programming language.

Why to Learn java Programming?


Java is a MUST for students and working professionals to become a great
Software Engineer especially when they are working in Software Development
Domain. I will list down some of the key advantages of learning Java
Programming:
• Object Oriented − In Java, everything is an Object. Java can be easily extended since it is
based on the Object model.

• 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.

• Architecture-neutral − Java compiler generates an architecture-neutral object file format,


which makes the compiled code executable on many processors, with the presence of Java
runtime system.

• Portable − Being architecture-neutral and having no implementation dependent aspects


of the specification makes Java portable. Compiler in Java is written in ANSI C with a clean
portability boundary, which is a POSIX subset.

• Robust − Java makes an effort to eliminate error prone situations by emphasizing mainly
on compile time error checking and runtime checking.
INTRODUCTION TO BLUEJ

BlueJ is an IDE (Integrated Development Environment) for beginners


to write, edit and execute the Java programs.

It allows students to write programs using an interactive visual


environment, which gives them a good understanding of the
programming concept. BlueJ includes:

 An editor, which you use to write your programs.


 A debugger, to help you find your mistakes.
 A viewer, to see the parts of your program.
 An easy way to run Java programs.
 An easy way to view documentation.
BlueJ is a Java development environment that is being
developed and maintained by a joint research group at Deakin
University, Melbourne, Australia, and the University of Kent in
Canterbury, UK, explicitly as an environment for teaching
introductory object oriented programming.
An Object Oriented Programming language is an art of
separating the program into a number of objects, i.e., self-
contained application components that work together in order
to complete the task.
PROGRAMS IN BLUEJ
ASSIGNMENT 1
If else if programs
Q1.Write a program to input 3 numbers and find the greatest and
smallest number

// To print the greatest number

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 :

Total Cost Discount


Less than Rs.2000 5%
Rs.2000 to Rs.5000 25%
Rs.5000 to Rs.10000 35%
Rs. 10000 and 50%
above

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

{public static void main(String args[])

{Scanner sc = new Scanner(System.in);

System.out.print("Enter total cost: ");

double cost = sc.nextDouble();

double amt;

if (cost < 2000)

amt = cost - (cost * 5 / 100.0);

else if (cost < 5000)

amt = cost - (cost * 25 / 100.0);

else if (cost < 10000)

amt = cost - (cost * 35 / 100.0);

else

amt = cost - (cost * 50 / 100.0);

System.out.println("Amount to be paid: " + amt); } }


Q3. Write a program to input the sides of a triangle, and print
whether the triangle is equilateral, isosceles or scalene triangle.

//To print the type of a triangle

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

a int To store the value of first side

b int To store the value of second side

c int To store the value of third side


ASSIGNMENT 2
Switch Case Programs

Q 1. Write a menu driven program to find the area of an


equilateral triangle , an isosceles triangle, and a scalene triangle
as per the user’s choice.
3
1. Equilateral triangle :- 𝑠 2 , s = side of an equilateral triangle
4
1
2. Isosceles triangle :- b*( 4𝑎2 −𝑏 2 )2
(𝑚 +𝑛+𝑝)
3. Scalene triangle :- 𝑠 ∗ 𝑠 − 𝑚 ∗ 𝑠 − 𝑛 ∗ (𝑠 − 𝑝) where s = 2

//A menu driven program to calculate the area of the triangles


import java.util.Scanner;
class triangle
{ public static void main(String args[ ])
Scanner sc=new Scanner(System.in);
{ int a, b, c, m, n, p, s;
Double k, area=0;
System.out.println("1.Area of an Equilateral triangle");
System.out.println("1.Area of an Isosceles triangle");
System.out.println("1.Area of a Scalene triangle");
System.out.println("Enter your choice");
C=sc.nextInt();
Switch
{
Case 1:
System.out.println("Enter side of an Equilateral triangle");
s=in.nextInt();
area=(math.sqrt(3)*s*s)/4.0;
System.out.println("Area="+area);
break;
Case 2:
System.out.println("Enter side of an Isosceles triangle”);
a=in.nextInt();
b=in.nextInt();
area=b*(Math.sqrt(4*a*a-b*b))/4.0;
System.outprintln("Area="=area);
break; }
{ Case 3:
System.out.println("Enter side of aScalene triangle");
m=in.nextInt();
n=in.nextInt();
p=in.nextInt();
K=(m+n+p)/2.0;
area=Math.sqrt(k*(k-m)(k-n)(k-p));
System.out.println("Area="+area);
break;
default;
System.out.println("Wrong choice!!"); } } }

List of Variables

Variable Data Type Purpose


a int to input the
first side
b int to input the
second side
c int to input the
third side
m int to store the
value of a
n int to store the
value of b
p int to store the
value of c
s int to input the
side of an
equilateral
triangle
Q 2. Write a program to display the subjects as per user’s choice

//To display the subjects


import java.util.Scanner;
class sub
{public static.void main( );
{Scanner sc = new Scanner (System.in);
System.out,printIn("Enter 1 for English, 2 for Science, 3 for
Mathematics, 4 for Social Science, 5 for Hindi and 6 for Computer");
System.out.println("enter your choice");
int a = sc.nextInt();
Switch (a):
{Case 1:
System.out.print("Subject is English");
break;
Case :2
System.out.print("Subject is Science");
break;
Case :3
System.out.print("Subject is Mathematics");
break;
Case : 4
System.out.print("Subject is Social Science");
break;
Case :5
System.out.print("Subject is Hindi");
break;
Case :6
System.out.print("Subject is Computer”);
break;
Default;
System.out.print("Wrong Choice");}}

LIST OF VARIABLES

VARIABLE DATA TYPE PURPOSE


a int To input different
subjects
Q 3. Using a switch statement, write a menu driven
program to calculate the maturity amount of a bank deposit. The
user is given the following options :
I. Term Deposit
II.Recurring Deposit
For option I. accept principal (p), rate of interest (r) and the time period in
the years (n), calculate and give the output of the maturity amount (A) using
the formula.
A =p*(1+r/100)n
For option (ii) accept monthly instalment (p), rate of interest (r) and
time period in months (n). Calculate and output the maturity
amount
(A) =P*n +p(n*(n+1/2)r/100*1/12
For an incorrect option, an appropriate error message should be
displayed.

//To calculate Term deposit or Recurring deposit


import java.util.Scanner;
public class deposit
{
public static voidmain(string args[ ])
{
Scanner sc = new scannner(System.in);
double p,r,a;
int n,ch;
System.out.println("Menu List”);
System.out.println("1. Term Deposit");
System.out.println("2. Recruring Deposit");
System.out.println("Enter your choice");
ch=sc.nextInt();
switch(ch)
{
Case 1:
System.out.println("Enter Principal, Rate and Time");
p= sc.nextDouble();
n=in.nextDouble();
r=in.nextInt();
a=p*Math.pow((1+r/100.0),n);
System.out.println("Amount under term deposit=Rs."+a);
break;
Case 2:
System.out.println("Enter Principal, Rate and Time”);
p=in.nextDouble();
n=in.nextDouble();
r=in.nextInt();
a=p*n +p(n*(n+1/2)*(r/100)*(1/12))
System.out.println("Amount under term deposit=Rs.”+a);
break;
default;
System.out.println("Invalid Choice"); } } }

LIST OF VARIABLES

VARIABLE DATA TYPE PURPOSE


p double to enter the value of
principal
r double to enter the value of rate
a double to enter the value of
amount
n int to enter the value of time
in years or months
ch int to enter your choice
ASSIGNMENT3
For Loop Programs
Q 1. Write a program in Java to check whether the number is
prime number or not.

//Program to Check whether the number is Prime or Not


import java.util.Scanner;
public class prime
{
public static void main(String args[ ])
{
int num, i, count=0;
Scanner scan = new Scanner(System.in);

System.out.print("Enter a Number : ");


num = scan.nextInt();

for(i=2; i<num; i++)


{
if(num%i == 0)
{
count++;
break;
}
}
if(count == 0)

System.out.print("This is a Prime Number");

else

System.out.print("This is not a Prime Number");


}
}
Q2.Write a program in java to print the sum
of natural number from 1 to 1000
// Program to find the sum of natural numbers
from 1 to 1000.

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

VARIABLE DATA TYPE PURPOSE


y int to store the value of a
r int to store the value of s
s int storing the sum
c int to input choice
av int storing the average
Q 2.Write a program to input a number and find whether
the number is cyclo or not.
(A number is said to be cyclo number if the first digit and
the last digit is same).

//To find whether the number is cyclo number or not


class cyclo
{public static void main (int a);
{ int x-a%10; int ;
while (x>0);
{r-a%10;
a-a%10; }
if(x == 1)
System.out.print("cyclo number");
else
System.out.print("Not a cyclo number");
}

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 )

//To find the number is palindrome number or not.


class palindrome
{public.static.void main(int a);
{int y + a :r;d:0,
while(a>0);
{r=a%10;
a=a%10
d=(d*10)+r;
}
System.out.println("it is palindrome");
else
System.out.println("it is not a palindrome");
}
LIST OF VARIABLES

Varaible Data Type Purpose


a int to input a number
y int to store the original
digits
r int to store digits
d int to store the reserved
digits
Q 4.Write a program to input and find whether the number is
neon or not.

(A number is said to to be neon if sum of the digits and square of


the number is equal to the number itself. E.g.- 9 ,

9*9=81 8+1=9 )

//Program to find whether the number is neon or not


class neon
{public.static.void.main(int a);
{int s=0; int a; int n;
While(a>0);
{ s=a+a%10;
a=a/10;
n=a; }
System.out.println("It is a neon number");
System.out.println("It is not a neon number");
}
LIST OF VARIABLES

VARIABLE DATA TYPE PURPOSE


a int to input a number
s int for divivding a
number
n int to store original
number
ASSIGNMENT 4
NESTED FOR LOOP

Q 1.Write pattern program in Java using nested for


loop
No. of rows : 5 1
No. of columns : 5 23
456
7 8 9 10
11 12 13 14 15

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 Input : BLUEJ

Sample Output :

//To display the given pattern

import java.util.Scanner ;

public class Pattern

public.static.void.main(sting args[]);

Scanner sc=new Scanner(System.in);

int a,b;

String st;

System.out.println("Enter the word in upper case");

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

replace with 'e' with '*' in a given String.Display a new string.

Sample Input : Computer Science

Sample Output:Comput*r Sci*nc*

//To replace 'e' with '*' in a String

import.java.util. Scanner;

public class Replace

int a,p;

String st;

Char chr;

Scanner sc=new Scanner(System.in);

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

// To convert the case of the string


import java.util.";
public case Convert Case
{
public static void main(String args());
{
Scanner in=new Scanner(system.in);
int al.p;
String st,sti."
Char chr chri)
System.out.println("Enter your string");
St=sc.nextLine();
p=sc.length);
for(a=0;a<p;a++);
{
Chr=st.charAt(a);
if(chr>='a'&&chr< '2');
{
Chr1 -Character.to.UpperCase(chr);
St=st+chr11;
}
else
{
Chr1=Character.to.LowerCase(chr);
Sti-st1+chr1;
)
else
St1=st+chr;
}
System.out.println("Thenew String after convertingthe case
of each
alphabet:");
System.out.println(st1);
}
}
ASSIGNMENT 6

FUNCTION PROGRAMS

Q 1.Write a program to input two numbers and find the greatest of


two numbers.

Use a function called maximum which will accept the two


numbers and print the greatest number

import java.util.Scanner;

class maxx

void maximum(int a,int b)

if (a>b)

return(a);

else

return(b);}

public static void main()

{ Scanner sc= new Scanner(System.in);

maxx ob =new maxx();

System.out.println(“Input two numbers”);

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

s=(1*2) +(2*3) +(3*4) + . . . to n times

import java.util.Scanner;

class series

{int sum(int n)

{ int s =0;

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

{ s=s+(i *(i+1); }

return (s); }

public static void main()

{Scanner sc=new Scanner(System.in);

series ob =new series();

System.out.println(“Input the value of n”);

int n =sc.nextInt();

int p =ob.sum(n);

System.out.println(“Sum of series “ +s);

}
Q 3. Write a program to calculate the monthly electricity bill of a
consumer according to units consumed. The tariff is given below

Units Consumed Charge


Upto 100 units Rs. 1.25 per unit
For next 100 units Rs. 1.50 per unit
For next 100 units Rs. 1.80 per unit
More than 300 units Rs. 2 per unit
Units consumed = Present Reading – Previous Reading

Use a function called cal(int unit) to accept the units consumed


and return the amount that has to payed to main program. Accept
all details for the program in main function and output should be
in the following format

Consumer No Name Units Consumed Amount

xxxxxx xxx xxxxx xxx

import java.util.Scanner;

class Electricity

void cal(int unit)

{ double amt =0.0;

if(unit<=100)

amt=unit*1.25;

else if ((unit >100)&&(unit<=200))

amt=(100*1.25) +(unit-100)*1.50;

else if ((unit >200)&&(unit<=300))

amt =(100*1.25) +(100*1.50) + (unit-200)*1.80;

else

amt=(100*1.25) +(100*1.50) + (100*1.80 )+(unit-3 00)*2;

return (amt ); }
public static void main()

{Scanner sc=new Scanner(System.in);

Electricity ob =new Electricity();

int prev, present, unit, cn;

double amt;

System.out.println(“Enter Customers Name ”);

String name =sc.next ();

System.out.println(“Enter Consumer number”);

cn = sc.nextInt();

System.out.println(“Enter previous reading ”);

prev = sc.nextInt();

System.out.println(“Enter present reading ”);

present = sc.nextInt();

unit =present-prev;

amt=ob.cal(unit);

System.out.println(“Consumer name \t Consumer No \tUnit


Consumed\tAmount “);

System. out.println(name+” ”+cn+”\t” +unit+”\t” + amt); }}


Q 4.Write a program to input the value of a and b and find the
𝒂!
sum by s=
𝒃!∗ 𝒂−𝒃 !

(! Sign means factorial of the number ) Use a function called fact


where you can find the factorial of each number.

import java.util.Scanner;

class sum

{int fact(int n)

{ int f=1;

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

{ f=f*i ; }

return (f); }

public static void main()

{Scanner sc=new Scanner(System.in);

sum ob =new sum();

System.out.println(“Input the value of a and b”);

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

Q 1.Define a class named ShowRoom with the following description:


Instance variables/data members:
String name: to store the name of the customer.
long mobno: to store the mobile number of the customer.
double cost: to store the cost of the items purchased.
double dis: to store the discount amount.
double amount: to store the amount to be paid after discount.
Member methods:
ShowRoom(): default constructor to initialize data members.
void input(): to input customer name, mobile number, cost.
void calculate(): to calculate discount on the cost of purchased items,
based on the following criteria:
void display(): to display customer name, mobile number, amount to be
paid after discount.
COST DISCOUNT(IN PERCENTAGE)
Less than or equal to Rs. 10000 5%
More than Rs. 10000 and less than 10%
or equal to Rs. 35000
More than Rs. 20000 and less than 15%
or equal to Rs. 35000
More than Rs. 35000 20%

Write a main() method to create an object of the class and call the above
member methods.

//To find the discount from cloth shop

import java.util.Scanner;

class showroom

{String name; long mobno;

double cost, dis, amount;

showroom()
{ name =“ “; mobno = 0; cost =0; dis=0; amount =0; }

void input()
{ Scanner sc=new Scanner(System.in);

System.out.println(“Input name, mobile no and cost “);

name =sc.nextLine();

mobno = sc.nextLong();

cost =sc.nextDouble(); }

void calculate()

{ if (cost <= 10000)

dis =cost*5/100;

else if ((cost>10000) &&(cost <=20000))

dis=cost*10/100;

else if ((cost>20000)&&(cost<=35000))

dis = cost* 15/ 100;

else

dis= cost*35/1000;

amount=cost-dis; }

void display()

{ System.out.println(“Name of customer”+name);

System.out.println(“Mobile number “+mobno);

System.out.println(“Cost “+cost);

System.out.println(“Discount”+dis);

System.out.println(“Amount to be paid”+amount); }

public static void main()


{ showroom ob = new showroom();
ob.input();
ob.calculate();
ob.display(); }}
Q 2.Define a class named FruitJuice with the following description :
Instance variables/data members:
int product_code - stores the product code number
String flavour - stores the flavor of the juice(eg.orange,apple, etc)
String pack _type - stores the type of packaging(eg. Tetra pack, PET
bottle, etc)
int pack_size - stores package size(eg.200ml,400ml,etc)
int product_price - stores the price of the product
Member methods:
(i) FruitJuice() - default constructor to initialize integer data members to 0
and
string data members to “”.
(ii) void input() - to input and store the product code, flavour, pack type,
pack
size and product price.
(iii) void discount() - To reduce the price by 10;
(iv) void display() - To display code, flavour, pack type, pack size and
price.

// To print the flavour price and code of fruit


import java.util.Scanner;
class Fruitjuice
{ int product_code ;
String flavour ; String pack _type ;
int pack_size; int product_price;

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); }

public static void main()


{ Fruitjuice ob = new Fruitjuice();
ob.input();
ob.discount();
ob.display(); }}
Q 3.Define a class named Book Fair with the following description :
Instance variables/data members:
String Bname - to store the name of the book
double price - to store the price of the book
Member methods:
BookFair() - Default constructor to initialize data members
void input() - To input and store the name and the price of the
book.
void calculate() - To calculate the price after discount.
Discount is based ont the following criteria :-
PRICE DISCOUNT
Less than or equal to Rs 1000 2%
More than Rs 1000 and less than 10%
or equal to Rs 3000 10%
More than Rs 3000 15%

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.

// To print the details of book


import java.util.Scanner;
class BookFair
{ String Bname; double price;

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

Q 1. Write a program to input 10 number and print the


greatest and smallest number.

// To input and print greatest and smallest number


import java.util.Scanner;
class greatsmall
{public static void main()
{Scanner sc=new Scanner (System.in);
int a[]=new int[10];
System.out.println("Input 10 numbers ");
for(int i=0;i<10; i++)
{ a[i] =sc.nextInt(); }
int m=a[0]; int s= a[0];
for(int i=0;i<10;i++)
{ if (m<a[i])
m=a[i];
if(s>a[i]) s= a[i]; }
System.out.println("Greatest number in array is “+m);
System.out.println("Smallest number in array is “ +s); }}
Q 2.Write a program to input 50 numbers . Store the even
numbers and odd numbers in two separate arrays and
print them.

// To store even and odd numbers in two separate arrays


import java.util.Scanner;
class evenodd
{public static void main()
{Scanner sc=new Scanner (System.in);
int a[]=new int[50];
System.out.println("Input 50 numbers ");
for(int i=0;i<50;i++)
{ a[i] =sc.nextInt(); }
int even[] =new int[50]; int odd[] = new int[50];
int c=0,d=0;
for (int i =0;i<50; i++)
{if a[i]%2==0)
{ even[c] =a[i]; [++;}
else
{odd[d] =a[i]; d++;}}
System.out.println("Even numbers are “);
for(int i=0;i<c; i++)
System.out.println(even[i]);}
System.out.println("Odd numbers are“);
for(int i=0;i<d; i++)
System.out.println(odd[i]);}
Q 3.Given two arrays :-
int a[]={2,5,8,10,12}; int b[]={0,-5,-3,-10,-22};
Combine both the arrays in the following format
int c[]={2,5,8,10,12,0,-5,-3,-10,-22};

// to combine both arrays


class number
{public static void main()
{
int a[] = {2,5,8,10,12};
int b[]= {0,-5,-3,-10,-22}
int c[] =new int [10];
for(int i =0;i< 5; i+ +)
{c[i]=a[i];}
int x=0;
for( int i =5;i< 10; i+ +)
{c[i]=b[x]; x++;}
System.out.println(“The combined array is”);
for(int i=0; i<10; i++)
{ System.out.println(c[i]);}
ASSIGNMENT 9
CLASS PROGRAMS
Q 1.Write a Program to print the area of a
rectangle by creating a class named “Area” taking
the values of its length and breadth as parameters
of its constructors and have a method named
“returnArea” which returns the area of the
rectangle.

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.

// Program to find the average marks of student


import java.util.Scanner;
class student
{ String name;
int age,m1,m2,m3 , maximum;
double average;
student()
{
name =“ “;
age =0;m1=0;m2=0;m3=0;maximum =0;
average =0.0; }
void input()
{Scanner sc=new Scanner(System.in);
System.out.println(“Input the name and age”);
name=sc.nextLine();
age =sc.nextInt();
System.out.println(“Input marks of 3 subject”);
m1=sc.nextInt();
m2=sc.nextInt();
m3=sc.nextInt(); }

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 :-

 LOGIX Computer Applications Text Book for


Class X

 Google

 Our Computer teacher- Ma’am Ganga Devi

 My Classmates

You might also like