Class 9 Computer Application Half Yearly 2018

Section A [40 Marks]

Q1. a) State the package that contains the class:
(i) BufferedReader – java.io
(ii) Scanner – java.util
b) Write a Java statement to create an object mp4 of class digital.
digital mp4 = new digital();
c) Which OOP principle implements function overloading?
Polymorphism.
d) State the Java concept that is implemented through:
(i) A superclass and a subclass. (Inheritance)
(ii) The act of representing essential features of a class without including the background details. (Data Abstraction)
e) Name any two non-primitive data types.
Arrays and Strings.

Q2. a) Predict the return data type of the following:
(i) int p; double q;
r = p + q;
System.out.println(r); (double)
(ii) float m;
p = m / 3 * (Math.pow(4, 3));
System.out.println(p); (double)
b) Rewrite the following code using if-else statement:
String grade = (marks >= 90)? “A” : “B”;
String grade = “”;
if(marks >= 90)
grade = “A”;
else
grade = “B”;
c) Give the output of the following code:
public static void main(String args[]){
int a = 5;
a++;
System.out.println(a);
a -= (a–) – (–a);
a -= (a–) – (–a);
System.out.println(a);
OUTPUT:
6
2
d) What is the difference between / and % operator?
/ is used to get the result after dividing two numbers.
% is used to get the remainder after dividing two numbers.
e) What will be the output of the following code?
int k = 7, j = 10;
k += k++ – ++j + k;
System.out.println(“k = ” + k);
System.out.println(“j = ” + j);
OUTPUT:
k = 11
j = 11

Q3. a) What is the use of the keyword ‘import’ in Java?
The ‘import’ keyword is used to include the classes and interfaces from a given package.
b) Name any two types of errors in Java.
Syntax and Runtime errors.
c) Name two jump statements in Java.
break and continue.
d) Name any two ways to manage the flow of control in a program.
Normal and Bi-directional flow of controls.
e) What do you understand by the term data abstraction?
It is the act of representing the essential features without knowing the background details.
f) Give the output of the following code:
int i, j;
for(i = 0; i < 4; i++){
for(j = i; j >= 0; j–)
System.out.print(j);
System.out.println();
}
0
10
210
3210
g) Name any two tokens used in Java.
Identifiers and Keywords.
h) What will be the result stored in ‘x’ after evaluating the following expressions?
(i) int x = 4;
x += x++ + ++x + x;
x = 20.
(ii) int x = 5;
x -= x– – ++x – x;
x = 10.
i) Name the method of Scanner class that:
(i) is used to input an integer data from the standard input device.
nextInt()
(ii) is used to input a string data from the standard input device.
nextLine()

Section B [60 Marks]

Q4. a) Write a program to accept an integer from the user and check if it is a Buzz Number. A Buzz Number is one that either ends with 7, or the number is divisible by 7.
b) Write variable list for the above program.

import java.io.*;
class Buzz{
    public static void main(String args[])
    throws IOException{
        InputStreamReader in = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(in);
        System.out.print("N = ");
        int n = Integer.parseInt(br.readLine());
        if(n % 10 == 7 || n % 7 == 0)
            System.out.println(n + " is a Buzz Number.");
        else
            System.out.println(n + " is not a Buzz Number.");
    }
}

Q5. a) Write a program to input the measure of three angles and check whether the triangle is possible or not. If possible, then check whether it is an acute-angled triangle, right-angled triangle or an obtuse-angled triangle. Display a suitable message for each possible case.
b) Write the variable list for the above program.

import java.io.*;
class Triangle{
    public static void main(String args[])
    throws IOException{
        InputStreamReader in = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(in);
        System.out.println("Enter three angles:");
        int a = Integer.parseInt(br.readLine());
        int b = Integer.parseInt(br.readLine());
        int c = Integer.parseInt(br.readLine());
        int sum = a + b + c;
        if(sum == 180 && a > 0 && b > 0 && c > 0){
            System.out.println("Triangle possible.");
            if(a < 90 && b < 90 && c < 90)
                System.out.println("Acute-angled triangle.");
            else if(a == 90 || b == 90 || c == 90)
                System.out.println("Right-angled triangle.");
            else
                System.out.println("Obtuse-angled triangle.");
        }
        else
            System.out.println("Triangle not possible.");
    }
}

