[go: up one dir, main page]

0% found this document useful (0 votes)
2 views29 pages

Computer Project Class 10 Finale

The document outlines a computer applications project for Class 10 E at The Bishop's Co-Ed School, including various assignments focused on Java programming concepts such as encapsulation, loops, arrays, user-defined methods, constructors, and library classes. Each assignment contains questions and answers, along with Java code examples to illustrate the concepts. The project serves as a revision of the Class 9 syllabus and includes practical coding exercises.
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)
2 views29 pages

Computer Project Class 10 Finale

The document outlines a computer applications project for Class 10 E at The Bishop's Co-Ed School, including various assignments focused on Java programming concepts such as encapsulation, loops, arrays, user-defined methods, constructors, and library classes. Each assignment contains questions and answers, along with Java code examples to illustrate the concepts. The project serves as a revision of the Class 9 syllabus and includes practical coding exercises.
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/ 29

ICSE COMPUTER APPLICATIONS PROJECT

(2023-2024)
CLASS:10 E

COMPUTER CODE:130768
ROLL NO. : 28

Assignment 1-20
THE BISHOP’S CO-ED SCHOOL
KALYANINAGAR,PUNE

Name: SHAFQUAT MULLA


ASSIGNMENT 1:
Assignment 1: Revision of class 9 Syllabus

a.In what way is Encapsulation and Data Abstraction interrelated?

Ans. Abstraction and encapsulation are complementary concepts.


Abstraction focuses upon the observable behaviour of an object, whereas
encapsulation focuses upon the implementation that gives rise to this
behaviour. Encapsulation is most often achieved through information
hiding, which is the process of hiding all the secrets of an object that do
not contribute to its essential characteristics, the structure of an object is
hidden, as well as the implementation of its methods. Only the essential
characteristics of object are visible.
Thus, encapsulation is a way to implement data abstraction.
Encapsulation hides the details of the implementation of an object.

b.What is a variable?
Ans. In Java,the data holders that save the data values during the
execution of a Java program are called variables.

ASSIGNMENT 2:
Revision of class 9 Syllabus

a. What is an exit-controlled loop?

Ans. An exit-controlled loop is a type of Loop in Java


computer programming that tests the loop condition at
the end of the Loop after executing the body of the
Loop at least once.

b.Write a Java Expression for the following: Z = u^2 +


v^2 + 2at^2

Ans. Z= (Math.pow(u, 2) + Math.pow(v, 2) +


Math.sqrt(2*a*t*t));
ASSIGNMENT 3:
Assignment 3: Revision of class 9 Syllabus
Write a Java program to input a number. Calculate and display the norm of a
number.
[Hint: Norm of a number is square root of sum of squares of all digits of the
number.
Example: The norm of 68 is 10 6×6 + 8×8 = 36+64 = 100 square root of 100 is
10.
Ans. Program code :
import java.util.Scanner;

public class ShafquatMulla10E {

public static void main(String[] args) {


Scanner input = new Scanner(System.in);
System.out.print("Enter a number: ");
int number = input.nextInt();
input.close();

int sumOfSquares = 0;
int digit;

// Calculate the sum of squares of all digits of the number


while (number != 0) {
digit = number % 10;
sumOfSquares += digit * digit;
number /= 10;
}

// Calculate the norm (square root of the sum of squares)


double norm = Math.sqrt(sumOfSquares);

System.out.println("The norm of the number is: " + norm);


}
}

Output window:

ASSIGNMENT 4: ARRAYS
a. State the output for the following snippet:
int P[ ] [ ] = {{5,10, 15,20,25},<4,8, 12,16,20},{3,6,9, 12,15 }};
for(int i=0;1<4;++)
{
for(int j=0;j<5;++)
{
System.out.print(P[i]Li]+" ");
System.out.printin);
}

Ans.
The expected output will be :

5 10 15 20 25
4 8 12 16 20
3 6 9 12 15

ASSIGNMENT 5: ARRAYS
a.What is a subscripted variable?
Ans. In Java, a subscripted variable refers to an element of an array
accessed using an index (also known as a subscript).

b.Write a Java statement to declare an array of size 4X4 which stores real
numbers.
Ans.
double[][] realNumbersArray = new double[4][4];

ASSIGNMENT 6: ARRAYS
a.Write a Java program to input integers in a 3X3
array. Enter a number and check if it is present in the
array. Display if its present or not.
Ans. Program code:
import java.util.Scanner;

