Python,C,C++ and JAVA programs for CBSE, ISC, B.Tech and I.T Computer Science and MCA students

The Programming Project

Tuesday, September 19, 2023

ICSE Java Programming Function Overload 2016 Q6 Solved

 Special words are those words which starts and ends with the same letter. 

Examples:
EXISTENCE
COMIC
WINDOW
Palindrome words are those words which read the same from left to right and vice versa
Examples:
MALAYALAM
MADAM
LEVEL
ROTATOR
CIVIC
All palindromes are special words, but all special words are not palindromes. Write a program to accept a word check and print Whether the word is a palindrome or only special word.

import java.util.Scanner;

public class PalindromeOrSpecialWord {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter a word: ");
        String word = scanner.nextLine();
        scanner.close();

        if (isPalindrome(word) && isSpecial(word)) {
            System.out.println("The word is both a palindrome and a special word.");
        } else if (isPalindrome(word)) {
            System.out.println("The word is a palindrome.");
        } else if (isSpecial(word)) {
            System.out.println("The word is a special word.");
        } else {
            System.out.println("The word is neither a palindrome nor a special word.");
        }
    }

    // Method to check if a word is a palindrome
    public static boolean isPalindrome(String word) {
        String reversed = "";
        for (int i = word.length() - 1; i >= 0; i--) {
            reversed += word.charAt(i);
        }
        return word.equalsIgnoreCase(reversed);
    }

    // Method to check if a word is a special word
    public static boolean isSpecial(String word) {
        return word.length() >= 2 && word.charAt(0) == word.charAt(word.length() - 1);
    }
}

ICSE Java Programming Function Overload 2016 Q5 Solved

Using the switch statement, write a menu driven program in Java for the following: (i) To print the Floyd’s triangle [Given below] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 (ii) To display the following pattern: I I C I C S I C S E  

For an incorrect option, an appropriate error message should be displayed. 



import java.util.Scanner;

public class PatternCreation {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int choice;

        do {
            System.out.println("Menu:");
            System.out.println("1. Print Floyd's Triangle");
            System.out.println("2. Display Pattern");
            System.out.println("3. Exit");
            System.out.print("Enter your choice (1/2/3): ");
            choice = scanner.nextInt();

            switch (choice) {
                case 1:
                    printFloydsTriangle();
                    break;
                case 2:
                    displayPattern();
                    break;
                case 3:
                    System.out.println("Exiting the program.");
                    break;
                default:
                    System.out.println("Invalid choice. Please select 1, 2, or 3.");
                    break;
            }
        } while (choice != 3);

        scanner.close();
    }

    // Method to print Floyd's Triangle
    public static void printFloydsTriangle() {
        int n = 1;
        int rows = 5; // You can change the number of rows as needed

        for (int i = 1; i <= rows; i++) {
            for (int j = 1; j <= i; j++) {
                System.out.print(n + " ");
                n++;
            }
            System.out.println();
        }
    }

    // Method to display the specified pattern
    public static void displayPattern() {
        String pattern = "ICSE";
        for (int i = 0; i < pattern.length(); i++) {
            for (int j = 0; j <= i; j++) {
                System.out.print(pattern.charAt(j) + " ");
            }
            System.out.println();
        }
    }
}

ICSE Java Programming Function Overload 2016 Q4 Solved

Define a class named BookFair with the following description: [15] Instance variables/Data members :

String Bname — stores the name of the book double price — stores the price of the book

Member methods : (i) BookFair() — Default constructor to initialize data members

(ii) void Input() — To input and store the name and the price of the book.

(iii) void calculate() — To calculate the price after discount. Discount is calculated based on the following criteria.

(iv) 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. Price Discount Less than or equal to Rs. 1000 2% of price More than Rs. 1000 and less than or equal to Rs. 3000 10% of price More than % 3000 15% of price


import java.util.Scanner;

class BookFair {

    private String Bname; // stores the name of the book

    private double price; // stores the price of the book

    // Default constructor to initialize data members

    public BookFair() {

        Bname = "";

        price = 0.0;

    }

    // To input and store the name and the price of the book

    public void Input() {

        Scanner scanner = new Scanner(System.in);

        System.out.print("Enter the name of the book: ");

        Bname = scanner.nextLine();

        System.out.print("Enter the price of the book: Rs. ");

        price = scanner.nextDouble();

        scanner.close();

    }

    // To calculate the price after discount based on the given criteria

    public void calculate() {

        if (price <= 1000) {

            price -= (0.02 * price); // 2% discount

        } else if (price > 1000 && price <= 3000) {

            price -= (0.10 * price); // 10% discount

        } else {

            price -= (0.15 * price); // 15% discount

        }

    }

    // To display the name and price of the book after discount

