The Programming Project

Friday, December 30, 2022

ICSE Java Programming Function Overloading 2023 Q4 SPECIMEN PAPER

ICSE Java Programming  2023 Q3 SPECIMEN PAPER Solved.


Question 4

Define a class to overload the method print as follows:

void print ()-to print the format

1

2 3

4 5 6

7 8 9 10

boolean print (int n) -

to check whether the number is a Dudeney number,a number is dudeney if the cube of the sum of the digits is equal to the number itself.

Eg: 512(5+1+2)3 = (8)3 = 512

void print (int a, char ch) -

if ch = s or S print the square of the number else if

ch=c or C print the cube of the number.

Function Overloading in java example.




import java.util.Scanner;
public class ICSEJava2023 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        FunctionOverloading obj = new FunctionOverloading();
        int choice = 0;
        int n;
        char ch;
        System.out.println("Press 1 to print the format:");
        System.out.println("Press 2 to check for Dudeney number:");

        System.out.println("Press 3 to print the square or cube:");
        choice = in.nextInt();
        switch (choice) {
            case 1:
                obj.print();
                break;
            case 2:
                System.out.println("Enter the number:");
                n = in.nextInt();
                if (obj.print(n) == true)
                    System.out.println(" It's a Dudeney numer");
                else
                    System.out.println(" It's not a Dudeney numer");
                break;
            case 3:
                System.out.println("Enter the number:");
                n = in.nextInt();
                System.out.println("Enter the character (c/C or s/S):");
                ch = in.next().charAt(0);
                System.out.println("Enter the height of the cuboid:");
                obj.print(n, ch);
                break;
            default:
                System.out.println("Wrong Choice!");
                break;
        }
        in.close();
    }
}

class FunctionOverloading {
    public void print() {
        int counter = 1;
        for (int i = 1; i <= 4; i++) {
            for (int j = 1; j <= i; j++) {
                System.out.print((counter++) + " ");
            }
            System.out.println();
        }
    }

    public boolean print(int n) {
        int sum = 0;
        int temp;
        temp = n;
        while (temp > 0) {
            sum += temp % 10;
            temp /= 10;
        }
        if (sum * sum * sum == n)
            return (true);
        else
            return (false);
    }

    public void print(int a, char ch) {
        if (ch == 's' || ch == 'S')
            System.out.println(a * a);
        else if (ch == 'c' || ch == 'C')
            System.out.println(a * a * a);
        else
            System.out.println("Invalid input!");
    }
}

ICSE Java Programming Class employee 2023 Q3 SPECIMEN PAPER

 ICSE Java Programming Class employee 2023 Q3 SPECIMEN PAPER Solved.




import java.util.Scanner;

public class ICSEJava2023 {
    public static void main(String[] args) {
        employee obj = new employee();
        obj.accept();
        obj.calculate();
        obj.print();
    }
}

class employee {
    public void print() {
        System.out.println("Details of the employee:");
        System.out.println("Employee number:" + eno);
        System.out.println("Employee name:" + ename);
        System.out.println("Age of the employee:" + age);
        System.out.println("Basic pay of the employee:" + basic);
        System.out.println("Net pay of the employee:" + net);
    }

    public void calculate() {
        if (this.age > 50)
            this.net = allowance + (basic + (hra * basic + da * basic - pf * basic) / 100f);

        else
            this.net = basic + (hra * basic + da * basic - pf * basic) / 100f;

    }

    public void accept() {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter the employee number:");
        eno = in.nextInt();
        System.out.print("Enter the employee name:");
        ename = in.nextLine();
        in.nextLine();
        System.out.print("Enter the age of the employee:");
        age = in.nextInt();
        System.out.print("Enter the basic pay of the employee:");
        basic = in.nextFloat();
        in.close();
    }

    employee() {
        this.eno = 0;
        this.ename = "";
        this.age = 0;
        this.basic = 0;
        this.net = 0;
    }
    private int eno;
    private String ename;
    private int age;
    private float basic;
    private float net;
    private static float hra = 18.5f;
    private static float da = 17.45f;
    private static float pf = 8.10f;
    private static float allowance = 5000f;
}

Thursday, December 29, 2022

ICSE Java Programming Average Marks 2018 Q9

Question 9.
Write a program to accept name and total marks of N number of students in two single subscript array name[] and
totalmarks[ ].  
Calculate and print:
(i) The average of the total marks obtained by N Number of students.
[average = (sum of total marks of all the students)/N]
(ii) Deviation of each student’s total marks with the average.