public class ShafquatMulla10E {

public static void main(String[] args) {

int[][] array = new int[3][3];

Scanner input = new Scanner(System.in);

// Input integers into the 3x3 array

System.out.println("Enter integers for the 3x3 array:");

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

for (int j = 0; j < 3; j++) {

System.out.print("Enter value for element at index [" + i + "][" + j + "]: ");

array[i][j] = input.nextInt();

System.out.print("Enter the number to check if it's present in the array: ");

int numberToFind = input.nextInt();

boolean isPresent = false;

// Check if the number is present in the array

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

for (int j = 0; j < 3; j++) {

if (array[i][j] == numberToFind) {

isPresent = true;

break;

// Display if the number is present or not

if (isPresent) {

System.out.println("The number " + numberToFind + " is present in the array.");

} else {

System.out.println("The number " + numberToFind + " is NOT present in the


array.");

}
}

Output window :

b.Write a Java program to input integers in a 3X3 matrix in a 2-


dimensional array. Display only the even numbers if present in the
array.
Ans. Program code:
import java.util.Scanner;

public class ShafquatMulla10E {

public static void main(String[] args) {

int[][] matrix = new int[3][3];

Scanner input = new Scanner(System.in);

// Input integers into the 3x3 matrix

System.out.println("Enter integers for the 3x3 matrix:");

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

for (int j = 0; j < 3; j++) {

System.out.print("Enter value for element at index [" + i + "][" + j + "]: ");

matrix[i][j] = input.nextInt();
}

System.out.println("Even numbers in the matrix:");

// Display even numbers in the matrix

boolean hasEvenNumbers = false;

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

for (int j = 0; j < 3; j++) {

if (matrix[i][j] % 2 == 0) {

System.out.print(matrix[i][j] + " ");

hasEvenNumbers = true;

if (!hasEvenNumbers) {

System.out.print("No even numbers found in the matrix.");

Output window :
ASSIGNMENT 7: USER DEFINED METHOD
a. State the output for the following snippet of code:
public static void Q1(int n)
for (int x = n: x > = 1; x--)
{
if (n% × == 0)
System.out.printIn(x);
}
} // Assume n= 15
Ans. Output
15

Output window:
Assignment 8: User Defined Method
Differentiate between Pure methods and Impure methods.
Ans.
- Pure methods: These are methods that do not modify the state of the
program and produce the same output for the same input. They have no
side effects and are predictable.

- Impure methods: These are methods that may modify the state of the
program or have side effects. They may produce different output for the
same input and are less predictable.

b.Explain return datatype with respect to Function prototype.


Ans. The return data type in the function prototype of a Java method
specifies the type of value that the method will return when it is called. It
defines what kind of data the method will provide as its result. The return
data type is declared before the method name in the function prototype
and helps ensure that the method returns the correct type of value.

ASSIGNMENT 9: USER DEFINED METHOD


a.Design a class to overload a function Sum () as follows :
a.int Sum (int A, int B) - with two integer arguments (A and B) calculate and
return sum of all the odd numbers in the range of A and B.
Sample input: A=3 and B=15
Sample output: sum = 3+5+7+9+11+13+15
Ans. Program code :
public class ShafquatMulla10E {

// Method to calculate the sum of odd numbers in the range of A and B

public int Sum(int A, int B) {


int sum = 0;

for (int i = A; i <= B; i++) {

if (i % 2 != 0) {

sum += i;

return sum;

// Main method to invoke the Sum() function

public static void main(String[] args) {

public class ShafquatMulla10E {

// Method to calculate the sum of odd numbers in the range of A and B

public int Sum(int A, int B) {

int sum = 0;

for (int i = A; i <= B; i++) {

if (i % 2 != 0) {

sum += i;

return sum;

// Main method to invoke the Sum() function

public static void main(String[] args) {

ShafquatMulla10E obj = new ShafquatMulla10E();

int A = 3; //random values of A and B ASSIGNED FOR CALCULATION AND DISPLAY IN OUTPUT

int B = 15;

int result = obj.Sum(A, B);

System.out.println("Sum of odd numbers between " + A + " and " + B + " is: " + result);

}ShafquatMulla10E obj = new ShafquatMulla10E();

int A = 3;

int B = 15;

int result = obj.Sum(A, B);

System.out.println("Sum of odd numbers in the range of " + A + " and " + B + " is: " + result);
}

Output window:

b. double Sum (double N) - with one double arguments(N) calculate and return
the product of the following series:
sum= 1.0 x 1.2 x 1.4 x ………….. x N
Write the main method to create an object and invoke the methods.
Ans. Program code :
public class ShafquatMulla10E {
// Overloaded method to calculate the product of the series 1.0 x 1.2 x 1.4 x ...
xN
public double Sum(double N) {
double sum = 1.0;
for (double i = 1.0; i <= N; i += 0.2) {
sum *= i;
}
return sum;
}
public static void main(String[] args) {
ShafquatMulla10E obj = new ShafquatMulla10E();
double number = 5.0; //random value for “N” for calculation
double result = obj.Sum(number);
System.out.println("The product of the series 1.0 x 1.2 x 1.4 x ... x " +
number + " is: " + result);
}
}

Output window :
ASSIGNMENT 10: CONSTRUCTOR
a.Define a constructor.
Ans.
A constructor in Java is a special method that is automatically called when an object
of a class is created. It is used to initialize the object's state and perform any
necessary setup tasks.

b.Explain how a Constructor is different from a method.


Ans.
A constructor in Java is different from a method, constructors are specifically used
for object initialization, have the same name as the class, and are automatically
called when an object is created. On the other hand, methods have various names,
are explicitly called, and define the behavior and actions of objects or classes.

ASSIGNMENT 11: CONSTRUCTOR


a.Mention any 4 features of a Constructor.

❖ Initialize object state: Constructors are used to set


initial values to the instance variables of the object.
❖ Handle object creation: Constructors are
automatically called when an object is created using the
`new` keyword.
❖ Overloading: Java allows constructors to be
overloaded, meaning a class can have multiple
constructors with different parameter lists.
❖ Access Modifiers: Constructors can have access
modifiers like `public`, `private`, `protected`, or package-
private to control their visibility and accessibility.
b.Differentiate between Parameterized and Non-
parameterized constructors.
Ans.
❖ - Parameterized Constructor: It is a constructor that
accepts parameters, allowing you to pass values to initialize
the object's state during object creation.

❖ - Non-Parameterized Constructor (Default Constructor):


It is a constructor that does not accept any parameters and
provides default initialization for the object's state. It is
automatically provided by Java if no other constructors are
defined in the class.

ASSIGNMENT 12 :

Q.Create a class having the following specification:


Class name - Area
Data members: float length, breadth
Member Methods:
Area(): default constructor to initialize length and breadth
void A1 (float I, float b): assigns length with I and breadth
with b for a rectangle. void A1 (float I): assigns length with I
for a square void display_1 (): calculate and display the area
of the rectangle. void display_2 (: calculate and display the
area of the square.

Ans. (Program code )


public class Area {

private float length;

private float breadth;

public Area() {

length = 0.0f;

breadth = 0.0f;

// Method to assign values for a rectangle

public void A1(float l, float b) {

length = l;

breadth = b;

// Method to assign values for a square

public void A1(float side) {

length = side;

breadth = side;

// Method to calculate and display the area of the rectangle

public void display_1() {

float area = length * breadth;

System.out.println("Area of the rectangle: " + area);

// Method to calculate and display the area of the square

public void display_2() {

float area = length * length;

System.out.println("Area of the square: " + area);

public static void main(String[] args) {

Area rectangle = new Area();

rectangle.A1(5.0f, 3.0f); //random values assigned for calculation purposes

rectangle.display_1();

Area square = new Area();


square.A1(4.0f); ); //random values assigned for calculation purposes

square.display_2();

OUTPUT WINDOW :

ASSIGNMENT 13:
Q. Library Class
1. State the use of the following functions:
Double.toString()
il.
Integer. valueOf()
2. State the output for the following snippet:
3.
char ch = 'X';
char chr = Character.toLowerCase(ch);
int n = (int)chr-32;
System.out.printin((char)n + "It" + chr);
Ans.
i. Double.toString():
This function is used to convert a double value to a
String.
Example: double value = 3.14; String str =
Double.toString(value);

ii. Integer.valueOf():
This function is used to convert a String to an int.
Example: String str = "123"; int number =
Integer.valueOf(str);

3.

Output:
char ch = 'X';
char chr = Character.toLowerCase(ch);
int n = (int)chr-32;
System.out.printin((char)n + "It" + chr);

The output of the following should be:

XItx
Assignment 14: Library Class
Write a Java program to input a character and count the number
of special characters entered. Terminate when the user enters an
alphabet or a digit. Display the count of special characters.

Program code:
import java.util.Scanner;
public class SpecialCharacterCounter {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int specialCharacterCount = 0;
System.out.println("Enter characters. To stop, enter an alphabet or
a digit.");
while (true) {
String input = scanner.next();
if (input.length() != 1) {
System.out.println("Please enter only one character at a time.");
continue;
}
char ch = input.charAt(0);
if (Character.isLetter(ch) || Character.isDigit(ch)) {
break; // Terminate the loop if an alphabet or a digit is entered
} else {
specialCharacterCount++;
}
}
System.out.println("Number of special characters entered: " +
specialCharacterCount);
}
}

OUTPUT WINDOW :

Assignment 15: String Manipulations in


Java
State the output for the for the following snippet of code:
1. String txt = "Please locate where 'locate' occurs!";
System.out.printIn(txt.indexOf("locate"));
2.String s= "12".
int m =Integer.parseInt(s);
m = m + 1000;
System.out.printIn(m);
Output:
1. 7
2. 1012
Program window :

Output window:
Assignment 16: String Manipulations in
Java
State the purpose and return type of the following
String functions:
1.lastIndexOf () :
Purpose: The lastIndexOf() method in Java is used
to find the index of the last occurrence of a
specified substring or character within the given
string.
Return Type: It returns an integer representing the
index of the last occurrence of the specified
substring or character. If the substring is not
found, it returns -1.

2.equals()
Purpose: The equals() method is used to compare
the contents of two strings to check if they are
equal.
Return Type: It returns a boolean value - true if the
strings are equal, and false otherwise.
ASSIGNMENT 17 : STRING MANIPULATIONS
IN JAVA
Q. Write Java program to accept a sentence in mixed case.
Find the frequency of vowels in each word and print the
word along with their frequencies on separate lines.
Program code :
Code :
import java.util.Scanner;

public class VowelFrequency {


public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);


System.out.println("Enter a sentence in mixed case:");

String sentence = scanner.nextLine()

System.out.println("\nWord\tFrequency of Vowels");
System.out.println(" “);

int length = sentence.length();

int i = 0;
while (i < length) {

while (i < length && sentence.charAt(i) == ' ') {


i++;
}

// Find the end of the current word


int start = i;

while (i < length && sentence.charAt(i) != ' ') {

i++;
}

int end = i;

if (start < end) {


String word = sentence.substring(start, end);

int vowelFrequency = countVowels(word);

System.out.println(word + "\t" + vowelFrequency);


}

}
private static int countVowels(String word) {

int count = 0;
String vowels = "aeiouAEIOU";

for (int i = 0; i < word.length(); i++) {


char ch = word.charAt(i);
if (vowels.indexOf(ch) != -1) {

count++;

}
}

return count;

}
}

Sample input & output :


ASSIGNMENT 18:
Class as a Basis of all Computations

• How are private members of a class different


from public members?
• Ans. Private Members vs. Public Members:
Private: Members are only accessible within the
class they are declared.
Public: Members can be accessed from any part of
the program, including external code.

• Differentiate between static members and non-


static members.
• Ans. Static Members vs. Non-Static Members:
Static: Belongs to the class itself, shared among all
instances of the class. Accessed using the class
name.
Non-Static (Instance): Belongs to instances of the
class. Each instance has its own copy. Accessed
using object references.
ASSIGNMENT 19:
Class as a Basis of all Computations
Q. Explain the terms:
1. Class Variables :
• Class variables are shared attributes
declared with the static keyword within
a class, making them accessible across
all instances of that class. They are
typically accessed using the class name.

2. Instance Variables :
• Instance variables are unique attributes
declared within a class, each instance of
the class having its own set of these
variables. They are accessed using object
references.
Assignment 20: Class as a Basis of all
Computations
Write a Java program by using class with the following
specifications:
Class Name: Check
Data Members:
String str
Member Methods:
void input (String s): to assign s to str void check print):to check
and print the following :
1.Number of letters
2.Number of special characters
3.Number of digits

PROGRAM CODE:
import java.util.Scanner;
public class Check {
String str;
void input(String s) {
str = s;
}
void checkAndPrint() {
int lettersCount = 0;
int specialCharsCount = 0;
int digitsCount = 0;
for (char ch : str.toCharArray()) {
if (Character.isLetter(ch)) {
lettersCount++;
} else if (Character.isDigit(ch)) {
digitsCount++;
}
specialCharsCount++;
}
}
System.out.println("Number of letters: " + lettersCount);
System.out.println("Number of special characters: " +
specialCharsCount);
System.out.println("Number of digits: " + digitsCount);
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Create an object of the Check class
Check checkObject = new Check();
// Input a string
System.out.println("Enter a string:");
String inputString = scanner.nextLine();
// Assign the input string to the class member
checkObject.input(inputString);
// Check and print the counts
checkObject.checkAndPrint();
}
}

Sample input & output:


Prajakta Bhambal, my computer


applications teacher, for her invaluable
guidance and encouragement throughout
my project assignment. Gratitude to my

fostering a conducive learning environment.


Your collective support has been
instrumental, and I am sincerely thankful

You might also like