0% found this document useful (0 votes)
260 views

Computer Project Class 10 Icse Programming Divine Mercy

The document contains details about a student project on the topic of Java Programming and BlueJ. It includes the student's name, class, registration number, school details, and an acknowledgement section thanking teachers and parents for their support. It also includes a table of contents listing 20 subtopics that are covered in the project along with their corresponding page numbers.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
260 views

Computer Project Class 10 Icse Programming Divine Mercy

The document contains details about a student project on the topic of Java Programming and BlueJ. It includes the student's name, class, registration number, school details, and an acknowledgement section thanking teachers and parents for their support. It also includes a table of contents listing 20 subtopics that are covered in the project along with their corresponding page numbers.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 49

NAME-Araman Kumar Parida

CLASS-X SECTION-A
REGISTRATION NUMBER-161
TOPIC-Java Programming and BlueJ
SUBJECT-Computer Applications
Unique ID- 7526233
SCHOOL-Divine Mercy School
SESSION-2021-2022

Acknowledgement
I would like to express my special thanks of gratitude to
my Computer Applications teacher Miss Anita Ma’am
for her able guidance and support for completing my
project. I would also like to thank our honorable
Principal Mr. Rajib Chakraborty for giving us this
golden opportunity to do this project on the topic ‘’Java
Programming and BlueJ”, which helped me a lot in
doing a lot of research. I am really thankful to them.
Secondly, I would also like to thank my parents and
friends, who helped me in finalizing this project within
the limited time frame.
CONTENT
Serial Number Subtopic Page Number
01 WAP to show discount 05-06
for Laptops
02 WAP to see whether 07-08
the number is
palindrome or special
number
03 WAP to initialize ‘The 09-10
Seven Wonders of the
World’ along with their
locations in two
different arrays
04 WAP with class 11-12
name FruitJuice
05 WAP Designing a 13-14
class to overload a
function series( )
06 WAP designing a class 15-16
to overload a function
polygon()
07 WAP to assign a full 17-19
path and file name
08 WAP to assign a full 20-21
path and file name
09 WAP in Java to accept a 21-22
String in upper case and
replace all the vowels
present in the String with
Asterisk (*) sign
10 WAP to input integer 23-24
elements into an array of
size 20
11 WAP to generate a 24-27
triangle or an
inverted triangle
based upon User’s
choice
12 WAP for a Unique 27-28
string
13 WAP to generate a 29-30
Floyd and ISCE
Pattern
14 WAP for Binary 31-32
search
15 WAP to calculate 32-34
the ACSII
difference
16 WAP for the 35-36
Piglatin number
17 WAP for Perfect 37-38
square
18 WAP to calculate 39-40
the Marks of 40
students
19 WAP to see 41-43
whether the
number is Prime or
Automorphic
number
20 WAP to calculate 44-45
the Fibonacci
series or sum of
digits
1.\\WAP to show the special discount on the purchase of Laptops
import java.util.Scanner;

public class Laptop


{
private String name;
private int price;
private double dis;
private double amt;

public Laptop(String s, int p)


{
name = s;
price = p;
}

public void compute() {


if (price <= 25000)
dis = price * 0.05;
else if (price <= 50000)
dis = price * 0.075;
else if (price <= 100000)
dis = price * 0.1;
else
dis = price * 0.15;

amt = price - dis;


}

public void display() {


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

public static void main(String args[]) {

Scanner in = new Scanner(System.in);


System.out.print("Enter Customer Name: ");
String str = in.nextLine();
System.out.print("Enter Price: ");
int p = in.nextInt();

Laptop obj = new Laptop(str,p);


obj.compute();
obj.display();
}
}
Output:-

Variable Description:-

Variable Name Data Type Function


name String To take the name of the
customer as input
price Integer To take the price of the
laptop as input
dis Double To calculate the
discount that has to be
deducted
amt double To calculate the total
amount to be paid by
the customer
2. \\WAP to accept a word and print whether the word is a
palindrome or only special word.
import java.util.Scanner;

public class PalindromeotSpecial


{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
System.out.print("Please enter a word: ");
String str = in.next();
str = str.toUpperCase();
int len = str.length();
if (str.charAt(0) == str.charAt(len - 1))
{
boolean Palin = true;
for (int i = 1; i < len / 2; i++)
{
if (str.charAt(i) != str.charAt(len - 1 - i))
{
Palin = false;
break;
}
}
if (Palin)
{
System.out.println("Palindrome");
}
else
{
System.out.println("Special");
}
}
}
}
Output:-

