Sunday, 1 December 2024

Class X Computer Applications Notes At A Glance

 ICSE NOTE AT A Glance
Class X
Computer Applications 

Chapter 1: Revision of Class IX

Introduction to Object Oriented Programming

1.      Programming paradigms - Programming paradigms are a way to classify programming languages based on their features. Paradigm means organizing principle of a program. It is an approach to programming.

2.      Procedure Oriented Programming: A Procedure oriented programming approach allows the users to develop their logic by using a number of functions that would enhance the program’s productivity. Example BASIC, COBOL, C

3.      Object Oriented Programming: An Object Oriented Programming is a modular approach, which allows the data to be applied with a stipulated program area. It also provides the reusability feature to develop productive logic, which means to give more emphasis on data.

4.      Basic Principles of OOP:

(a)    Abstraction: The act of representing essential features,without including the background details.

(b)    Inheritance: Capability of one class of things to inherit capabilities or properties from


(c)    another class.


(d)    Encapsulation: Wrapping up of data and functions into asingle unit.

(e)    Polymorphism: Polymorphism is the ability for a message or data to be processed in more than one form.

5.      Java compilation process:

(a)     Java programs are written in “.java” file. (source code) and then compiled by Java compiler.

(b)    Byte code: Java compiler converts the source code into an intermediate binary form called the byte code.

(c)    Java Virtual Machine (JVM): It a java interpreter that converts byte code into machine to various platforms.

(d)    Just In Time(JIT): It is part of the JVM and it compiles byte code into executable code in real time, one piece-by-piece, demand basis.

6.      Types of Java program:

(a)    Internet Applets: The programs executed inside the Javabased web browser.

(b)    Java Applications: The programs developed by the users.

(c)    Java libraries:

A package is a collection of various classes. Each class contains different functions.

A package can be inclued in the program by using a keyword

'import'.

 Example  import java.io.*;  import java.util.*;

7.      Keywords or Reserved words: Java reserved words or the keywords are the words which carry special meaning to the system compiler. Such words cannot be used for naming a variable in the program. case , switch, else, break , static, do, const, throws, float , char, try, int, double, void, goto, for, while, new, import , boolean, long, if, byte , package, private, catch, short, public, class ,default.

8.      Comment line: The comment statement is a non executable statement in Java.

These are the remarks given by the user.

 Types:

1. single line comment //----------

2. Multiline comment /* ---------- */

3. Document comment /** --------- **/

9.      ASCII Characters

A - Z                      65 - 90

a-z                         97 - 122

0-9                        48 - 57

white space        32

10.   Token: The smallest individual unit in a program is known as a Token

11.   Literals: Literals or constants are data items that are fixed data values (do not during the execution of the program).

12.   Data Types:

a) Integer Literals (int) are whole numbers without any fractional part.

b)      Double (double)- Decimal, Octal, Hexa decimal.

 Ex) a= 505, b=-15

Real Literals are numbers having fractional parts.

Ex) p=16.79 , q=-1.005

c)      Character Literal (char) is one character enclosed in single quotes.

Ex) ‘x’, ‘9’,’*”

d)      Long Literals(long)

e)      Short Literals(short)

f)       Boolean Literals(boolean)

g)      Byte Literals(byte)

 

13.   Separators: The following nine ASCII characters are the separators(punctuators).( ) { } [ ] ; , .

14.   Identifier: Identifiers are fundamental building block of a program such as a variable, class, method etc. It’s used as the general terminology for the names given to different parts of the program. double area=15.6;

15.   Rules for forming identifiers:

• Identifiers can have alphabets, digits and underscore and doller sign characters.

• They must not be a keyword or Boolean literal or null literal

• They must not begin with a digit

• They can be of any length

16.   Operators: Operators are special symbols that cause an action to take place.

·        Arithmetic,

·        Relational,

·        Logical,

·        Conditional Operators. A=b*c;

17.   Escape Sequences: Nongraphic characters are those characters that cannot be typed directly from keyboard. E.g. backspace, tabs etc.,

