The Programming Project

Sunday, January 8, 2023

ICSE Java Programming Equal and Uppercase strings 2022 Q5 SPECIMEN PAPER Solved

ICSE Java Programming Equal and Uppercase strings  2022 Q4 SPECIMEN PAPER Solved

Question 5

Define a class to accept two strings, convert them into uppercase, check and display whether two strings are equal or not, if the two strings are not equal, print the string with the highest length or print the message both the strings are of equal length.




import java.util.Scanner;

public class ICSEJava {
    public static void main(String[] args) {
        StringCheck obj = new StringCheck();
        obj.inputString();
        obj.display();

    }
}

class StringCheck {
    public void display() {
        if (this.isequal)
            System.out.println("Both the strings are equal");
        else
            System.out
                    .println(" String with highest length :"
                            + (this.message_first.length() < this.message_second.length()
                                    ? this.message_second
                                    : this.message_first));
    }

    public void inputString() {
        Scanner in = new Scanner(System.in);
        System.out.println("Enter the first string:");
        this.message_first = in.nextLine();
        System.out.println("Enter the second string:");
        this.message_second = in.nextLine();
        System.out.println("OUTPUT:");
        System.out.println(this.toUpperCase(this.message_first));
        System.out.println(this.toUpperCase(this.message_second));
        if (!this.message_first.equals(this.message_second))
            this.isequal = false;
        in.close();
    }

    private String toUpperCase(String msg) {
        String temp = "";
        for (int i = 0; i < msg.length(); i++) {
            if (msg.charAt(i) >= 'a' && msg.charAt(i) <= 'z') {
                temp += (char) (msg.charAt(i) - 32);
            } else
                temp += (msg.charAt(i));
        }
        return temp;
    }

    StringCheck() {
        this.message_first = "";
        this.message_second = "";
        this.isequal = true;
    }

    private boolean isequal;
    private String message_first;
    private String message_second;

}

Thursday, January 5, 2023

ICSE Java Programming Array of Numbers 2022 Q4 SPECIMEN PAPER Solved

ICSE Java Programming Array of Numbers 2022 Q4 SPECIMEN PAPER Solved

Question 4

Define a class to declare an array of size 20 of double datatype, accept the elements into the array and perform the following:

Calculate and print the sum of all the elements.

Calculate and print the highest value of the array.



Python Code (Without using class)

_array = []
array_size = 20
max_element = 0.0
sum = 0.0
print("Enter the elements in the array:")
for i in range(array_size):
    print("Enter the element at the position:",(i+1))
    _array.append(float(input()))
    sum += _array[i]
    if max_element < _array[i]:
        max_element = _array[i]
print("Sum of all the elements is ",sum)
print("Maximum element in the array ",max_element)

JAVA CODE

import java.util.Scanner;

public class ICSEJava {
    public static void main(String[] args) {
        Array obj = new Array();
        obj.inputArray();
        obj.sumOfElements();
        obj.maxElement();
    }
}

class Array {
    public void inputArray() {
        Scanner in = new Scanner(System.in);
        System.out.println("Enter the elements of the array:");
        for (int i = 0; i < this.array_size; i++) {
            System.out.println("Enter the element:");
            this.array[i] = in.nextDouble();
        }
        in.close();
    }

    public void maxElement() {
        for (int i = 0; i < this.array_size; i++)
            if (this.max_element < this.array[i])
                this.max_element = this.array[i];
        System.out.println("Maximum element in the array " + this.max_element);
    }

    public void sumOfElements() {
        for (int i = 0; i < this.array_size; i++)
            this.sum += this.array[i];
        System.out.println("Sum of all the elements is " + this.sum);
    }

    Array() {
        this.sum = 0;
        this.max_element = 0;
    }

    private double[] array = new double[20];
    private double sum;
    private double max_element;
    private static int array_size = 20;
}

Wednesday, January 4, 2023

ICSE Java Programming Character Array 2022 Q3 Specimen Paper Solved

  ICSE Java Programming Character Array  2022 Q3 Solved


PYTHON CODE

char_array = []
array_size = 10
upper_counter = 0
vowel_counter = 0
vowel =['A', 'E', 'I', 'O', 'U' ]
print("Enter the characters in the array:")
for i in range(array_size):
    print("Enter the element at the position:",(i+1))
    char_array.append(str(input()))
for i in range(array_size):
    if char_array[i] >= 'A' and char_array[i] <= 'Z':
        print(char_array[i]," is an upper case character.")
        upper_counter +=1
for i in range(array_size):
    for j in range(5):
        if char_array[i] == vowel[j] or str(char_array[i]).upper() == vowel[j]:
            print(char_array[i]," is an vowel.")
            vowel_counter +=1
print("Total number of uppercase characters =",upper_counter)
print("Total number of vowels =",vowel_counter)


JAVA CODE

import java.util.Scanner;

public class ICSEJava2022 {
    public static void main(String[] args) {
        characterArray obj = new characterArray();
        obj.input();
        obj.display();
    }
}

class characterArray {
    public void display() {
        for (int i = 0; i < this.array_size; i++) {
            if (this.char_array[i] >= 65 && this.char_array[i] <= 90) {
                System.out.println(this.char_array[i] + " is an upper case character.");
                this.upper_counter++;
            }
            for (int j = 0; j < 5; j++)
                if (this.char_array[i] == this.vowel[j] || (char) (this.char_array[i] - 32) == this.vowel[j]) {
                    System.out.println(this.char_array[i] + " is an vowel.");
                    this.vowel_counter++;
                }
        }
        System.out.println("Total number of upper case characters =" + this.upper_counter);
        System.out.println("Total number of vowels =" + this.vowel_counter);
    }