Variable Description:-

Variable Name Data Type Function


str String To take the word given
by the user as input
len Integer To calculate the length
of the word given by
the user
Palin Boolean To return the value
“true “ or “false”
3. \\WAP to initialize the Seven Wonders of the World along with
their locations in two different arrays. Search for a name of the
country input by the user. If found, display the name of the country
along with its Wonder, otherwise display “Sorry Not Found!”.
import java.util.Scanner;

public class SevenWonders


{
public static void main(String args[])
{

String wonders[] = {"CHICHEN ITZA", "CHRIST THE REDEEMER", "TAJMAHAL",


"GREAT WALL OF CHINA", "MACHU PICCHU", "PETRA", "COLOSSEUM"};

String locations[] = {"MEXICO", "BRAZIL", "INDIA", "CHINA", "PERU",


"JORDAN","ITALY"};

Scanner in = new Scanner(System.in);


System.out.print("Enter country: ");
String c = in.nextLine();
int i;

for (i = 0; i < locations.length; i++)


{
if (locations[i].equals(c))
{
System.out.println(locations[i] + " - " + wonders[i]);
break;
}
}

if (i == locations.length)
System.out.println("Sorry Not Found!");
}
}

Variable Description:-

Variable Name Data Type Function


wonders[] String To initialize the Seven
Wonders of the World
locations[] String To initialize the locations
c String To store the country’s
name as input by the
user
i Integer To check whether the
inputted country’s name
is there in the list of
country’s name where
the Seven Wonders of
the World are.

Output:-
4. //WAP defining a class named FruitJuice with the given instructions:

Member Purpose
Methods
FruitJuice() constructor to initialize integer data members to 0 and string data
members to ""
void input() to input and store the product code, flavour, pack type, pack size
and product price
void discount() to reduce the product price by 10
void display() to display the product code, flavour, pack type, pack size and
product price
import java.util.Scanner;

public class FruitJuice


{
int product_code;
String flavour;
String pack_type;
int pack_size;
int product_price;

public FruitJuice()
{
product_code = 0;
flavour = "";
pack_type = "";
pack_size = 0;
product_price = 0;
}

public void input()


{
Scanner in = new Scanner(System.in);
System.out.print("Enter Flavour: ");
flavour = in.nextLine();
System.out.print("Enter Pack Type: ");
pack_type = in.nextLine();
System.out.print("Enter Product Code: ");
product_code = in.nextInt();
System.out.print("Enter Pack Size: ");
pack_size = in.nextInt();
System.out.print("Enter Product Price: ");
product_price = in.nextInt();
}

public void discount()


{
product_price -= 10;
}

public void display() {


System.out.println("Product Code: " + product_code);
System.out.println("Flavour: " + flavour);
System.out.println("Pack Type: " + pack_type);
System.out.println("Pack Size: " + pack_size);
System.out.println("Product Price: " + product_price);
}

public static void main(String args[])


{
FruitJuice obj = new FruitJuice();
obj.input();
obj.discount();
obj.display();
}
}
Output:-

Variable Name Data Type Function


product_code Integer stores the product code
number
flavour String stores the flavour of the
juice (e.g., orange, apple,
etc.)
pack_type String stores the type of
packaging (e.g., tera-
pack, PET bottle, etc.)
pack_size int stores package size (e.g.,
200 mL, 400 mL, etc.)
product_price int stores the price of the
product

5. Design a class to overload a function series( ) as follows:

1. double series(double n) with one double argument and returns the sum of the
series.
sum = (1/1) + (1/2) + (1/3) + ………. + (1/n)