    public void display() {

        System.out.println("Book Name: " + Bname);

        System.out.println("Price after discount: Rs. " + price);

    }

    public static void main(String[] args) {

        BookFair book = new BookFair(); // Create an object of the class

        book.Input(); // Input the name and price of the book

        book.calculate(); // Calculate the price after discount

        book.display(); // Display the book details after discount

    }

}

Sunday, April 30, 2023

ICSE Java Programming Function Overload 2017 Q8 Solved

ICSE Java Programming Design a class to overload a function 2017 Q8 Solved 



import java.util.Scanner;

public class ICSEJava {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s;
        char c;
        System.out.println("Enter the string");
        s = in.nextLine();
        System.out.println("Enter the character");
        c = in.nextLine().charAt(0);
        StringCheck obj = new StringCheck();
        obj.check(s, c);
        obj.check(s);
        in.close();
    }
}

class StringCheck {
    public void check(String str, char ch) {
        for (int i = 0; i < str.length(); i++) {
            if (ch == str.charAt(i))
                counter++;
        }
        System.out.println("Number of times " + ch + " present is " + counter);
    }

    public void check(String str) {
        str = str.toLowerCase();
        for (int i = 0; i < str.length(); i++) {
            if (str.charAt(i) == 'a' || str.charAt(i) == 'e' || str.charAt(i) == 'i' || str.charAt(i) == 'o'
                    || str.charAt(i) == 'u')
                System.out.print(str.charAt(i) + " ");
        }
    }

    StringCheck() {
        counter = 0;
    }

    private int counter;
}

ICSE Java Programming Switch Case 2017 Q7 Solved

 

ICSE Java Programming  2017 Q7 Solved

Finding the sum, largest and the smallest element of an array with 20 integer elements.




import java.util.Scanner;

public class ICSEJava {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int[] array = new int[20];
        int sum = 0;
        int max = 0;
        int min = 0;
        System.out.println("Enter the elements of the array:");
        for (int i = 0; i < 20; i++) {
            System.out.println("Enter the element at the position:" + (i + 1));
            array[i] = in.nextInt();
            sum += array[i];
        }
        max = array[0];
        min = array[0];
        for (int i = 0; i < 20; i++) {
            if (max < array[i])
                max = array[i];
            if (min > array[i])
                min = array[i];
        }
        System.out.println("Sum of the elements of the array is "+sum);
        System.out.println("Largest number  of the array is "+max);
        System.out.println("Smallest number of the array is "+min);
        in.close();
    }
}



Tuesday, February 14, 2023

Python Program Divisibility with 5

Write a python program to print and count all numbers from 0 to n which are divisible by 5 and having none of the digits being repeated.




def checkRepeatingDigits(numb):
    checkString = str(numb)
    flag = True
    for i in range(len(checkString)-1):
        for j in range(i+1,len(checkString)):
            if checkString[i] == checkString[j]:
                flag = False
                break
        if flag == False:
            break
    return(flag)
n = int(input("Enter the limit:"))
counter = 0
for i in range(n):
    numb = i
    if numb % 5 == 0:
        if checkRepeatingDigits(numb) == True:
            counter +=1
            print(numb)
print("Total number of numbers divisible by 5 and having non-repeating characters =",counter)

Friday, February 3, 2023

INCOME TAX CALCULATOR : New Tax Regime FY 2023-24 Onwards


INCOME TAX CALCULATOR - NEW REGIME

CALCULATE YOUR INCOME TAX UNDER NEW REGIME HERE: 

Enter your gross salary in ₹

Enter your total income from other sources (Savings Interest, Dividend, Interest on FDs) in ₹

Enter your total Professional Tax (P.Tax) in ₹


Compare with the Old Tax Regime

Income Tax Slabs & Rates 2023-24

The Finance Minister introduced new tax regime in Union Budget, 2020 wherein there is
 an option for individuals and HUF (Hindu Undivided Family) to pay taxes at lower 
rates without claiming deductions under various sections. 
The following Income Tax slab rates are notified in new tax regime:

Income Tax Slab Tax Rates As Per New Regime 
₹0 - ₹3,00,000  Nil 
₹3,00,000 -  ₹6,00,000      5%  
₹6,00,001 -  ₹9,00,000      ₹15000 + 10% of total income exceeding ₹5,00,000    
₹9,00,001 -  ₹12,00,000     ₹45000 + 15% of total income exceeding ₹7,50,000     
₹12,00,001 - ₹15,00,000     ₹90000 + 20% of total income exceeding ₹12,50,000  
Above        ₹15,00,000     ₹140000 + 30% of total income exceeding ₹15,00,000  
Above rates does not include Surcharge and Cess.
4% Health & Education Cess is applicable on the income tax and applicable surcharge.