An escape sequence is represented by a backslash ( \ ) followed by one or more characters. Escape sequence Nongraphic character

 \b Backspace

\f Formfeed

\n Newline or linefeed

\r Carriage return

\t Tab space

\\ Backslash

\’ Single quotes

\” Double quotes

\? Question mark

\0 null Data types:

18.    Data Types are means to identify the type of data and associated operations of handling it.

Two types:

1. Primitive or fundamental or Instrinsic (predefined)

                     int, long, float, double, char, short, byte , boolean

2. Reference or composite ( user defined)

                     class, string, array

19.   Initializing a variable: Initializing a variable means specifying an initial value to assign to it (i.e., before it is used at all). Notice that a variable that is not initialized does not have a defined value, hence it cannot be used until it is assigned such a value.

20.   Static initialization: Initialize the variable at the time of declaration

int b=5,a=0; float c=0.0

21.   Dynamic Initialization : Initialize the variable at program execution time.(at run time)

int b=5, c=6;

int a= b + c;

22.   Arithmetic expression: A set of variables, constants and arithmetical operators used together to yield a meaningful result is known as Arithmetical Expression.

d= a*b+c/4;

23.   Types of Arithmetical Expression

1. Pure Expression: An arithmetical expression that uses all its components of same data type.

int a,b;

int c=a+b*4;

2. Impure expression: An arithmetical expression in which one or more components are of different data types.

int a; float f; double d;

double s= a*f/d;

24.   Type conversion: In a mixed expression, the result can be obtained in any one form of its data types. Hence, it is needed to convert the various data types into a single type. Such conversion is termed as Type conversion.[Converting one form of data type into another form of data type].

Types of Type Conversion

Implicit (Coercion) Conversion done automatically from lower version of data type to its higher version of data type.

char short int

int float double

25.   Explicit Conversion done forcefully from higher version of data type to its lower version of data type.

int x=10, y=34;

double z=(double)x +(double)y 

26.   Operators: Operators are special symbols that cause an action to take place.

Types:

27.   Unary(+):

int a=5;

int b= +a; //5

Unary(-):

int a=5;

int b= -a; //-5

int a=-5; int b=-a ; //5

(a)  Increment operator(++):  increased by 1)

(a)     Post increment a++

int a=10;

System.out.println(a++);

is 10

(b)    Pre increment ++a

System.out.println(++a);

is 11

28.   (b) Decrement operator(--): (decreased by 1)

a) post decrement a--

int a=10;

System.out.println(a--);

is 10

b) pre decrement(--a)

int a=10;

System.out.println(--a);

is 9

29.   Binary operators: (Two operands and one operator)

1. Arithmetic operators: + , - , * , / , %

a=5, b=2

a+b, a - b, a*b, a/b, a%b

2. Relational operators:( comparing the values)

>, >= ,< , <= , == , !=

a>b, a>=b, a<b, a<=b, a==b, a!=b

3. Logical operators: AND ( && ) , OR ( ||) , NOT ( ! )

Example

if(a>b && c>a){}

30.   Ternary operator (or) Conditional operator: ( ? : ) Syntax:

Condition ? Expression 1 : Expression 2 ;

Example; 1) a= 19 , b= 15

Example;

1) a= 19 , b= 15 max = (a > b) ? a : b ;

2) salary = 15000 bonus = ( salary> 10000) ? salary*15/100 : salary* 5/100 ;

 

31.   Special operators: new: dynamically allocate the memory for the object. Example: example e = new example( ); Dot (.)

32.   operator: invoking members of class Example: System.out.println(); (System.in)

33.   Operator precedence: Operator precedence determines the order in which the operators in an expression are evaluated.

34.   Object is an instance of a class. It is an identifiable entity with some characteristics and behavior.

35.   Class represents a set of objects that share common characteristics and behavior.

36.   Abstraction: It is the act of representing essential features and hiding the background details.