[deviation = total marks of a student – average] 



import java.util.Scanner;

public class ICSEJava2018 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String[] name;
        float[] totalmarks;
        int N;
        float averageMarks = 0;
        System.out.println("Enter the number of students:");
        N = in.nextInt();
        in.nextLine();
        name = new String[N];
        totalmarks = new float[N];
        for (int i = 0; i < N; i++) {
            name[i] = "";
            System.out.print("Enter the name of student:");
            name[i] = in.nextLine();
            System.out.print("Enter the total marks of " + name[i] + ":");
            totalmarks[i] = in.nextFloat();
            in.nextLine();
            averageMarks += totalmarks[i];
        }
        System.out.println("The average of the total marks obtained by N Number of students:" + averageMarks / N);
        for (int j = 0; j < N; j++)
            System.out.println("Deviation for " + name[j] + "=" + (totalmarks[j] - (averageMarks / N)));
        in.close();

    }
}

ICSE Java Programming Pattern Print 2018 Q8

Question 8.
Write a menu driven program to display the pattern as per user’s choice.
ICSE Computer Applications Question Paper 2018 Solved for Class X
For an incorrect option, an appropriate error message should be displayed.



import java.util.Scanner;

public class ICSEJava2018 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int choice = 0;
        char[] array1 = { 'A', 'B', 'C', 'D', 'E' };
        char[] array2 = { 'B', 'L', 'U', 'E' };
        System.out.println("Press 1 to generate the first pattern:");
        System.out.println("Press 2 to generate the second pattern::");
        System.out.println("Enter your choice:");
        choice = in.nextInt();
        switch (choice) {
            case 1:
                for (int i = 0; i < 5; i++) {
                    for (int j = 5 - i; j >= 1; j--) {
                        System.out.print(array1[5 - j]);
                    }
                    System.out.println();
                }
                break;
            case 2:
                int counter = 0;
                for (int i = 1; i <= 4; i++) {
                    for (int j = 1; j <= i; j++) {
                        System.out.print(array2[counter]);
                    }
                    counter++;
                    System.out.println();
                }
                break;
            default:
                System.out.println("WRONG CHOICE!:");
                break;
        }
    in.close();
    }
}

 

ICSE Java Programming Function Overload 2018 Q7

Question 7.

Design a class to overload a function volume() as follows : 

(i) double volume (double R) — with radius (R) as an argument, returns the volume of sphere using the formula.

V = 4/3 × 22/7 × R3

(ii) double volume (double H, double R) – with height(H) and radius(R) as the arguments, returns the volume of a cylinder using the formula.

V = 22/7 × R2 × H

(iii) double volume (double L, double B, double H) – with length(L), breadth(B) and Height(H) as the arguments, returns the volume of a cuboid using the formula.





import java.util.Scanner;

public class ICSEJava2018 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        VolumeOfObjects obj = new VolumeOfObjects();
        int choice = 0;
        double R = 0, H = 0, B = 0;
        System.out.println("Press 1 to calculate the volume of a sphere:");
        System.out.println("Press 2 to calculate the volume of a cylinder:");
        System.out.println("Press 3 to calculate the volume of a cuboid:");
        choice = in.nextInt();
        switch (choice) {
            case 1:
                System.out.println("Enter the radius of the sphere:");
                R = in.nextDouble();
                System.out.println("Volume of the sphere:" + obj.volume(R)+" cubic units");
                break;
            case 2:
                System.out.println("Enter the radius of the cylinder:");
                R = in.nextDouble();
                System.out.println("Enter the height of the cylinder:");
                H = in.nextDouble();
                System.out.println("Volume of the cylinder:" + obj.volume(H, R)+" cubic units");
                break;
            case 3:
                System.out.println("Enter the length of the cuboid:");
                R = in.nextDouble();
                System.out.println("Enter the breadth of the cuboid:");
                H = in.nextDouble();
                System.out.println("Enter the height of the cuboid:");
                B = in.nextDouble();
                System.out.println("Volume of the cylinder:" + obj.volume(R, H,B)+" cubic units");
                break;
            default:
                System.out.println("Wrong Choice!");
                break;
        }
    in.close();
    }
}

class VolumeOfObjects {
    public double volume(double R) {
        return (4 * 22 * R * R * R) / (21);
    }