2. double series(double a, double n) with two double arguments and returns the
sum of the series.sum = (1/a2) + (4/a5) + (7/a8) + (10/a11) + ………. to n terms
public class Series
{
double series(double n) {
double sum = 0;
for (int i = 1; i <= n; i++)
{
double term = 1.0 / i;
sum += term;
}
return sum;
}

double series(double a, double n)


{
double sum = 0;
int x = 1;
for (int i = 1; i <= n; i++)
{
int e = x + 1;
double term1 = x / Math.pow(a, e);
sum += term1;
x += 3;
}
return sum;
}

public static void main(String args[])


{
Series obj = new Series();
System.out.println("First series sum = " + obj.series(5));
System.out.println("Second series sum = " + obj.series(3, 8));
}
}
Variable Description:-
Variable Name Data Type Function
sum Double To initialize the variable sum
to 0
term Double To count the number of
terms
x Integer To initialize the variable x to
1
e Integer To calculate the sum of the
variable x and 1
term1 Double

Output:-
6. //WAP to design a class to overload a function polygon() as follows:
1 void polygon(int n, char ch) — with one integer and one character
type argument to draw a filled square of side n using the character stored
in ch.
2 void polygon(int x, int y) — with two integer arguments that draws a
filled rectangle of length x and breadth y, using the symbol '@'.
3 void polygon() — with no argument that draws a filled triangle..
public class Polygon
{
public void polygon(int n, char ch) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
System.out.print(ch);
}
System.out.println();
}
}

public void polygon(int x, int y) {


for (int i = 1; i <= x; i++) {
for (int j = 1; j <= y; j++)
{
System.out.print('@');
}
System.out.println();
}
}

public void polygon()


{
for (int i = 1; i <= 3; i++)
{
for (int j = 1; j <= i; j++)
{
System.out.print('*');
}
System.out.println();
}
}

public static void main(String args[])


{
Polygon obj = new Polygon();
obj.polygon(2, 'o');
System.out.println();
obj.polygon(2, 5);
System.out.println();
obj.polygon();
}
}
Output:-

Variable Description:-

Variable Name Data Type Function


n int To receive an integer
value from user
ch char To receive an character
value from user
x Int To receive an integer
value from user
y Int To receive an integer
value from user
i Int To calculate number of
rows by iterating
j int To calculate number of
columns iterating
7. //WAP by using a class name Calculate with the following specifications

Member Methods:

1. Calculate(int n) — to initialize num with n, f and rev with 0 (zero)


2. int prime() — to return 1, if number is prime
3. int reverse() — to return reverse of the number
4. void display() — to check and print whether the number is a prime palindrome
or not

import java.util.Scanner;

public class Calculate


{
private int num;
private int f;
private int rev;

public Calculate(int n) {
num = n;
f = 0;
rev = 0;
}

public int prime() {

f = 1;

if (num == 0 || num == 1)
f = 0;
else
for (int i = 2; i <= num / 2; i++) {
if (num % i == 0) {
f = 0;
break;
}
}

return f;
}

public int reverse() {

int t = num;

while (t != 0) {
int digit = t % 10;
rev = rev * 10 + digit;
t /= 10;
}

return rev;
}

public void display() {


if (f == 1 && rev == num)
System.out.println(num + " is prime palindrome");
else
System.out.println(num + " is not prime palindrome");
}

public static void main(String args[]) {

Scanner in = new Scanner(System.in);


System.out.print("Enter number: ");
int x = in.nextInt();

Calculate obj = new Calculate(x);


obj.prime();
obj.reverse();
obj.display();
}
}
Variable Description:-

Variable Name Data Type Function


num Integer To initialize the variable
num equal to n

f Integer To initialize the variable f


equal to 0

rev Integer To initialize the variable rev


equal to 0

T Integer To initialize the variable t


equal to num

digit Integer To find the quotient of the


variable t by 10

X Integer To print the number given


by the user as input

Output:-
Q8. //WAP to assign a full path and file name as given below. Using library functions,
extract and output the file path, file name and file extension separately as shown.

Input C:\Users\admin\Pictures\flower.jpg
Output Path: C:\Users\admin\Pictures\
File name: flower
Extension: jpg
import java.util.*;
public class path_8
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
String str,name="",exten="",path="";
int a=0,b=0;
System.out.println("Enter the String");
str = sc.nextLine();
a = str.lastIndexOf('\\');
b = str.lastIndexOf('.');
path = str.substring(0,a+1);
name = str.substring(a+1,b);
exten = str.substring(b+1);
System.out.println("Path : "+path);
System.out.println("File name: "+name);
System.out.println("File Extension : "+exten);
}
}
Output:-
Variable Description:-

