The Programming Project

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)

Leet Code Longest Substring Without Repeating Characters

Given a string s, find the length of the longest 

 without repeating characters.

 

Example 1:

Input: s = "abcabcbb"
Output: 3
Explanation: The answer is "abc", with the length of 3.

Example 2:

Input: s = "bbbbb"
Output: 1
Explanation: The answer is "b", with the length of 1.

Example 3:

Input: s = "pwwkew"
Output: 3
Explanation: The answer is "wke", with the length of 3.
Notice that the answer must be a substring, "pwke" is a subsequence and not a substring.

 

Constraints:

  • 0 <= s.length <= 5 * 104
  • s consists of English letters, digits, symbols and spaces.

class Solution:
    def lengthOfLongestSubstring(self, s: str) -> int:
        maxLength = 0
        for i in range(len(s)):
            substring = []
            for j in range(i,len(s)):
                if s[j] in substring:
                    break
                else:
                    substring.append(s[j])
            if len(substring) > maxLength:
                maxLength = len(substring)
        return maxLength
obj = Solution()
s = str(input("Enter a string:"))
print(obj.lengthOfLongestSubstring(s))