Computer App With BlueJ-9 - TM - 2023
Computer App With BlueJ-9 - TM - 2023
Understanding ICSE
Computer Applications With Blue J
Class IX
Published by:
Avichal Publishing Company
Industrial Area, Trilokpur Road
Kala Amb 173 030, Distt. Sirmour (HP)
Delhi Office:
1002, Faiz Road (opp. Hanumanji Murti)
Karol Bagh, New Delhi 110 005 (India)
Phone: 011-41525819, 35543752
email: [email protected]
Website: www.apcbooks.co.in
ISBN–978-81-XXXX-XXX-X
© Authors
Price: ` ……….00
Printed at:
…………
……………
Preface
—AUTHORS
Contents
4. Operators in Java 19
5. Input in Java 25
1
6. Procedure Oriented Programming
Ans. Procedure Oriented Programming basically consists of a list of instructions
for the computer to follow and these are organised into groups known
as functions. In Procedure Oriented Programming, most of the functions
share global data and this data moves more openly around the system
from one function to the other.
7. Inheritance
Ans. Inheritence can be defined as the process where one class acquires the
properties of another class. The class which inherits the properties of
other class is known as the sub-class (derived class) and the class whose
properties are inherited is known as super class (base class).
8. Assembly Language
Ans. In assembly language, the instructions are written more in English like
words knowns as mnemonics. These instructions are not understood
by the processor directly. They are converted into equivalent machine
code through a translator program called Assembler. Assembly language
is machine dependent that makes it unsuitable for writing portable
programs that can execute across machines.
V. Distinguish between:
1. Object Oriented Programming and Procedure Oriented Programming
Ans. Object Oriented Programming Procedure Oriented
Programming
The stress is put on data rather than The stress is put on function rather
functions. than data.
The data is restricted and used in a It allows data to flow freely
specific program area. throughout the program.
It follows bottom-top programming It follows top-down programming
approach. approach.
9
(d) class Book
Ans. Characteristics Methods
Name Input( )
ISBN Number Read( )
Price
Author
Publisher
(e) class Park
Ans. Characteristics Methods
Name OpenPark( )
Address ClosePark( )
ENtry
Opening Time
Closing Time
(f) class Medicine
Ans. Characteristics Methods
Name Purchase( )
Quantity Sell( )
Price
Manufacturing Date
Expiry Date
(g) class Computer
Ans. Characteristics Methods
Company Input( )
Model Display( )
Processor
RAM
Hard Disk
(h) class Camera
Ans. Characteristics Methods
Company Input( )
Model Display( )
Serial Number
Price
Resolution
14. Write a program by using a class 'Picnic' without any data members but
having only functions as per the specifications given below:
class name : Picnic
void display1( ) : to print venue, place and reporting time
void display2( ) : to print number of students, name of the teacher
accompanying and bus number
Write a main class to create an object of the class 'Picnic' and call the
functions display1( ) and display2( ) to enable the task.
Ans. class Picnic
{
public void display1( )
{
System.out.println("Venue: Dimna Lake");
System.out.println("Place: Jamshedpur");
System.out.println("Reporting Time: 9:00 am");
}
public void display2( )
{
System.out.println("Number of students: 50");
14
7. Explain the term 'type casting'?
Ans. The process of converting one pre-defined data type into another after
the user's intervention, is called type casting.
8. Perform the following:
Ans. (a) Assign the value of pie (3.142) to a variable with the requisite data
type.
double pi = 3.142;
(b) Assign the value of 3 (1.732) to a variable with the requisite data type.
double x = 1.732;
9. Distinguish between:
Ans. (a) Integer and floating constant
Integer Constant Floating Constant
Integer constants represent whole Floating constants represent
number values like 2, –16, 18246, fractional numbers like 3.14159,
24041973, etc. –14.08, 42.0, 675.238, etc.
Integer constants are assigned Floating constants are assigned
to variables of data type such as to variables of data type such as
byte, short, int, long, char. float, double.
(b) Token and Identifier
Token Identifier
A token is the smallest element of Identifiers are used to name
a program that is meaningful to things like classes, objects,
the compiler. variables, arrays, etc.
Tokens in Java are categorised Identifier is a type of token in
into various types such as Java.
Keywords, Identifiers, Literals,
Operators, etc.
(c) Character and String constant
Character Constant String Constant
These constants are written by They are written by enclosing a
enclosing a character within a set of characters within a pair of
pair of single quotes. double quotes.
Character constants are assigned String constants are assigned to
to variables of type char. variables of type String.
(d) Character and Boolean literal
Character Literal Boolean Literal
Character literals are written by A boolean literal can take only
enclosing a character within a one of the two boolean values
pair of single quotes. represented by the words true or
false.
Character literals can be assigned Boolean literals can only be
to variables of any numeric data assigned to variables declared as
type such as byte, short, int, boolean.
double, char, etc.
Operators in Java
19
4. What is a Ternary operator? Explain with the help of an example.
Ans. Ternary operators deal with three operands and evaluates the condition.
Syntax: variable = (test expression)? Expression 1: Expression 2;
If the condition is true then the result of ternary operator is the value of
expression 1. Otherwise, the result is the value of expression 2.
For example,
int a = 5; int b = 3;
int Max = (a>b)? a : b;
Here, the value 5 is stored in Max, as a>b is true.
5. Differentiate between the following:
Ans. (a) Arithmetical operator and Logical operator
Arithmetical Operator Logical Operator
Arithmetic operators are used They operate on boolean
to perform mathematical expressions to combine the results
operations. into a single boolean value.
It results in int, float, double data It results in true or false.
types.
(b) Binary operator and Ternary operator
Binary operator Ternary operator
Binary operators work on two Ternary operators work on three
operands. operands.
It is an arithmetical operator. It is a conditional operator.
Operators in Java 21
(b) a * (++b) % c;
Ans. a * (++b) % c
⇒ a * (++b) % c
⇒ 2 * (4) % 9
⇒8%9
⇒8
12. If a = 5, b = 9, calculate the value of:
a += a++ – ++b + a;
Ans. a += a++ – ++b + a
⇒ a = a + (a++ – ++b + a)
⇒ a = 5 + (5 – 10 + 6)
⇒a=5+1
⇒a=6
13. Give the output of the program snippet given below:
int a = 10, b =12;
if(a>=10)
a++;
else
++b;
System.out.println(" a = " + a + " and b = " +b);
Output: a = 11 and b = 12
14. Rewrite the following using ternary operator.
(a) if(income<=100000)
tax = 0;
else
tax = (0.1*income);
Ans. tax = income <= 100000 ? 0 : (0.1*income);
(b) if(p>5000)
d = p*5/100;
else
d = p*2/100;
Ans. d = p > 5000 ? p * 5 / 100 : p * 2 / 100;
IV. Unsolved Java Programs
1. Write a program to find and display the value of the given expressions:
(a) (x + 3) / 6 – (2x + 5) / 3; taking the value of x = 5
Prog. public class Expression
{
public static void main(String args[ ])
{
int x = 5;
double value = ((x + 3) / 6.0) – ((2 * x + 5) / 3.0);
System.out.println("Result = " + value);
}
}
Operators in Java 23
System.out.println("Percentage Increase = " + p + "%");
}
}
(b) a number is updated from 7.5 to 7.2
Prog. public class Decrease
{
public static void main(String args[ ])
{
double num = 7.5;
double newnum = 7.2;
double inc = num – newnum;
double p = inc / num * 100;
System.out.println("Percentage Decrease = " + p + "%");
}
}
5. The normal temperature of human body is 98.6°F. Write a program to
convert the temperature into degree Celsius and display the output.
[Hint: c / 5 = f – 32 / 9]
Prog. public class Temp
{
public static void main(String args[ ])
{
double f = 98.6;
double c = 5 * (f – 32) / 9.0;
System.out.println("Temperature in Degree Celsius = " + c);
}
}
6. The angles of a quadrilateral are in the ratio 3:4:5:6. Write a program to
find and display all of its angles.
[Hint: The sum of angles of a quadrilateral = 360°]
Prog. public class Display
{
public static void main(String args[ ])
{
int r1 = 3, r2 = 4, r3 = 5, r4 = 6, total;
double a, b, c, d;
total = r1 + r2 + r3 + r4;
a = (double)r1/total * 360;
b = (double)r2 /total * 360;
c = (double)r3 /total * 360;
d = (double)r4 /total * 360;
System.out.println("Angle A = " + a);
System.out.println("Angle B = " + b);
System.out.println("Angle C = " + c);
System.out.println("Angle D = " + d);
}
}
Input in Java
25
3. Testing and Debugging
Ans. Testing Debugging
In this process, we check the validity In this process, we correct the errors
of a program. that were found during testing.
Testing is complete when all Debugging is finished when there
the desired verifications against are no errors and the program is
specifications have been performed. ready for execution.
Input in Java 27
System.out.print("Enter length: ");
l = in.nextDouble( );
System.out.print("Enter the value g: ");
g = in.nextDouble( );
t = 2 * (22.0/7.0) * Math.sqrt(l/g);
System.out.println("Time Peroid = " + t);
}
}
2. Write a program by using class 'Employee' to accept basic pay of an
employee. Calculate the allowances/deductions as given below.
Finally, find and display the gross and net pay.
Input in Java 31
Prog. import java.util.*;
public class Difference
{
public static void main(String args[ ])
{
Scanner in = new Scanner(System.in);
int p;
double si, amt, ci;
System.out.print("Enter principal : ");
p = in.nextInt( );
si = p * 10 * 3/100;
amt = p * Math.pow(1+(10/100.0), 3);
ci = amt – p;
System.out.print("Difference between CI and SI: " + (ci – si));
}
}
10. A shopkeeper sells two calculators for the same price. He earns 20%
profit on one and suffers a loss of 20% on the other. Write a program
to find and display his total cost price of the calculators by taking their
selling price as input.
Hint: CP = (SP/(1 + (profit/100))) (when profit)
CP = (SP/(1 – (loss/100))) (when loss)
Prog. import java.util.*;
public class Calculate
{
public static void main(String args[ ])
{
Scanner in = new Scanner(System.in);
int sp;
double cp1, cp2, totalcp;
System.out.print("Enter the selling price: ");
sp = in.nextInt( );
cp1 = (sp/(1 + (20/100.0)));
cp2 = (sp/(1 – (20/100.0)));
totalcp = cp1 + cp2;
System.out.println("Cost Price of first article = " + cp1);
System.out.println("Cost Price of second article = " + cp2);
System.out.println("Total Cost Price = " + totalcp);
}
}
33
5. Math.log( )
Ans. Returns the natural logarithm value of its argument. Both return type
and argument are of double data type.
VI. Distinguish between them with suitable examples:
1. Math.ceil( ) and Math.floor( )
Ans. Math.ceil( ) Math.floor( )
This function is used to return This function is used to return
the higher integer for the given the lower integer for the given
argument. argument.
double a = Math.ceil(65.5); double b = Math.floor(65.5);
It will result in 66.0. It will result in 65.0.
2. Math.rint( ) and Math.round( )
Ans. Math.rint( ) Math.round( )
Rounds off its argument to the Rounds off its argument to the
nearest mathematical integer and nearest mathematical integer and
returns its value as a double type. returns its value as a long type.
At mid-point, it returns the integer At mid-point, it returns the higher
that is even. integer.
double a = Math.rint(1.5); long a = Math.round(1.5);
double b =Math.rint(2.5); long b = Math.round(2.5);
Both, a and b will have a value of 2.0 a will have a value of 2 and b will
have a value of 3
37
(b) if - else
if - else statement is used to execute one set of statements when the
condition is true and another set of statements when the condition is
false.
Syntax:
if (condition 1)
{
Statement 1;
Statement 2;
………………
}
else
{
Statement 3;
Statement 4;
………………
}
(c) if - else - if
if - else - if ladder construct is used to test multiple conditions and then
take a decision. It provides multiple branching of control.
Syntax:
if (condition)
statement;
else if (condition)
statement;
else if (condition)
statement;
……………….
……………....
else
statement;
4. Differentiate between if and switch statement.
Ans. if switch
if can test for any Boolean switch can only test for equality.
expression.
if doesn't have such limitations. tests the same expression against
constant values.
5. What is the purpose of the switch statement in a program?
Ans. Switch statement is used for multi-way branching. It compares its
expression with multiple case values for equality and executes the case
whose value is equal to the expression of switch. If none of the cases
match, default case is executed.
6. Explain with the help of an example, the purpose of default in a switch
statement.
Ans. When none of the case values are equal to the expression of switch
statement then default case is executed.
Distance Rate
Up to 5 km ` 100
For the next 10 km ` 10/km
For the next 10 km ` 8/km
More than 25 km ` 5/km
Write a program to input the distance covered and calculate the amount
to be paid by the passenger. The program displays the printed bill with
the details given below:
Taxi No. : …………………………
Distance covered : …………………………
Amount : …………………………
Prog. import java.util.*;
public class PrePaidTaxi
{
public static void main(String args[ ])
{
Scanner in = new Scanner(System.in);
int dist, fare;
String tn;
System.out.print("Enter Taxi Number: ");
tn = in.nextLine( );
System.out.print("Enter distance travelled: ");
dist = in.nextInt( );
fare = 0;
if (dist <= 5)
fare = 100;
else if (dist <= 15)
fare = 100 + (dist – 5) * 10;
else if (dist <= 25)
fare = 100 + 100 + (dist – 15) * 8;
else
fare = 100 + 100 + 80 + (dist – 25) * 5;
System.out.println("Taxi No: " + tn);
Write a program to input the name, age and taxable income of a person. If
the age is more than 60 years then display the message "Wrong Category".
If the age is less than or equal to 60 years then compute and display the
income tax payable along with the name of tax payer, as per the table
given above.
Prog. import java.util.*;
public class IncomeTax
{
public static void main(String args[ ])
{
Scanner in = new Scanner(System.in);
int age;
double ti, tax=0.0;
String name;
System.out.print("Enter Name: ");
name = in.nextLine( );
System.out.print("Enter taxable income: ");
ti = in.nextDouble( );
System.out.print("Enter age: ");
age = in.nextInt( );
if (age > 60)
{
System.out.print("Wrong Category");
System.exit(0);
}
else
{
if (ti <= 250000)
tax = 0;
else if (ti <= 500000)
tax = (ti – 160000) * 10/100;
else if (ti <= 1000000)
tax = 34000 + ((ti – 500000) * 20/100);
else
61
(b) Exit controlled loop
Ans. An exit-controlled loop checks the condition after executing its body. If
the condition is true, the loop will perform the next iteration, otherwise
the program control will exit the loop.
For example, do-while loop
6. Write down the general format of:
(a) for loop
Ans. for (initial value; test condition; update)
{
//loop-body
}
(b) do - while loop
do
{
//loop-body
} while (condition);
(c) while loop
while (condition)
{
//loop-body
}
7. What is the purpose of using:
(a) break statement?
Ans. The 'break' statement is also used in looping construct for unnatural
termination of the loop. It can be used in all the loops.
(b) continue statement?
Ans. The continue statement is used to unconditionally jump to the next
iteration of the loop, skipping the remaining statements of the current
iteration.
8. What do you understand by inter-conversion of loops?
Ans. We can convert the repetitive statement using one type of loop into other
type of loops. Thus, the process of converting of some repetitive logic is
coded using a loop into other type of loop is termed as inter-conversion
of loops.
9. What are the different ways to inter-convert the loops? Name them.
Ans. The different ways to inter-convert the loops are:
• for loop to while loop
• for loop to do-while loop
• do-while loop to while loop
• do-while loop to for loop
• while loop to do-while loop
• while loop to for loop
10. Define the following:
(a) Finite loop
Ans. A loop which iterates for a finite number of iterations is termed as a finite
loop.
92
3. How will you terminate outer loop from the block of the inner loop?
Ans. We can terminate outer loop from the block of the inner loop by using
Labelled break statement (break outer).
4. What do you mean by labelled break statement? Give an example.
Ans. Sometimes, it may happen that the outer loop is to be terminated, if a
condition is met in the inner loop. In this situation, the labelled break
statement will be used to serve the purpose.
For example,
int i, j;
outer:
for(i=1;i<=5;i++)
{
for(j=1;j<=3;j++)
{
System.out.println(i*j);
if (j ==2)
break outer; //Labelled break
}
}
5. Write down the syntax of the nested loop.
Ans. The syntax of the nested loop:
1
12
1234
5. int i, j;
first:
for (i=10; i>=5; i– –)
{
for (j= 5; j<=i; j++)
{
if (i*j <40)
continue first;
System.out.print(j);
}
System.out.println( );
}
110
common issues of computer ethics include intellectual property rights
(such as copyrighted electronic content), privacy concerns, and how the
computers affect society.
Five ethical values related to computers are as follows:
• Do not install or uninstall any software without prior permission.
• Never move the peripherals from one place to other unnecessarily.
• While working in a computer lab/room, you must maintain the rules
and regulations of the lab.
• Do not try to steal the secret information of any other computer.
• Do not copy or use proprietary software for which you have not paid.
2. How will you protect your data on the Internet?
Ans. The different ways to protect data on the internet are as follows:
• Do not disclose your passwords to your friends. They may open
different websites and misuse your accounts.
• Do not download unwanted software/free software from the web. It
may corrupt your system.
• Do not read unwanted e-mails, as they might be carrying viruses.
• Install high quality antivirus programs or signatory antivirus of a
reputed company in your computer to protect against viruses.
3. What is meant by malicious code?
Ans. Malicious code refers to a new kind of threat, which corrupts the system
and leaks personal data in due course of time. It is virtually impossible
to recognise such malicious code attacks.
Malicious code is any program that acts in unexpected and potentially
damaging ways (e.g., Trojan Horse). Malicious code can attack
institutions at either the server or the client level. It can also attack into
the infrastructure of a system (i.e., it can change, delete, insert or even
transmit data outside the institution).
Malicious code may be downloaded by the user in the following ways:
• While working on e-mails
• At the time of web surfing
• While downloading files/documents/software
Protection from malicious code involves limiting the capabilities of the
servers and web applications to only functions necessary to support the
operations. User of firewalls and other such network protection devices
prevents ingress of malicious code through the network. There must be
user awareness and training programs to overcome such situations.
4. How will you protect your system from malicious intent and malicious
code?
Ans. You can protect your computer system by using it in a proper and
systematic way. The following precautions can protect your system from
attackers:
• You should use high quality antivirus/signature-based antivirus on
your computer system.
• If you have started downloading a software that you suspect to be
malicious then stop the downloading immediately.
• You should avoid the use of pirated software or unauthorised software
which might cause great damage to your system in due course.
113
IV. Differentiate between the following:
1. Scanner object and BufferedReader object
Ans. Scanner Object BufferedReader Object
It works on the principle of 'Tokens' The buffered allows storing of input
into specific types like int, float, so that the instant supply of data
boolean, etc. as an input. can be done to the CPU without
any delay.
It works in JDK 1.5 version or more. It works in JDK 1.1 version onwards.
V. Unsolved Programs:
1. Using Scanner class, write a program to input temperatures recorded in
different cities in °F (Fahrenheit). Convert and print each temperature
in °C (Celsius). The program terminates when the user enters a non-
numeric character.
c F – 32
Formula:
= =
5 9