Variable Name Data Type Function


str String To accept the entire path
name String To get the name of the file
exten String To get the extension of
the file
path String To get the path of the file
a Int To get the last index of
back slash
b int To get the last index of
period

9. //WAP in Java to accept a String in upper case and replace all the vowels
present in the String with Asterisk (*) sign.
Sample Input: "TATA STEEL IS IN JAMSHEDPUR"
Sample output: T*T* ST**L *S *N J*MSH*DP*R
import java.util.Scanner;

public class ReplaceVowels


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("Enter a string in uppercase:");
String str = in.nextLine();
String newStr = "";
int len = str.length();

for (int i = 0; i < len; i++) {


char ch = str.charAt(i);
if (ch == 'A' ||
ch == 'E' ||
ch == 'I' ||
ch == 'O' ||
ch == 'U') {
newStr = newStr + '*';
}
else {
newStr = newStr + ch;
}
}

System.out.println(newStr);
}
}

Variable Description:-

Variable Name Data Type Function


str String To take the word given by
the user as input
len Integer To calculate the length of
the word given by the user
newstr String To initialize a new created
string object so that it
represents the same
sequence of character
ch Character To return a character at a
specific position in a
string replacing the
original one
i Integer To enter into the loop
Output:-
10. //WAP to input integer elements into an array of size 20 and perform
the following operations:
(i) Display largest number from the array.
(ii) Display smallest number from the array.
(iii) Display sum of all the elements of the array.
import java.util.Scanner;

public class MinMaxSum


{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
int arr[] = new int[20];
System.out.println("Enter 20 numbers:");
for (int i = 0; i < 20; i++)
{
arr[i] = in.nextInt();
}
int min = arr[0], max = arr[0], sum = 0;
for (int i = 0; i < arr.length; i++)
{
if (arr[i] < min)
min = arr[i];

if (arr[i] > max)


max = arr[i];
sum += arr[i];
}

System.out.println("Largest Number = " + max);


System.out.println("Smallest Number = " + min);
System.out.println("Sum = " + sum);
}
}

Variable Description:-

Variable Name Data Type Function


arr[] Integer It creates an array
that is a collection
of similar type of
data items stored at
memory location
arr[i] Integer To print 20 elements
given by the user
continuously in the
next line
min Integer To print the elements
which the lowest value
max Integer To print the element
which has the highest
value
sum Integer To print the sum of
all the 20 element

Output:-
Q11. //WAP to generate a triangle or an inverted triangle based upon User’s choice.
Example 1:
Input: Type 1 for a triangle and Type 2 for an inverted triangle
Enter your choice 1 Enter a word : BLUEJ
Sample Output: if choice is 1 Output will be
B
LL
UUU
EEEE
JJJJJ
if choice is 2 Output will be
BLUEJ
BLUE
BLU
BL
B
import java.util.Scanner;
public class PatternedTraingle
{
public static void choosePattern()
{
Scanner sc = new Scanner(System.in);
System.out.println("Type 1 for triangle type 1");
System.out.println("Type 2 for triangle type 2");
System.out.print("Enter your choice: ");
int ch = sc.nextInt();
switch(ch)
{
case 1:
System.out.print("Enter your word: ");
String word1 = sc.next();
int n1=word1.length();
int k=0;
for(int i=0;i<=n1-1;i++)
{
for(int j=0;j<=k;j++)
{
System.out.print(word1.charAt(i));
}
System.out.println();
k++;
}
break;
case 2:
System.out.print("Enter your word: ");
String word = sc.next();
int n=word.length();
for(int i=n;i>=0;i--)
{
System.out.println(word.substring(0,i));
}
break;
default:
System.out.println("Wrong Choice");
break;
}
}
}
Output:-

Variable Description:-
Variable Name Data Type Function
ch Integer To accept choice from the
user
n1 Integer To find the length of the
word
Word1 Integer To accept the word
k Integer To calculate the number
of rows
i Integer To enter into loop
j Integer To calculate the number
of rows
word String To accept the word from
the user
n Integer To find the length of the
word
12. //WAP where a string is said to be ‘Unique’ if none of the letters present
in the string are repeated. Write a program to accept a string and check
whether the string is Unique or not. The program displays a message
accordingly.
Sample Input: COMPUTER
Sample Output: Unique String
import java.util.Scanner;