37.   Encapsulation: It is an act of wrapping of the data and function as one single unit. Provides insulation of the data from the direct access by the program.

38.   Inheritance : It is the capability of one class to inherit the properties from another class

39.   Polymorphism: It is the ability of data to be processed in more than one form.

40.   Message passing – when the objects need to interact with one another, they pass /request information to one another. This interaction is known as message passing.

41.   Compiler : It is a software which converts high level language program to machine language and viz. as a whole. It is faster but hard to debug.

42.   Interpreter: It is a software which converts high level language program to machine language and viz line by line. It is slow but easy to debug.

43.   Bytecode: When a java source code is compiled the resultant got is called a bytecode.

44.   Keywords: These are words have a specific meaning to a language compiler.

45.   Constant: a data item that never changes its value during a program runs.

46.   Final: The keyword final makes a variable as constant. i.e., whose value cannot be changed during the program execution

47.   Operators: a symbol used to depict a mathematical or logical operation.

48.   Arithmetic operators: they provide facilitation to the mathematical calculations within a program: they are + - * / %

                ----------------------

 

 

 

Find the output of the Code

1.      Math.round(6.6) + Math.ceil(3.4)

Ans:   ⇒ 7 + 4.0

             ⇒ 11.0

2.      System.out.print(

Character.toLowerCase('1'));

Ans: 1

3.      Evaluate the expression when the value of x = 2:

x = x++ + ++x + x

Ans: 10

4.      Initially, x = 2. The expression is calculated as follows:

x = x++ + ++x + x

Solution-

x = 2 + ++x + x          (x = 3)

x = 2 + 4 + x               (x = 4)

x = 2 + 4 + 4               (x = 4)

x = 10

5.      The following code segment should print "You can go out" if you have done your homework (dh) and cleaned your room (cr). However, the code has errors. Fix the code so that it compiles and runs correctly.

boolean dh = true;

boolean cr= true;

if (dh && cr)

System.out.println("You cannot go out");

else

System.out.println("You can go out");           

Solution:-

The corrected code is as follows:

boolean dh = true;

boolean cr= true;

if (dh && cr)

System.out.println("You can go out");

else

System.out.println("You cannot go out");

6.      Sam executes the following program segment and the answer displayed is zero irrespective of any non zero values are given. Name the error. How the program can be modified to get the correct answer?

void triangle(double b, double h)

{       

    double a;

    a = 1/2 * b * h;

    System.out.println("Area=" + a);             

}     

Answer

Logical error.

Modified program:

void triangle(double b, double h)

{       

    double a;

    a = 1.0/2 * b * h;

    System.out.println("Area=" + a);                   

}       

7.      Explanation

The statement is evaluated as follows:

a = 1/2 * b * h;