    public void input() {
        Scanner in = new Scanner(System.in);
        System.out.println("Enter the characters in the array:");
        for (int i = 0; i < this.array_size; i++) {
            System.out.println("Enter the element at the position " + (i + 1));
            this.char_array[i] = in.next().charAt(0);
        }
        in.close();
    }

    characterArray() {
        this.array_size = 10;
        this.char_array = new char[this.array_size];
        this.upper_counter = 0;
        this.vowel_counter = 0;
    }

    private char[] char_array;
    private static char[] vowel = { 'A', 'E', 'I', 'O', 'U' };
    private static int array_size;
    private int upper_counter;
    private int vowel_counter;

}

Saturday, December 31, 2022

ICSE Java Programming Array of Integers 2022 Q2 Specimen Paper Solved

 ICSE Java Programming Array of Integers 2022 Q2 Solved





import java.util.Scanner;

public class ICSEJava2022 {
    public static void main(String[] args) {
        int N, s;
        Scanner in = new Scanner(System.in);
        System.out.println("Enter the size of the array:");
        N = in.nextInt();
        ArraySearch obj = new ArraySearch(N);
        obj.inputElements(in);
        System.out.println("Enter the name to be searched:");
        s = in.nextInt();
        obj.searchElement(s);
        in.close();
    }
}

class ArraySearch {
    public void searchElement(int s) {
        boolean flag = false;
        for (int i = 0; i < this.array_size; i++) {
            if (s == this.array[i]) {
                System.out.println("The entered element is at position " + (i + 1));
                flag = true;
            }
        }
        if (!flag)
            System.out.println("The entered element is not present in the array.");
    }

    public void inputElements(Scanner in) {
        System.out.println("Enter the elements of the array:");
        for (int i = 0; i < this.array_size; i++) {
            System.out.println("Enter the element at position:" + (i + 1));
            this.array[i] = in.nextInt();
        }
    }

    ArraySearch(int N) {
        this.array_size = N;
        this.array = new int[this.array_size];
    }

    private static int array_size;
    private int[] array;
}

ICSE Specimen paper 2023 Computer Application

 



Friday, December 30, 2022

ICSE Java Programming Array of Strings 2023 Q8 SPECIMEN PAPER Solved

ICSE Java Programming Array of Strings 2023 Q8 SPECIMEN PAPER solved


Define a class to accept the names of 10 students in an array and check for the existence of the given name in the array using linear search, if found print the position of the name, if not found print the appropriate message. Also print the names which begins with the word "SRI".






import java.util.Scanner;

public class ICSEJava2023 {
    public static void main(String[] args) {
        String s = "";
        Scanner in = new Scanner(System.in);
        Name obj = new Name();
        obj.inputNames();
        System.out.println("Enter the name to be searched:");
        s = in.nextLine();
        obj.searchName(s);
        obj.checkName();
        in.close();
    }
}

class Name {
    public void checkName() {
        for (int i = 0; i < this.total_students; i++) {
            if (this.names[i].charAt(0) == 'S' && this.names[i].charAt(1) == 'R' && this.names[i].charAt(2) == 'I')
                System.out.println(this.names[i] + " begins with SRI");
        }
    }
    public void inputNames() {
        Scanner in = new Scanner(System.in);
        System.out.println("Enter the names:");
        for (int i = 0; i < this.total_students; i++) {
            System.out.println("Enter the name at position:" + (i + 1));
            this.names[i] = in.nextLine();
        }
    }
    public void searchName(String sname) {
        boolean flag = false;
        for (int i = 0; i < this.total_students; i++) {
            if (sname.equals(this.names[i])) {
                System.out.println("Position of the entered name in the array is: " + (i + 1));
                flag = true;
                break;
            }
        }
        if (flag == false)
            System.out.println("Name not found in the list");
    }
    Name() {
        this.names = new String[this.total_students];
    }
    private static int total_students = 10;
    private String[] names;
}

ICSE Java Programming Vowels in a String 2023 Q7 SPECIMEN PAPER

ICSE Java Programming Vowels in a String 2023 Q7 SPECIMEN PAPER

Question 7

Define a class to accept a string and print the same in reverse, also print the number of vowels in the string.

Eg:S="BEAUTIFUL"

Output - "LUFITUAEB" No. of vowels = 5


JAVA CODE ICSE Java programming Solved



import java.util.Scanner;

public class ICSEJava2023 {
    public static void main(String[] args) {
        StringReverse obj = new StringReverse();
        obj.inputString();
        obj.display();
    }
}

class StringReverse {
    public void inputString() {
        Scanner in = new Scanner(System.in);
        System.out.println("Enter a word:");
        this.message = in.nextLine();
        in.close();
    }

    public void display() {
        char[] c = new char[this.message.length()];
        System.out.println("Output");
        for (int i = 0; i < this.message.length(); i++) {
            System.out.print(this.message.charAt(this.message.length() - 1 - i));
            c[i] = this.message.charAt(i);
            if (c[i] >= 'a' || c[i] <= 'z')
                c[i] = (char) (c[i] - 32);
            for (int j = 0; j < 5; j++) {
                if (c[i] == this.vowels[j])
                    this.number_of_vowels++;
            }
        }
        System.out.println();
        System.out.println("No. of vowels:" + this.number_of_vowels);
    }
    StringReverse() {
        this.number_of_vowels = 0;
        this.message = "";
    }

    private int number_of_vowels;
    private String message;
    private static char[] vowels = { 'A', 'E', 'I', 'O', 'U' };
}