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

The Programming Project: 2023

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.
 


Monday, January 30, 2023

Banking ICSE Interest Calculator

Calculation of interest on a savings bank account
Mini Python project for middle and high school students

Example




Run the code on google colaboratory
Python Code:
class Solution(object):

    def Banking(self, numberOfMonths):
        transactions = dict()
        for i in range(numberOfMonths):
            month = str(input("Enter the month:"))
            transactions_for_month = int(
                input("Enter the number of transactions for this month:"))
            tempList = []
            for j in range(transactions_for_month):
                tempList.append(int(input("Enter the date of the month:")))
                # put a negative sign before the number if the amount is withdrawn
                tempList.append(
                    float(input("Enter the amount deposited or withdrawn:")))
            transactions[month] = tempList
        #print(transactions)
        self.MinimumBalance(transactions)

    def MinimumBalance(self, transactions):
        key = list(transactions.keys())
        balance = []
        balanceFinal = 0
        date = []
        monthWiseMBList = []
        for i in range(len(transactions)):
            for j in range(len(transactions[key[i]])):
                if j % 2 == 0:
                    date.append(transactions[key[i]][j])
                else:
                    balanceFinal += (transactions[key[i]][j])
                    balance.append(balanceFinal)
            balanceFinal = balance[-1]
            #print(balance)
            #print(date)
            if i != 0:
                move_date += int((len(transactions[key[i - 1]]) / 2))
            else:
                move_date = 0
            #print(move_date)
            minimumBalanceMonthly = float('inf')
            flagTransactionLessThanTenth = False
           
            for k in range(len(date) - move_date):
                if date[k+move_date] <= 10:
                    minimumBalanceMonthly = balance[k + move_date]
                    flagTransactionLessThanTenth = True
                else:

                    if minimumBalanceMonthly > balance[k + move_date]:
                        minimumBalanceMonthly = balance[k + move_date]
            if len(transactions[key[i]]) == 0:
                monthWiseMBList.append(monthWiseMBList[i - 1])
            else:
                monthWiseMBList.append(minimumBalanceMonthly)
            if flagTransactionLessThanTenth == False:
                if i == 0:
                    print(monthWiseMBList[i], i, minimumBalanceMonthly)
                    monthWiseMBList[i] = 0
                if i!=0:
                    if monthWiseMBList[i] > monthWiseMBList[i - 1] and len(transactions[key[i]]) != 0:
                        monthWiseMBList[i] = monthWiseMBList[i - 1]
                    else:
                        monthWiseMBList[i] = balance[-1]
            if i == len(key) - 1:
                print("Press Y/y is the account was closed in the month of ", key[-1])
                choice = str(input())
                if choice == "Y" or choice == "y":
                    monthWiseMBList[-1] = 0
            print("Minimum Monthly Balance for the month of ", key[i], "= ",
                  monthWiseMBList[i])
        #calculation of interest
        qualifyingAmount = 0
        for j in (monthWiseMBList):
            qualifyingAmount += j
        print("Total of balances ", qualifyingAmount)
        rate_of_interest = float(input("Enter the rate of interest:"))
        interest = (qualifyingAmount * rate_of_interest * (1 / 12)) / 100.0
        print("Total interest earned = ", round(interest, 2))


obj = Solution()
numberOfmonths = int(input("Enter the number of months:"))
obj.Banking(numberOfmonths)






Wednesday, January 25, 2023

Leet Code Rotate Image

Leet Code Rotate Image 

You are given an n x n 2D matrix representing an image, rotate the image by 90 degrees (clockwise).


Example 1:

Input: matrix = [[1,2,3],[4,5,6],[7,8,9]]
Output: [[7,4,1],[8,5,2],[9,6,3]]

Example 2:

Input: matrix = [[5,1,9,11],[2,4,8,10],[13,3,6,7],[15,14,12,16]]
Output: [[15,13,2,5],[14,3,4,1],[12,6,8,9],[16,7,10,11]]

 

Constraints:

  • n == matrix.length == matrix[i].length
  • 1 <= n <= 20
  • -1000 <= matrix[i][j] <= 1000





class Solution:
    def rotate(self, matrix):
        order = len(matrix[0])
        newmatrix = []
        for i in range(order):
            newmatrix.append([])
            for j in range(order):
                newmatrix[i].append(0)
        newColoumn = []
        for i in range(order):
            newColoumn.append(order-1-i)
        for i in range(order):
            for j in range(order):
                newmatrix[j][newColoumn[i]] = matrix[i][j]
        for i in range(order):
            for j in range(order):
                matrix[i][j] = int(newmatrix[i][j])
        print(matrix)
obj = Solution()
#change the matrix here
matrix = [[5,1,9,11],[2,4,8,10],[13,3,6,7],[15,14,12,16]]
obj.rotate(matrix)