public class UniqueString


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter a string: ");
String str = in.nextLine();
str = str.toUpperCase();
boolean isUnique = true;
int len = str.length();

for (int i = 0; i < len; i++) {

char ch = str.charAt(i);

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


if (ch == str.charAt(j)) {
isUnique = false;
break;
}
}

if (!isUnique)
break;
}

if (isUnique)
System.out.println("Unique String");
else
System.out.println("Not Unique String");
}
}

Variable Description:-

Variable name Variable type Description


str String To accept the word
from the user
len int To find the length of the
word
IsUnique boolean To check whether the
word is unique or not
i int To enter into for loop
j int To check if a character
repeats itself
ch char To get every character
in the word

Output:-
13. //WAP using the switch statement, write a menu driven program for
the following:
(a) To print the Floyd’s triangle:
(b) To display the following pattern:
I
IC
ICS
ICSE
For an incorrect option, an appropriate error message should be displayed.

import java.util.Scanner;

public class Pattern


{
public void choosePattern() {
Scanner in = new Scanner(System.in);
System.out.println("Type 1 for Floyd's triangle");
System.out.println("Type 2 for an ICSE pattern");

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


int ch = in.nextInt();

switch (ch) {
case 1:
int a = 1;
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(a++ + "\t");
}
System.out.println();
}
break;

case 2:
String s = "ICSE";
for (int i = 0; i < s.length(); i++) {
for (int j = 0; j <= i; j++) {
System.out.print(s.charAt(j) + " ");
}
System.out.println();
}
break;

default:
System.out.println("Incorrect Choice");
}
}
}
Output:-

Variable Description:-

Variable Name Variable Type Description


ch int To accept choice from
the user
a int To set the 1st value for
the Floyd’s triangle
i int To enter into loop

j int To increment the value


s String To store the string
‘ICSE’
14. //WAP to accept the year of graduation from school as an integer value from the
user. Using the Binary Search technique on the sorted array of integers given below,
output the message “Record exists” if the value input is located in the array. If not,
output the message “Record does not exist”. {1982, 1987, 1993, 1996, 1999, 2003,
2006, 2007, 2009, 2010}
import java.util.Scanner;

public class GraduationYear


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int n[] = {1982, 1987, 1993, 1996, 1999, 2003, 2006, 2007, 2009, 2010};

System.out.print("Enter graduation year to search: ");


int year = in.nextInt();

int l = 0, h = n.length - 1, idx = -1;


while (l <= h) {
int m = (l + h) / 2;
if (n[m] == year) {
idx = m;
break;
}
else if (n[m] < year) {
l = m + 1;
}
else {
h = m - 1;
}
}

if (idx == -1)
System.out.println("Record does not exist");
else
System.out.println("Record exists");
}
}
Variable Description:-

Variable name Variable type Description


n int To store the years
year int To accept year
I int To set a condition
h int To find the length of n
m int To find the middle term
idx int To set as flag

Output:-

15. //WAP to input two characters from the keyboard. Find the difference
(d) between their ASCII codes. Display the following messages: If d=0 : both
the characters are same. If d<0 : first character is smaller. If d>0 : second
character is smaller.
Sample Input : D P
Sample Output : d= (68-80) = -12 First character is smaller

import java.util.Scanner;
public class PerfectSquare_17
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
System.out.print("Enter first number: ");
int a = in.nextInt();
System.out.print("Enter second number: ");
int b = in.nextInt();
if (a < 0 || b < 0)
{
System.out.println("Square root of a negative number can't be determined");
}
else
{
double sqrtA = Math.sqrt(a);
double sqrtB = Math.sqrt(b);
double isAPerfectSq = sqrtA - Math.floor(sqrtA);
double isBPerfectSq = sqrtB - Math.floor(sqrtB);

if (isAPerfectSq == 0 &&isBPerfectSq == 0)
{
System.out.println("They are perfect square numbers.");
}
else if (isAPerfectSq == 0)
{
System.out.println(a + " is a perfect square number.");
System.out.println(b + " is not a perfect square number.");
}
else if (isBPerfectSq == 0)
{
System.out.println(a + " is not a perfect square number.");
System.out.println(b + " is a perfect square number.");
}
else
{
System.out.println("Both are not perfect square numbers.");
}
}
}
}
  Output:-