    public double volume(double H, double R) {
        return (22 * R * R * H) / 7;
    }

    public double volume(double L, double B, double H) {
        return (L * B * H);
    }

} 

Wednesday, December 28, 2022

Median and Mode Calculator : CBSE & ICSE

Median,Mode, Percentile and Percentile Rank Calculator for CBSE,ICSE,Statistics, Psychology and Education students using Python programming. 
def parityString(string):
        while len(string) < 9:
            string += " "
        return string
def modeContinuousData(numberOFClasses,lowerLimitOfFirstClass,upperLimitOfFirstClass):
    classWidth = upperLimitOfFirstClass - lowerLimitOfFirstClass
    listLowerClassLimits = []
    listUpperClassLimits = []
    classFrequency = []
    lower_limit_modalclass = 0
    f0 = 0
    f1 = 0
    f2 = 0
    modal_index = 0
    max_frequency = 0
    for i in range(numberOFClasses):
        listLowerClassLimits.append(lowerLimitOfFirstClass)
        listUpperClassLimits.append(upperLimitOfFirstClass)
        print("Enter the frequency of the class:",listLowerClassLimits[i],"-",listUpperClassLimits[i])
        classFrequency.append(float(input()))
        if max_frequency < classFrequency[i]:
            max_frequency = classFrequency[i]
            modal_index = i
        lowerLimitOfFirstClass += classWidth
        upperLimitOfFirstClass += classWidth
    f1 = classFrequency[modal_index]
    f0 = classFrequency[modal_index-1]
    f2 = classFrequency[modal_index+1]
    lower_limit_modalclass = listLowerClassLimits[modal_index]
    print(parityString("CLASSES"),parityString("frequency(fi)"))
    for i in range(numberOFClasses):
        if i == modal_index or i == modal_index+1:
            print("----------------------------------------------------------")
        print(str(listLowerClassLimits[i]),end =' '),
        print("-",parityString(str(listUpperClassLimits[i])),"   ",end='')
        print(parityString(str(classFrequency[i])))
       
    print("=================================================================")
    print("lower limit of the modal class l =",lower_limit_modalclass," Class width h = ",classWidth)
    print("frequency of the modal class f1 =",f1)
    print("frequency of the class preceeding the modal class f0 =",f0)
    print("frequency of the class succeeding the modal class f2 =",f2)
    mode = lower_limit_modalclass + ((f1-f0)/(2*f1-f0-f2))*classWidth
    print("MODE FOR THE GIVEN DATA SET:",round(mode,2))
    print()
def medianContinuousData(numberOFClasses,lowerLimitOfFirstClass,upperLimitOfFirstClass):
    classWidth = upperLimitOfFirstClass - lowerLimitOfFirstClass
    listLowerClassLimits = []
    listUpperClassLimits = []
    classFrequency = []
    cumulativeFrequency = []
    lower_limit_medianclass = 0
    f = 0 #frequency of median class
    cf = 0 #cf of the class preceeding the median class
    n = 0 # total frequency
    for i in range(numberOFClasses):
        listLowerClassLimits.append(lowerLimitOfFirstClass)
        listUpperClassLimits.append(upperLimitOfFirstClass)
        print("Enter the frequency of the class:",listLowerClassLimits[i],"-",listUpperClassLimits[i])
        classFrequency.append(float(input()))
        n += classFrequency[i]
        lowerLimitOfFirstClass += classWidth
        upperLimitOfFirstClass += classWidth
    for j in range(numberOFClasses):
        if j == 0:
            cumulativeFrequency.append(classFrequency[j])
        else:
            cumulativeFrequency.append(cumulativeFrequency[j-1]+classFrequency[j])
    counter = 0
    #print(classFrequency,cumulativeFrequency)
    while cumulativeFrequency[counter] < (n/2.0):
        counter +=1
    lower_limit_medianclass = listLowerClassLimits[counter]
    f = classFrequency[counter]
    cf = cumulativeFrequency[counter-1]
    print(parityString("CLASSES"),parityString("frequency(fi)")+"       "+parityString("cf"))
    for i in range(numberOFClasses):
        if i == counter or i == counter+1:
            print("----------------------------------------------------------")
        print(str(listLowerClassLimits[i]),end =' '),
        print("-",parityString(str(listUpperClassLimits[i])),"   ",end='')
        print(parityString(str(classFrequency[i])),parityString(str(cumulativeFrequency[i])))
       
    print("=================================================================")
    print("lower limit of the modal class l =",lower_limit_medianclass," Class width h = ",classWidth)
    print("frequency of the median class f =",f)
    print("cumulative frequency of the class preceeding the median class cf =",cf)
    median = lower_limit_medianclass + ((n/2 - cf)/f)*classWidth
    print("Median FOR THE GIVEN DATA SET:",round(median,2))
    print()