a = 0 * b * h; (1/2 being integer division gives the result as 0

a = 0 (Since anything multiplied by 0 will be 0)

To avoid this error, we can replace '1/2' with '1.0/2'. Now the expression will be evaluated as follows:

a = 1.0/2 * b * h;

a = 0.5 * b * h; (The floating-point division will result in result as as 0.5)

This will give the correct result for the given code.

8.      int res = 'A';

What is the value of res?

Answer

Value of res is 65 which is the ASCII code of A. As res is an int variable and we are trying to assign it the character A so through implicit type conversion the ASCII code of A is assigned to res.

System.out.print("BEST ");

     System.out.println("OF LUCK");

Choose the correct option for the output of the above statements

Option 1: BEST OF LUCK

Option 2: BEST

OF LUCK

Answer

Option 1 — BEST OF LUCK is the correct option.

System.out.print does not print a newline at the end of its output so the println statement begins printing on the same line. So the output is BEST OF LUCK printed on a single line.

9.      Write a Java expression for the following:

Answer: Math.sqrt(3 * x + x * x) / (a + b)

 

Sections – B

PROGRAMS

1.      CONDITIONAL BASED QUESTION

Program 1: Define a class called with the following specifications:

Class name: Eshop

Member variables:
String name: name of the item purchased
double price: Price of the item purchased

Member methods:
void accept():
Accept the name and the price of the item using the methods of Scanner class.
void calculate(): To calculate the net amount to be paid by a customer, based on the following criteria:

Price

Discount

1000 – 25000

5.0%

25001 – 57000

7.5 %

57001 – 100000

10.0%

More than 100000

15.0 %

void display(): To display the name of the item and the net amount to be paid.

Write the main method to create an object and call the above methods.

import java.util.Scanner;

public class Eshop

{

    private String name;

    private double price;

    private double disc;

    private double amount;

 

    public void accept() {

        Scanner in = new Scanner(System.in);

        System.out.print("Enter item name: ");

        name = in.nextLine();

        System.out.print("Enter price of item: ");

        price = in.nextDouble();

    }

   

    public void calculate() {

        double d = 0.0;

       

        if (price < 1000)

            d = 0.0;

        else if (price <= 25000)

            d = 5.0;

        else if (price <= 57000)

            d = 7.5;

        else if (price <= 100000)

            d = 10.0;

        else

            d = 15.0;

       

        disc = price * d / 100.0;

        amount = price - disc;

       

    }

   

    public void display() {

        System.out.println("Item Name: " + name);

        System.out.println("Net Amount: " + amount);

    }

   

    public static void main(String args[]) {

        Eshop obj = new Eshop();

        obj.accept();

        obj.calculate();

        obj.display();

    }

}

 

Program 2: Design a class name ShowRoom with the following description:

Instance variables / Data members:
String name — To store the name of the customer
long mobno — To store the mobile number of the customer
double cost — To store the cost of the items purchased
double dis — To store the discount amount
double amount — To store the amount to be paid after discount

Member methods:
ShowRoom() — default constructor to initialize data members
void input() — To input customer name, mobile number, cost
void calculate() — To calculate discount on the cost of
purchased items, based on following criteria

void display() — To display customer name, mobile number, amount to be paid after discount.

Cost

Discount (in percentage)

Less than or equal to ₹10000

5%

More than ₹10000 and less than or equal to ₹20000

10%

More than ₹20000 and less than or equal to ₹35000

15%

More than ₹35000

20%

 

Write a main method to create an object of the class and call the above member methods.

Answer

import java.util.Scanner;

 

public class ShowRoom

{

    private String name;

    private long mobno;

    private double cost;

    private double dis;

    private double amount;

 

    public ShowRoom()

    {

        name = "";

        mobno = 0;

        cost = 0.0;

        dis = 0.0;

        amount = 0.0;

    }

 

    public void input() {

        Scanner in = new Scanner(System.in);

        System.out.print("Enter customer name: ");

        name = in.nextLine();

        System.out.print("Enter customer mobile no: ");

        mobno = in.nextLong();

        System.out.print("Enter cost: ");

        cost = in.nextDouble();

    }

   

    public void calculate() {

        int disPercent = 0;

        if (cost <= 10000)

            disPercent = 5;

        else if (cost <= 20000)

            disPercent = 10;

        else if (cost <= 35000)

            disPercent = 15;

        else

            disPercent = 20;

       

        dis = cost * disPercent / 100.0;

        amount = cost - dis;

    }

   

    public void display() {

        System.out.println("Customer Name: " + name);

        System.out.println("Mobile Number: " + mobno);

        System.out.println("Amout after discount: " + amount);

    }

   

    public static void main(String args[]) {

        ShowRoom obj = new ShowRoom();

        obj.input();

        obj.calculate();

        obj.display();

    }

}

 

2.      SWITCH CASE  BASED QUESTION

 

Program 3: Using the switch-case statement, write a menu driven program to do the following:

(a) To generate and print Letters from A to Z and their Unicode

(b) Display the following pattern using iteration (looping) statement:

Letters

Unicode

A

65

B

66

.

.

.

.

.

.

Z

90

 

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

Answer

import java.util.Scanner;

 

public class Switch1

{

  public static void main(String args[]) {

  Scanner in = new Scanner(System.in);

  System.out.println("Enter 1 for letters and Unicode");

  System.out.println("Enter 2 to display the pattern");

  System.out.print("Enter your choice: ");

  int ch = in.nextInt();

   switch(ch)

   {

    case 1:

    System.out.println("Letters\tUnicode");

            for (int i = 65; i <= 90; i++)

                System.out.println((char)i + "\t" + i);

            break;

           

            case 2:

            for (int i = 1; i <= 5; i++) {

                for (int j = 1; j <= i; j++)

                    System.out.print(j + " ");

                System.out.println();

            }

            break;

           

            default:

            System.out.println("Wrong choice");

            break;

        }

    }

}

 

3.      OPERATOR OVERLOADING  BASED QUESTION

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

1.       double volume (double R) – with radius (R) as an argument, returns the volume of sphere using the formula.
V = 4/3 x 22/7 x R3

2.       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 x R2 x H

3.       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.
V = L x B x H

Answer

public class Volume

{

    double volume(double r) {

        return (4 / 3.0) * (22 / 7.0) * r * r * r;

    }

   

    double volume(double h, double r) {

        return (22 / 7.0) * r * r * h;

    }

   

    double volume(double l, double b, double h) {

        return l * b * h;

    }

   

    public static void main(String args[]) {

        Volume obj = new KboatVolume();

        System.out.println("Sphere Volume = " +

            obj.volume(6));

        System.out.println("Cylinder Volume = " +

            obj.volume(5, 3.5));

        System.out.println("Cuboid Volume = " +

            obj.volume(7.5, 3.5, 2));

    }

}

 

4.       STRING  BASED QUESTION

Program 5: Write a program in Java to accept a string in lower case and change the first letter of every word to upper case. Display the new string.

Sample input: we are in cyber world
Sample output: We Are In Cyber World

Answer

import java.util.Scanner;

 

public class StringPro

{

    public static void main(String args[]) {

        Scanner in = new Scanner(System.in);

        System.out.println("Enter a sentence:");

        String str = in.nextLine();

        String word = "";

 

        for (int i = 0; i < str.length(); i++) {

            if (i == 0 || str.charAt(i - 1) == ' ') {

                word += Character.toUpperCase(str.charAt(i));

            }

            else {

                word += str.charAt(i);

            }

        }

 

        System.out.println(word);

    }

}

 

5.      ARRAY BASED QUESTIONS

Binary Search

Program

Define a class to perform binary search on a list of integers given below, to search for an element input by the user, if it is found display the element along with its position, otherwise display the message “Search element not found”.       [ICSE 2020]

2,  5,  7, 10, 15, 20, 29, 30, 46, 50

Solution:-

import java.util.*;

public class BSearch

{

      public static void main(String args[])

      {

         int x[]={2,  5,  7, 10, 15, 20, 29, 30, 46, 50};

       int srch;

          int l=0,m=0,u=x.length;

       Scanner sc=new Scanner(System.in);

          System.out.println("Enter Value to Search : ");

          srch=sc.nextInt();

          while(l<u)

          {

              m=(l+u)/2;

              if(x[m]>srch)

              {

                  u=m-1;

              }

              else if(x[m]<srch) 

              {

                  l=m+1;

              }

              else

              {

                  pos=m;

                    flag=1;

                     break;

              }   

          }

        if(flag==1)

        {

          System.out.println("Value Found at position "+(pos)+" position");

 

        }

        else

        {

          System.out.println("Value Not Found!");

 

        }

     }

 

  }

 

Visit to my blog:

https://mukulsiricsenotes.blogspot.com/

 

 


No comments:

Post a Comment

CLASS X TYPES OF NUMBERS

 CLASS X  TYPES OF NUMBERS List of types of Numbers 1. Arm Strong Number 2.  Co-prime Number 3. Duck Number [I.C.S.E 2024] 4. Magic Number  ...