Variable Description:-

Variable name Variable type Description


d int To calculate the
difference
a int To accept a character

b int To accept a character


ch1 int To covert the value of a
into ASCII
ch2 int To covert the value of b
into ASCII

16. //WAP that encodes a word into Pig latin. To translate word into Pig latin word,
convert the word into uppercase and then place the first vowel of the original word as
the start of the new word along with the remaining alphabets. The alphabets present
before the vowel being shifted towards the end followed by "AY".

Sample Input 1: London


Output: ONDONLAY

Sample Input 2: Olympics


Output: OLYMPICSAY
import java.util.Scanner;

public class PigLatin


{
public static void main(String args[]) {

Scanner in = new Scanner(System.in);


System.out.print("Enter word: ");
String word = in.next();
int len = word.length();

word=word.toUpperCase();
String piglatin="";
int flag=0;

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


{
char x = word.charAt(i);
if(x=='A' || x=='E' || x=='I' || x=='O' || x=='U')
{
piglatin=word.substring(i) + word.substring(0,i) + "AY";
flag=1;
break;
}
}

if(flag == 0)
{
piglatin = word + "AY";
}
System.out.println(word + " in Piglatin format is " + piglatin);
}
}

Variable Description:-

Variable Name Variable Type Description


word String To accept a word from
the user
len int To calculate number of
characters
piglatin String To output the piglatin
number
flag int To use as a counter
x char To compare each
character with vowel
i int To enter into for loop
  Output:-

17. //WAP to input two unequal positive numbers and check whether they
are perfect square numbers or not. If the user enters a negative number
then the program displays the message 'Square root of a negative number
can't be determined'.
Sample Input: 81, 100
Sample Output: They are perfect square numbers.
Sample Input: 225, 99
Sample Output: 225 is a perfect square number. 99 is not a perfect square
number.
import java.util.Scanner;

public class PerfectSquare


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter first number: ");
int a = in.nextInt();
System.out.print("Enter second number: ");
int b = in.nextInt();

if (a < 0 || b < 0) {
System.out.println("Square root of a negative number can't be
determined");
}
else {
double sqrtA = Math.sqrt(a);
double sqrtB = Math.sqrt(b);
double isAPerfectSq = sqrtA - Math.floor(sqrtA);
double isBPerfectSq = sqrtB - Math.floor(sqrtB);

if (isAPerfectSq == 0 && isBPerfectSq == 0) {


System.out.println("They are perfect square numbers.");
}
else if (isAPerfectSq == 0) {
System.out.println(a + " is a perfect square number.");
System.out.println(b + " is not a perfect square number.");
}
else if (isBPerfectSq == 0) {
System.out.println(a + " is not a perfect square number.");
System.out.println(b + " is a perfect square number.");
}
else {
System.out.println("Both are not perfect square numbers.");
}
}
}
}
Output:-
 
 

Variable Description:-
Variable name Variable type Description
a int To accept a number from
the user
b int To accept another number
from the user
sqrtA double To find the square root of a

sqrtB double To find the square root of b

isAPerfectSq double To convert a to math.floor


value
isBPerfectSq double To covert b to math.floor
value

18. //WAP to input marks in English, Maths and Science of 40 students who
have passed ICSE Examination 2014. Now, perform the following tasks:
(a) Number of students, who have secured 95% or more in all the subjects.
(b) Number of students, who have secured 90% or more in English, Maths
and Science.
import java.util.Scanner;

public class ExamResult


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int ta = 0, te = 0, tm = 0, ts = 0;
for (int i = 1; i <= 40; i++) {
System.out.println("Enter marks of student " + i);
System.out.print("English: ");
int eng = in.nextInt();
System.out.print("Maths: ");
int maths = in.nextInt();
System.out.print("Science: ");
int sci = in.nextInt();

if (eng >= 95 && maths >= 95 && sci >= 95)


ta++;

if (eng >= 90)


te++;

if (maths >= 90)


tm++;

if (sci >= 90)


ts++;
}
System.out.println("No. of students >= 95% in all subjects: " +
ta);
System.out.println("No. of students >= 90% in English: " + te);
System.out.println("No. of students >= 90% in Maths: " + tm);
System.out.println("No. of students >= 90% in Science: " + ts);
}
}
Variable Description:-
Variable Name Data Type Function
te Integer To take the marks of English
as input
tm Integer To take the marks of
Mathematics as input
ts Integer To take the marks of Science
as input
ta Integer Tom count the no. of times
the loop will run
Output:-