def percentileRankContinuousData(numberOFClasses,lowerLimitOfFirstClass,upperLimitOfFirstClass,score):
    listLowerClassLimits = []
    listUpperClassLimits = []
    classFrequency = []
    cumulativeFrequency = []
    classWidth = upperLimitOfFirstClass - lowerLimitOfFirstClass
    X = score
    f = 0 #frequency of class containing the score
    cf = 0 #cf of the class preceeding the class containing the score
    n = 0 # total frequency
    L = 0 #lower limit of the class containing the score
    positionOfScore = 0
    for i in range(numberOFClasses):
        listLowerClassLimits.append(lowerLimitOfFirstClass)
        listUpperClassLimits.append(upperLimitOfFirstClass)
        print("Enter the frequency of the class:",listLowerClassLimits[i],"-",listUpperClassLimits[i])
        classFrequency.append(float(input()))
        if score >= listLowerClassLimits[i] and i <= listUpperClassLimits[i]:
            L = listLowerClassLimits[i]
            positionOfScore = i
            f= classFrequency[i]
        n += classFrequency[i]
        lowerLimitOfFirstClass += classWidth
        upperLimitOfFirstClass += classWidth
    for j in range(numberOFClasses):
        if j == 0:
            cumulativeFrequency.append(classFrequency[j])
        else:
            cumulativeFrequency.append(cumulativeFrequency[j-1]+classFrequency[j])
    counter = 0
    cf = cumulativeFrequency[positionOfScore-1]
    print(parityString("CLASSES"),parityString("frequency(fi)")+"       "+parityString("cf"))
    for i in range(numberOFClasses):
        if i == positionOfScore+1 or i == positionOfScore:
            print("----------------------------------------------------------")
        print(str(listLowerClassLimits[i]),end =' '),
        print("-",parityString(str(listUpperClassLimits[i])),"   ",end='')
        print(parityString(str(classFrequency[i])),parityString(str(cumulativeFrequency[i])))
       
    print("=================================================================")
    print("Score for which the percentile rank is being calculated X =",X)
    print("cumulative frequency of the class preceeding the class containing the score F/cf =",cf)
    print("lower limit of the class containing the score L =",L)
    print("size/width of the class interval i = ",classWidth)
    print("frequency of the class f =",f)
    print("Total number of cases in the given frequency distribution N =",n)
    print(" Percentile Rank PR = (100/N)(cf + ((X-L)/classWidth)*f)")
    PR = (cf + ((X-L)/classWidth)*f)
    PR = float((100*PR)/n)
    print("Percentile rank for the given score ",X," is ",round(PR,2))
    print("In other words the person who scored ",X," is above ",round(PR,2),"% of the sample")
    print()
def percentileContinuousData(numberOFClasses,lowerLimitOfFirstClass,upperLimitOfFirstClass):
    classWidth = upperLimitOfFirstClass - lowerLimitOfFirstClass
    listLowerClassLimits = []
    listUpperClassLimits = []
    classFrequency = []
    cumulativeFrequency = []
    lower_limit_percentileclass = 0
    p = int(input("Enter the percentile which you want to calculate:"))
    f = 0 #frequency of percentile class
    cf = 0 #cf of the class preceeding the percentile class
    n = 0 # total frequency
    for i in range(numberOFClasses):
        listLowerClassLimits.append(lowerLimitOfFirstClass)
        listUpperClassLimits.append(upperLimitOfFirstClass)
        print("Enter the frequency of the class:",listLowerClassLimits[i],"-",listUpperClassLimits[i])
        classFrequency.append(float(input()))
        n += classFrequency[i]
        lowerLimitOfFirstClass += classWidth
        upperLimitOfFirstClass += classWidth
    X = (p*n)/100.0
    for j in range(numberOFClasses):
        if j == 0:
            cumulativeFrequency.append(classFrequency[j])
        else:
            cumulativeFrequency.append(cumulativeFrequency[j-1]+classFrequency[j])
    counter = 0
    #print(classFrequency,cumulativeFrequency)
    while cumulativeFrequency[counter] < (X):
        counter +=1
    lower_limit_percentileclass = listLowerClassLimits[counter]
    f = classFrequency[counter]
    cf = cumulativeFrequency[counter-1]
    print(parityString("CLASSES"),parityString("frequency(fi)")+"       "+parityString("cf"))
    for i in range(numberOFClasses):
        if i == counter or i == counter+1:
            print("----------------------------------------------------------")
        print(str(listLowerClassLimits[i]),end =' '),
        print("-",parityString(str(listUpperClassLimits[i])),"   ",end='')
        print(parityString(str(classFrequency[i])),parityString(str(cumulativeFrequency[i])))
       
    print("=================================================================")
    print("lower limit of the percentile class l =",lower_limit_percentileclass," Class width h = ",classWidth)
    print("frequency of the percentile class f =",f)
    print("cumulative frequency of the class preceeding the percentile class cf =",cf)
    percentile = lower_limit_percentileclass + ((X - cf)/f)*classWidth
    print("Percentile P",p," = ",round(percentile,2))
    print(p,"% of data lies below the score of ",round(percentile,2))
    print()