Q6. a) West Bengal State Electricity Board calculates electricity bill for their consumers according to the units consumed per month as per the given tariff:

UNITS CONSUMED                          CHARGES
Upto 100 units Rs. 1.50/unit
More than 100 units & upto 300 units Rs. 2.30/unit
More than 300 units & upto 500 units Rs. 2.80/unit
More than 500 units Rs. 3.50/unit

Write a program to input name of the consumer, consumer number, month and units consumed. Calculate and display the electricity bill with all the details.
b) Give variable listing of the program.

import java.io.*;
class ElectricityBill{
    public static void main(String args[])
    throws IOException{
        InputStreamReader in = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(in);
        System.out.print("Consumer name: ");
        String n = br.readLine();
        System.out.print("Consumer number: ");
        int cno = Integer.parseInt(br.readLine());
        System.out.print("Month: ");
        String month = br.readLine();
        System.out.print("Units consumed: ");
        int u = Integer.parseInt(br.readLine());
        double bill = 0.0;
        if(u <= 100)
            bill = u * 1.50;
        else if(u > 100 && u <= 300)
            bill = u * 2.30;
        else if(u > 300 && u <= 500)
            bill = u * 2.80;
        else
            bill = u * 3.50;
        System.out.println("Consumer name: " + n);
        System.out.println("Consumer No. " + cno);
        System.out.println("Month: " + month);
        System.out.println("Units consumed: " + u);
        System.out.println("Bill: Rs. " + bill);
    }
}

Q7. a) A cloth showroom has announced festival discounts and the gifts on the purchase of items based on the total cost as given below:

TOTAL COST                DISCOUNT           GIFT
Upto Rs. 2000 5% Calculator
Rs. 2001 to Rs. 5000 10% School Bag
Rs. 5001 to Rs. 10,000 15% Wall Clock
Above Rs. 10,000 20% Wrist Watch

Write a program to input the total cost. Compute and display the amount to be paid by the customer along with the gift.
b) Give variable listing of the program.

import java.io.*;
class Showroom{
    public static void main(String args[])
    throws IOException{
        InputStreamReader in = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(in);
        System.out.print("Total cost: ");
        double c = Double.parseDouble(br.readLine());
        String gift = "";
        double dp = 0.0;
        double amt = 0.0;
        if(c <= 2000){
            gift = "Calculator";
            dp = 5.0;
        }
        else if(c > 2000 && c <= 5000){
            gift = "School Bag";
            dp = 10.0;
        }
        else if(c > 5000 && c <= 10000){
            gift = "Wall Clock";
            dp = 15.0;
        }
        else{
            gift = "Wrist Watch";
            dp = 20.0;
        }
        amt = c - dp / 100 * c;
        System.out.println("Gift: " + gift);
        System.out.println("Amount: Rs. " + amt);
    }
}

Q8. a) Write a program in Java to find the sum of the series:
s = a – a / 2 + a / 3 – a / 4 … – a / 20.
b) Write the variable description for the above program.

import java.io.*;
class Series{
    public static void main(String args[])
    throws IOException{
        InputStreamReader in = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(in);
        System.out.print("a = ");
        double a = Double.parseDouble(br.readLine());
        double sum = 0.0;
        int sign = 1;
        for(int i = 1; i <= 20; i++){
            double t = a / i * sign;
            sum += t;
            sign = sign * (-1);
        }
        System.out.println("Sum = " + sum);
    }
}

Q9. a) Write a program in Java to enter a number. Find its reverse. Test and display whether it is palindrome or not. For example, 121 is a palindrome.
b) Write the variable description for the above program.

import java.io.*;
class Palindrome{
    public static void main(String args[])
    throws IOException{
        InputStreamReader in = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(in);
        System.out.print("N = ");
        int n = Integer.parseInt(br.readLine());
        int rev = 0;
        for(int i = n; i > 0; i /= 10)
            rev = rev * 10 + i % 10;
        if(n == rev)
            System.out.println(n + " is Palindrome.");
        else
            System.out.println(n + " is not Palindrome.");
    }
}

9 thoughts on “Class 9 Computer Application Half Yearly 2018

Leave a Reply