19. Write a menu driven program to accept a number from the user and
check whether it is a Prime number or an Automorphic number.
(a) Prime number: (A number is said to be prime, if it is only divisible by 1
and itself) Example: 3,5,7,11
(b) Automorphic number: (Automorphic number is the number which is
contained in the last digit(s) of its square.) Example: 25 is an Automorphic
number as its square is 625 and 25 is present as the last two digits.
import java.util.Scanner;
public class PrimeOrAuto_19
{
public static void main(String args[])
{
int i,ch,num,C=0;
Scanner sc=new Scanner(System.in);
System.out.println("***************MENU***************");
System.out.println("Type 1 to check if the number is a Prime Number");
System.out.println("Type 2 to check if the number is an Automorphic
Number");
ch = sc.nextInt();
switch(ch)
{
case 1:
System.out.println("Enter the number: ");
num=sc.nextInt();
for(i=1;i<=num;i++)
{
if(num%i==0)
{
C++;
}
}
if(C==2)
{
System.out.println("It is a Prime Number");
}
else
{
System.out.println("It is not a Prime Number");
}
break;
case 2:
System.out.println("Enter the number");
int number = sc.nextInt();
int A=0, square = number*number;
int dot = number;
while(dot>0)
{
A++;
dot=dot/10;
}
int LSQ = (int) (square%(Math.pow(10,A)));
if(number == LSQ)
{
System.out.println("It is an Automorphic Number");
}
else
{
System.out.println("It is not an Automorphic Number");
}
break;
default:
System.out.println("Wrong Choice");
}
}
}

Output:-
Variable Description:-

Variable Name Variable Type Description


i int To enter into loop
ch int To accept a choice
num int To accept a number
C int To act as a counter
A int To act as a counter
number int To accept a number
square int To find the square of
the number
dot int To be passed with the
value of number
LSQ int To find if the number is
automorphic or not

20. Using a switch statement, write a menu driven program to:


(a) generate and display the first 10 terms of the Fibonacci series
     0, 1, 1, 2, 3, 5
The first two Fibonacci numbers are 0 and 1, and each subsequent number is the sum
of the previous two.

(b) find the sum of the digits of an integer that is input by the user.
Sample Input: 15390
Sample Output: Sum of the digits = 18
For an incorrect choice, an appropriate error message should be displayed
import java.util.Scanner;

public class FibonacciNDigitSum


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("1. Fibonacci Series");
System.out.println("2. Sum of digits");
System.out.print("Enter your choice: ");
int ch = in.nextInt();

switch (ch) {
case 1:
int a = 0, b = 1;
System.out.print(a + " " + b);

for (int i = 3; i <= 10; i++) {


int term = a + b;
System.out.print(" " + term);
a = b;
b = term;
}
break;

case 2:
System.out.print("Enter number: ");
int num = in.nextInt();
int sum = 0;
while (num != 0) {
sum += num % 10;
num /= 10;
}
System.out.println("Sum of Digits " + " = " + sum);
break;

default:
System.out.println("Incorrect choice");
break;
}
}
}
Output:-
Variable Description:-
Variable name Variable type Description
ch int To accept choice from
the user
a int Predefined value for
the Fibonacci series
b int Predefined value for
the Fibonacci series
i int To enter into loop
term int To get the sum of
previous number
num int To accept a number
sum int To find the sum of the
numbers
Chemistry Project
File
Divine Mercy School

Name-Araman Kumar Parida

Class-10 Section-A

Registration Number- 161

UID-7526233

Session- 2021-2022
Physics Project
File
Divine Mercy School

Name-Araman Kumar Parida

Class-10 Section-A

Registration Number- 161

UID-7526233

Session- 2021-2022
Mathematics Project
File

Divine Mercy School

Name-Araman Kumar Parida

Class-10 Section-A

Registration Number- 161

UID-7526233

Session- 2021-2022

You might also like