def medianDiscreetData():
    n = int(input("Enter the number of values: "))
    dataList = []
    for i in range(n):
        print("Enter a number: ")
        dataList.append(float(input()))
    dataList.sort()
    print("Sorted numbers:",dataList)
    if n % 2 != 0:
        print("Median is the ",int((n+1)/2), "th observation")
        print("Median =",dataList[int((n+1)/2)])
    else:
        print("Median is the average of ",int((n)/2)," and ",int((n/2)+1), " th observation")
        print("Median =",(dataList[int(n/2)]+dataList[int((n/2)+1)])/2)
print("****** MEDIAN AND MODE CALCULATION *******")
key = 0
while key != -99:
    print(" WELCOME TO THE MAIN MENU ***** STATISTICS CALCULATION FOR CONTINUOUS AND DISCREET DATA *****")
    print(" Press 1 to CALCULATE MODE FOR CONTINUOUS DATA SET: ")
    print(" Press 2 to CALCULATE MEDIAN FOR CONTINUOUS DATA SET: ")
    print(" Press 3 to CALCULATE MEDIAN FOR DISCREET DATA: ")
    print(" Press 4 to CALCULATE PERCENTILE RANK FOR CONTINUOUS DATA SET: ")
    print(" Press 5 to CALCULATE PERCENTILES FOR CONTINUOUS DATA SET")
    print(" Type -99 to exit the menu:")
    key = int(input("Enter your choice:"))
    if key == 1:
        numberOFClasses = int(input("Enter the number of classes:"))
        lowerLimitOfFirstClass = float(input("Enter the lower limit of the first classes:"))
        upperLimitOfFirstClass = float(input("Enter the upper limit of the first classes:"))
        modeContinuousData(numberOFClasses,lowerLimitOfFirstClass,upperLimitOfFirstClass)
    if key == 2:
        numberOFClasses = int(input("Enter the number of classes:"))
        lowerLimitOfFirstClass = float(input("Enter the lower limit of the first classes:"))
        upperLimitOfFirstClass = float(input("Enter the upper limit of the first classes:"))
        medianContinuousData(numberOFClasses,lowerLimitOfFirstClass,upperLimitOfFirstClass)
    if key == 3:
        medianDiscreetData()
    if key == 4:
        numberOFClasses = int(input("Enter the number of classes:"))
        lowerLimitOfFirstClass = float(input("Enter the lower limit of the first classes:"))
        upperLimitOfFirstClass = float(input("Enter the upper limit of the first classes:"))
        score = float(input("Enter the score for which you want to get the percentile rank:"))
        percentileRankContinuousData(numberOFClasses,lowerLimitOfFirstClass,upperLimitOfFirstClass,score)
    if key == 5:
        numberOFClasses = int(input("Enter the number of classes:"))
        lowerLimitOfFirstClass = float(input("Enter the lower limit of the first classes:"))
        upperLimitOfFirstClass = float(input("Enter the upper limit of the first classes:"))
        percentileContinuousData(numberOFClasses,lowerLimitOfFirstClass,upperLimitOfFirstClass)
    if key == -99:
        print("Exited from main menu:")
Median,Mode, Percentile and Percentile Rank Calculator for CBSE,ICSE,Statistics, Psychology and Education students using Python programming.