Technical Tips Trick and Java Tutorials

Technical Tips Tricks and Tutorials. Java program for school and college students and also programming concept. Contact for online classes via skype : smartinspireskills@gmail.com

Thursday, 10 August 2017

ICSE Class X Computer Applications ( Java ) Solved Model Question Papers

ICSE Class X Computer Applications ( Java ) Solved Question Papers

ICSE Class X solved model paper for 2018

Model Paper Solved
Section A (40 Marks)
Attempt all question

Question 1.
a.       Define Encapsulation.
Ans: The wrapping of data and function together into a single unit is called Encapsulation.
b.      Name any two OOP’s principles
Ans: Inheritance and Polymorphism
c.       Define Object with an example.
Ans:  Object: An instance of a class called Object. The table is an instance of class Furniture.
Class: Blue print of an object is called Class. Example, mango, apple, and orange are members of the class fruit.
d.      What is wrapper class? Give example.
e.      A wrapper class is a class which wraps a primitive data type. Example Double, Float, Integer

Question 2.
a.       What is a class variable?
Ans: Instance variables having the keyword static before it is a class variable. For every object, there is just one copy of the variable made.
b.      What is the significance of import java.io.* in your program?
Ans: The line imports all the classes of the java.io package into the current program.
c.       State the two kinds of data types.
Ans: The two kinds of data types in Java are primitive and reference data types.
d.      Define impure function.
Ans: Impure Function: A function that brings about a change in the argument that it receives. Its arguments will always be reference types. It may or may not return value. In other words, an impure function brings about a change in the state of the function. This change in state is called the side effect of calling an impure function.
Example:
Static void count(Number num) 
{
        num.counter=num.counter+1;
}
e.      What are comments? Name the different types.
Ans: Comments are statements which enhance the readability and understanding of the program. They are not part of the program.
The different types are: single line (//….), multiple line (/* … */) and documenting comment (/**….*/).

Question 3.
a.       What is meant by the private visibility of a method?
Ans:  The visibility of private method restricted to the class itself. It is not visible to anywhere outside the class.
b.      What is a variable?
Ans: A variable is a named memory location whose value can change. Example int a,b;
c.       What is the use of return keyword?
Ans: A return keyword is used to return any value from a function. It denotes the end of a function.
d.      What is call by value?
Ans: In call by value arguments are passed by the value, which means that a copy of the arguments is passed to the method can make changes to the value of this copy but can not change the values of the original variables in the calling method.
e.      What is meant by an infinite loop? Give an example.
Ans: An infinite loop is a loop whose test condition is always true. This type of loop never ends by itself. For example:
for(i=1;i>0;i++)
{
        System.out.println(“Hello”);
}
f.        State any two objectives of using Arrays.
Ans:  1. Use hold elements in contiguous memory location. 2. Arrays are used to group storage locations.






Section B (60 Marks)
Attempt any four questions from this Section

Question  4.
Design a program in Java to calculate the tax for the people living in Mango city. Specify a class taxpayer whose class description is given below:                                                                                                                                                                                    [15]
Class name:                                         TaxCalculator
Data members:                                    int PAN
                                                                String name
                                                                double  taxableIncome
                                                                double  tax
Member methods:                               inputData()
                                                            displayData()
                                                            computeData()
The tax is calculated according to the following rules:
Total Annual Taxable Income
Rate of Taxation
Up to 60000
0%
Above 60000 but up to 150000
5%
Above 150000 but up to 500000
10%
Above 500000
15%

Solution
import java.io.*;
/**
 * class TaxCalculator here.
 *
*
 */
public class TaxCalculator
{
       int pan;
       String name;
       double taxableIncome;
       double tax;
       void input()throws IOException
       {
              InputStreamReader in=new InputStreamReader(System.in);
              BufferedReader br=new BufferedReader(in);
              System.out.println("Enter name and taxable income:");
              name=br.readLine();
               taxableIncome=Double.parseDouble(br.readLine());
       }
      void computeData()
      {
               if(taxableIncome<=60000)
                   tax=0;
               else if(taxableIncome>60000 && taxableIncome<=150000)
                  tax=taxableIncome*0.05;
               else if(taxableIncome>150000 && taxableIncome<=500000)
                  tax=taxableIncome*0.1;
             else
                  tax=taxableIncome*0.2;
      }
      void displayData()
      {
        System.out.println("Display Data”);
        System.out.println("Name =" + name);
        System.out.println("Taxable Income =" + taxableIncome);
        System.out.println("Tax Paid =" + tax);
    }
    
    public static void main(String args[])throws IOException
    {
        TaxCalculator ob=new TaxCalculator();
        ob.input();
        ob.computeData();
        ob.displayData();
    }
}
Output:
Enter name and taxable income:
Rehan
120000
Display Data
Name=Rehan
Taxable Income=120000.0
Tax Paid=6000.0

Question 5
Write a menu driven program to convert Fahrenheit to Celsius and Celsius to Fahrenheit.

Solution:
import java.io.*;
import java.io.*;
/**
 * Class FahrenToCelsius
*
 */
public class FahrenToCelsius
{
    public static void main(String args[])throws IOException
    {
        int ch,c,f;
        InputStreamReader ab=new InputStreamReader(System.in);
        BufferedReader br=new BufferedReader(ab);
        // Menu List
        System.out.println("Enter 1. Farenheit to Celsius:");
        System.out.println("Enter 2. Celsius To Farenheit:");
        System.out.print("Enter Choice :");
        ch=Integer.parseInt(br.readLine());
        // switch statement
        switch(ch)
        {
            case 1:
                System.out.print("Enter Temperature in Farenheit :");
                f=Integer.parseInt(br.readLine());
                c=((f-32)*5)/9;
                System.out.println("Temperature in Celsius :"+c);
                break;
            case 2:
                System.out.print("Enter Temperature in Celsius :");
                c=Integer.parseInt(br.readLine());
                f=(9*c/5)+32;
                System.out.println("Temperature in Farenheit :"+f);
                break;
       }
    }
}

Output :
Enter 1. Farenheit to Celsius:
Enter 2. Celsius To Farenheit:
Enter Choice :1
Enter Temperature in Farenheit :100
Temperature in Celsius :37
Enter 1. Farenheit to Celsius:
Enter 2. Celsius To Farenheit:
Enter Choice :2
Enter Temperature in Celsius :100
Temperature in Farenheit :212

Question 6.
 Write a class Automorphic  to check whether a number is Automorphic or not using function with the help of a method
Int digit(int n)
Solution
import java.io.*;
/**
 * class Automorphic
*
 */
public class Automorphic
{
    int digits(int n)
    {
        int c,p,k;c=0;k=0;
        while(n!=0)
        {
            k=n/10;
            c=c+1;
            n=k;
        }
        return(c);
    }

    public static void main(String args[])throws IOException
    {
        InputStreamReader read =new InputStreamReader(System.in);
        BufferedReader in =new BufferedReader(read);
        int m,n,p,b;
        double r;
        r = 0;
        Automorphic ob= new Automorphic();
        System.out.println("Enter your no.");
        n=Integer.parseInt(in.readLine());
        m= n;
        p= m * m;
        b=ob.digits(n);
        r=p % (Math.pow(10,b));
        if(m==r)
            System.out.println(m + " is an Automorphic no.");
        else
            System.out.println(m + " is not an Automorphic no.");
    }
}

Output;
Enter your no.
625
625 is an Automorphic no.
Enter your no.
525
525 is not an Automorphic no.
Question 7
. A cloth showroom has announced the following festival discounts on the purchase of items based on
    the total cost of the items purchased:
                                    Total cost                                   Discount (in Percentage)
                                    Less than Rs. 2000                                  5%
                                    Rs. 2001 to Rs. 5000                              25%
                                    Rs. 5001 to Rs. 10000                            35%
                                    Above Rs. 10000                                   50%     
     Write a program to input the total cost and to compute and display the amount to be paid by the customer after availing the discount. Three methods also their input(), calculate() and display().

Solution
import java.io.*;
/**
 * class Showroom
 *
*/
public class Showroom
{
    private double cost;    // For cost
    private double dis;     // For Discount
    private double amt;     // For Amount
    void input()throws IOException
    {
        InputStreamReader in=new InputStreamReader(System.in);
        BufferedReader br=new BufferedReader(in);
        System.out.println("Enter Cost of the product:");
        cost=Double.parseDouble(br.readLine());
    }
    void calculate()
    {
        if(cost<=2000)
          dis = cost * 0.05;
        else if(cost>2000 && cost<=5000)
          dis = cost * 0.25;
        else if(cost>5000 && cost<=10000)
          dis = cost *0.35;
        else
          dis = cost * 0.5;
        amt= cost - dis;
    }    
    void display()
    {
        System.out.println("Cost of the product="+cost);
        System.out.println("Discount given="+dis);
        System.out.println("Amount Paid="+amt);
    }
    public static void main(String args[])throws IOException
    {
        Showroom ob=new Showroom();
        ob.input();
        ob.calculate();
        ob.display();
    }
}
Output:
 Enter Cost of the product:
5630
Cost of the product=5630.0
Discount given=1970.4999999999998
Amount Paid=3659.5

Question 8.
Write a program to enter a sentence. Calculate total Vowel, Space, Consonant, and word.

Solution.
import java.io.*;
/**
 * class SentenceCounter
 *
* Vowel, Space, Consonant  and word counter program
 */
class SentenceCounter
{
                public static void main(String args[])throws IOException
                {
                                String st="";
                                int i,l,v,c,sp;
                                char a;
                                v=c=sp=0;
                                InputStreamReader in=new InputStreamReader(System.in);
        BufferedReader br=new BufferedReader(in);
                                System.out.println("Enter a sentence:");
                                st=br.readLine();
                                l=st.length();
                                for(i=0;i<l;i++)
                                {
                                                a=st.charAt(i);
                                                if(a=='a' || a=='A' || a=='e' || a=='E' || a=='i' || a=='I' || a=='o' || a=='O' || a=='u' || a=='U')
                                                 v++;
                                                 if(a==' ')
                                                  sp++;

                                }
                                c=l-(v+sp);
                                System.out.println("Total Vowel="+v);
                                System.out.println("Total Space="+sp);
                                System.out.println("Total Consonent="+c);
                                System.out.println("Total Words="+(sp+1));
                }
}

Output:
Enter a sentence:
the quick brown fox jumps over a lazy hungry dog
Total Vowel=13
Total Space=9
Total Consonent=27
Total Words=10

Question 9.
Define a class Employee having the following description :
Instance variables  :
int pan  – to store personal account number
String name – to store name
double taxIncome – to store annual taxable income
double tax – to store tax that is calculated
Member functions :
input ( ) – Store the pan number, name, taxable income
calc( ) – Calculate tax for an employee
display ( ) – Output details of an employee
Write a program to compute the tax according to the given conditions and display the output as per given format.
Total Annual Taxable Income        Tax Rate
Upto Rs, 1,00,000                                      No tax
From 1,00,001 to 1,50,000                   10% of the income exceeding Rs. 1,00,000
From 1,50,001 to 2,50,000                   Rs. 5000 + 20% of the income exceeding Rs. 1,50,000
Above Rs. 2,50,000                                   Rs. 25,000 + 30% of the income exceeding Rs. 2,50,000
Output :
Pan Number                  Name                                    Tax-income                 Tax       
=======                    ==========                          =========                            =====
=======                    ==========                          =========                            =====
=======                    ==========                          =========                            =====

Solution
  import java.io.*;
/**
 * class Employee
 *
*
 */
class Employee
{
    // instance variables
    int pan;
    String name;
    double taxIncome, tax;

    // read the data from keyboard
    public void input()throws IOException
    {
        InputStreamReader in = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(in);
        System.out.println("Enter the name, pan and taxable income : ");
        name = br.readLine();
        pan = Integer.parseInt(br.readLine());
        taxIncome = Double.parseDouble(br.readLine());
       
    }

    // Method calculate tax
    public void calc()
    {
        tax = 0.0;
        if( (taxIncome > 100000) && (taxIncome <= 150000) )
          tax = (taxIncome - 100000) * 0.1;
        else if( (taxIncome > 150000) && (taxIncome <= 250000) )
          tax = 5000.0 + (taxIncome - 150000) * 0.2;
        else
          tax = 25000.0 + (taxIncome - 250000) * 0.3;
    }

    // display details of an employee
    public void display()
    {
        System.out.println("Pan Number        Name                 Tax-income         Tax");
        System.out.println(pan+"           " + name + "               " + taxIncome + "      " + tax);
    }
// Main method
    public static void main(String args[])throws IOException
    {
        Employee ob=new Employee();
        ob.input();
        ob.calc();
        ob.display();
    }
}

Output:
Enter the name, pan and taxable income :
Abdulla
20938
150000
Pan Number        Name                 Tax-income         Tax
20938                 Abdulla               150000.0      5000.0


More useful link

Java method or function


Saturday, 8 July 2017

Three best 10 years books for ICSE exam 2018


Three best 10 years books for ICSE exam 2018


First Book
ICSE is a very important exam for student’s life. A great number or position will make a great career. So it is important to read and study good books for the examination. ICSE Class 10 students previous read 10 years Question and Answer book. In this regard I strongly recommend ICSE 10 Years Solved Papers Chapter wise Class X for 2018 Examination Superior Publications, it is an awesome book. 
ICSE 10 years Chapter wise book

It is very helpful to students in preparing for exams. Over the years there have been frequent changes in the patterns and trends in the paper setting. This volume will positively help a student to develop deep insight into the subject as well as chapters and prepare him/her to attempt questions from various angles. Students will also be acquainted with the design of units and distribution of marks within the chapters of specific subjects. Also, after going through this edition of book students will benefit from the advance knowledge of the type and style of questions asked. As the book contains an ample number of previous years' solved questions in subject-wise and chapter-wise form, so I think this is a very good 10 years book.
Buy from Amazon 

Second Book


ICSE 10 years question and answer book



It is also very good and useful book for ICSE 10 exam preparation. This book contains year wise question and answers for the last 10 years. So if any student follows the last ten years pattern of the question then he or she will definitely score good marks in the ICSE 10 final exam.

Buy from Amazon 

Third Book

ICSE Last 10 Years Solved Papers Class 10 For 2018 Examinations (Bengali Paper Included) By Gurukul Books & Packaging
This is another great book for ICSE 2018 exam.It contains ten years solved materials by a team of experienced teachers. 
Buy from Amazon

Monday, 10 April 2017

java program for spy number

java program for spy number

Spy Number program

Write a program to accept a number and check and display whether it is a Spy Number or not.
A Number is spy number if the sum of its digits equals the product of its digits.
 Example : consider the number 1124
 Sum of the digits = 1 + 1 + 2 + 4
 Product of the digits = 1 * 1 * 2 * 4



// ICSE 2017 Question Answer

import java.util.*;
public class SpyNumber
{
    public static void main(String args[])
    {
        int no, pro, sum, digit;
        pro = 1;
        sum = 0;
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter a number to check spy number :");
        no = sc.nextInt();
        while(no != 0)
        {
            digit = no % 10;
            pro = pro * digit;
            sum = sum + digit;
            no = no / 10;
        }
        if(sum == pro)
        {
            System.out.println("Spy Number");
        }
        else
        {
            System.out.println("Not Spy Number");
        }
    }
}


Output:
Enter a number to check spy number:
1124
Spy Number
Enter a number to check spy number:
1254
Not Spy Number

Variable Description

Sr. No
Variable / Function
Type
Description
1
no
int
Taking number for spy number checking
2
pro
int
For product of digits
3
sum
int
For summation of digits
4
digit
int
Digit to add pr multiply
5
sc
Object
Scanner class object

More Java Program

circular prime number program in java

Monday, 27 March 2017

Java Program for BinarySearch

Java Program for BinarySearch


Java Program for Binary Search


From Wikipedia
In computer science, binary search, also known as half-interval search, logarithmic search, or binary chop, is a search algorithm that finds the position of a target value within a sorted array. Binary search compares the target value to the middle element of the array; if they are unequal, the half in which the target cannot lie is eliminated and the search continues for the remaining half until it is successful or the remaining half is empty.
This search method uses low and high positions and matches with the middle element. The array must be in sorted order and low and high positions are changed in order to search the given data(mid = (low + high) / 2. If the given value is less than mid value then high = mid - 1. If the value is greater then mid value then low = mid + 1 and if the given value is equal to the mid value then the search result found and printed.
The time complexity of above algorithm is O(n).   


Java Program

import java.util.*;
public class BinarySearch
{
    public static void main(String arg[])
    {
        int n[]={1,4,6,7,8,9,10,11,14,15,16};
        int low,high,mid,p=0,l,i,m;
        l=n.length;
        low=0;
        high=l;
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter number to search:");
        m=sc.nextInt();
        while(low<=high)
        {
            p++;
            mid=(low+high)/2;
            if(m<n[mid])
             high=mid-1;
            else if(m>n[mid])
             low=mid+1;
            else if(m==n[mid])
            {
                System.out.println(m+" is located at "+mid+1);
            }
        }
    }
     
}




Saturday, 25 March 2017

Wrapper class in Java

java wrapper class
Wrapper class in Java
According to Wikipedia “In object-oriented programming, a wrapper class is a class that encapsulates types, so that those types can be used to create object instances and methods in another class that needs those types. So a primitive wrapper class is a wrapper class that encapsulates hides or wraps data types from the eight primitive data so that these can be used to create instantiated objects with methods in another class or in other classes. The primitive wrapper classes are found in the Java API.”



It is a process by which we can convert primitive data type into object types.  Every primitive data type has its own wrapper class.
Primitive Type
Wrapper class
boolean
Boolean
char
Character
byte
Byte
short
Short
int
Integer
long
Long
float
Float
double
Double

All the wrapper class is the sub classes of the abstract number class.

Java data types are primitive by default and sometimes we require to represent as an object so we need to wrap the primitive data type in a class.
class WrapperClassExample
{
    public static void main(String[] args)
    {
        String a = "20";
        String b = "30";
        int f1, f2, result;
        System.out.println("Sum before:"+ a + b); // print 2030 not 50
        f1 = Integer.parseInt(a); // convert String to int type
        f2 = Integer.parseInt(b); // convert String to int type
        result = f1 + f2;
        System.out.println("sum after: " + result); // 50
    }
Sample output
Sum before:2030
sum after: 50

In this program we try to add a and b it will give 2030 not 50 because “20” and “30” are not integer type. So if need to sum it up then we need to convert String to int type.

Buy some important Computer Books Books 
Java: The Complete Reference by Herbert Schildt
Java: A Beginner's Guide, Sixth Edition by Herbert Schildt
DSSSB TGT,PGT COMPUTER SCIENCE GUIDE-CUM-PWB (E) - 1039 by Think Tank of Kiran Prakashan (Author)
UGC NET/JRF/SET Computer Science and Applications: Paper II & III by Chandresh Shah (Author), Saurab Mishra (Author)