if the values of basic = 1500; what will be the values of tax after the following statement get executed.tax=basic>10000?20:100;
Answers
Answer:
ICSE Computer Applications Year 2019
Posted on March 19, 2019
SECTION A (40 Marks)
Question 1
(a) Name any two basic principles of Object-oriented programming.
Encapsulation and Inheritance.
(b) Write a difference between unary and binary operators.
Unary operators work on one operand, whereas binary operators work on two operands.
(c) Name the keyword which:
(i) indicates that a method has no return type.
void
(ii) makes the variable as a class variable.
static
(d) Write the memory capacity (storage size) of short and float data types in bytes.
short occupies 2 bytes.
float occupies 4 bytes.
(e) Identify and name the following tokens:
(i) public
keyword
(ii) ‘a’
constant
(iii) ==
operator
(iv) {}
separator
Question 2
(a) Differentiate between if else if and switch statements.
if else if can test for all types of conditions, whereas switch only tests for equality.
(b) Give the output of the following code:
String p = "20", q = "19";
int a = Integer.parseInt(p);
int b = Integer.valueOf(q);
System.out.println(a + "" + b);
OUTPUT:
2019
(c) What are the various types of errors in Java?
Compile-time error
Runtime error
Logical error
(d) State the data type and value of res after the following is executed:
char ch = '9';
res = Character.isDigit(ch);
boolean
res = true
(e) What is the difference between the linear search and the binary search technique?
Linear search can work on both sorted and unsorted lists, whereas binary search can only work on sorted lists.
Question 3
(a) Write a Java expression for the following:
|x2 + 2xy|
Math.abs(x * x + 2 * x * y)
(b) Write the return data type of the following functions:
(i) startsWith()
boolean
(ii) random()
double
(c) If the value of basic = 1500, what will be the value of tax after the following statement is executed?
tax = basic > 1200 ? 200 : 100;
tax = 200.
(d) Give the output of the following code and mention how many times the loop will execute:
int i;
for(i = 5; i >= 1; i--){
if(i % 2 == 1)
continue;
System.out.print(i + " ");
}
OUTPUT:
4 2
The loop executes 5 times.
(e) State a difference between call by value and call by reference.
Call by value takes place through primitive data types, whereas call by reference takes place through composite data types.
(f) Give the output of the following:
Math.sqrt(Math.max(9, 16))
OUTPUT:
4.0
(g) Write the output for the following:
String s1 = "phoenix";
String s2 = "island";
System.out.println(s1.substring(0).concat(s2.substring(2)));
System.out.println(s2.toUpperCase());
OUTPUT:
phoenixland
ISLAND
(h) Evaluate the following expression if the value of x = 2, y = 3 and z = 1.
v = x + --z + y++ + y;
= 2 + 0 + 3 + 4
= 9
(i) String x[] = {"Artificial intelligence", "IOT", "Machine Learning", "Big data"};
Give the output of the following statements:
(i) System.out.println(x[3]);
Big data
(ii) System.out.println(x.length);
4
(j) What is meant by a package? Give an example.
A package is a collection of related classes and interfaces.
Example: java.io
SECTION B (60 Marks)
Question 4
Design a class named 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,
void display(): to display customer name, mobile number, amount to be paid after discount.
Write a main() method to create an object of the class and call the above member methods.
import java.io.*;
class ShowRoom{
private String name;
private long mobno;
private double cost;
private double dis;
private double amount;
public ShowRoom(){
name = new String();
mobno = 0L;
cost = 0.0;
dis = 0.0;
amount = 0.0;
}
public void input()throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Customer name: ");
name = br.readLine();
System.out.print("Mobile Number: ");
mobno = Long.parseLong(br.readLine());
System.out.print("Cost: ");
cost = Double.parseDouble(br.readLine());
}
public void calculate(){
if(cost <= 10000)
dis = 5.0;
else if(cost <= 20000)
dis = 10.0;
else if(cost <= 35000)
dis = 15.0;
else
dis = 20.0;
dis = dis / 100.0 * cost;
amount = cost - dis;
}
public void display(){
System.out.println("Customer name: " + name);
System.out.println("Mobile Number: " + mobno);
System.out.println("Amount: " + amount);
}
public static void main(String args[])throws IOException{
ShowRoom obj = new ShowRoom();
obj.input();
obj.calculate();
obj.display();
}
}