Computer Project Class 10 Finale
Computer Project Class 10 Finale
(2023-2024)
CLASS:10 E
COMPUTER CODE:130768
ROLL NO. : 28
Assignment 1-20
THE BISHOP’S CO-ED SCHOOL
KALYANINAGAR,PUNE
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
int sumOfSquares = 0;
int digit;
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;
array[i][j] = input.nextInt();
if (array[i][j] == numberToFind) {
isPresent = true;
break;
if (isPresent) {
} else {
}
}
Output window :
matrix[i][j] = input.nextInt();
}
if (matrix[i][j] % 2 == 0) {
hasEvenNumbers = true;
if (!hasEvenNumbers) {
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.
if (i % 2 != 0) {
sum += i;
return sum;
int sum = 0;
if (i % 2 != 0) {
sum += i;
return sum;
int A = 3; //random values of A and B ASSIGNED FOR CALCULATION AND DISPLAY IN OUTPUT
int B = 15;
System.out.println("Sum of odd numbers between " + A + " and " + B + " is: " + result);
int A = 3;
int B = 15;
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.
ASSIGNMENT 12 :
public Area() {
length = 0.0f;
breadth = 0.0f;
length = l;
breadth = b;
length = side;
breadth = side;
rectangle.display_1();
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);
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 :
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;
System.out.println("\nWord\tFrequency of Vowels");
System.out.println(" “);
int i = 0;
while (i < length) {
i++;
}
int end = i;
}
private static int countVowels(String word) {
int count = 0;
String vowels = "aeiouAEIOU";
count++;
}
}
return count;
}
}
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();
}
}