Library Classes

ICSE Class 10 Computer Applications · Logix Computer Applications · 24 solved questions

Exercise
Marks
11 Mark · Multiple Choice Questions

Which of the following is a primitive data type?

Show SolutionHide Solution↓

All of these

Reason — int, float, char, all three are primitive data types in Java.

21 Mark · Multiple Choice Questions

Which of the following is a composite data type?

Show SolutionHide Solution↓

String

Reason — String is a composite data type.

31 Mark · Multiple Choice Questions

The return type of the isLowerCase() method is ............... .

Show SolutionHide Solution↓

boolean

Reason — The return type of isLowerCase() method is boolean as it returns true if the character argument is in lower case else it returns false.

41 Mark · Multiple Choice Questions

The return type of the toLowerCase() method is ............... .

Show SolutionHide Solution↓

char

Reason — The return type of the toLowerCase() method is char as it converts the given character argument into lower case.

51 Mark · Multiple Choice Questions

The value returned by Integer.parseInt("-321") is ............... .

Show SolutionHide Solution↓

-321

Reason — parseInt() converts the given String argument into an integer value if the given string is a combination of numbers and decimal. The String can have a '-' sign in the beginning.

61 Mark · Multiple Choice Questions

Name the method that can convert a string into its integer equivalent.

Show SolutionHide Solution↓

Integer.parseInt()

Reason — Integer.parseInt() method parses the String argument as a signed integer.

71 Mark · Multiple Choice Questions

What will be the result when the following statement is executed?
int count = new Integer(12);

Show SolutionHide Solution↓

Variable count will be initialised with value 12.

Reason — The given statement initialises the variable count with the integer value 12.

81 Mark · Multiple Choice Questions

In which package is the wrapper class Integer available?

Show SolutionHide Solution↓

java.lang

Reason — All the wrapper classes are available in java.lang package.

1Assignment Questions

What are the library classes in Java? What is their use?

Show SolutionHide Solution↓

Library classes are the pre-written classes which are a part of the Java system. For example, the String and Scanner class.

Java environment has a huge library of library classes that contain pre-defined methods to simplify the job of a programmer. These methods support input/output operations, String handling and help in development of network and graphical user interface.

2(i)Assignment Questions

Define Primitive data type

Show SolutionHide Solution↓

Primitive data types are pre-defined by the language and form the basic building blocks of representing data. They store a single value of a specific declared type at a time. The eight built-in primitive data types in Java are byte, short, int, long, float, double, char, boolean.

2(ii)Assignment Questions

Define Composite data type

Show SolutionHide Solution↓

A composite data type is a data type which can be constructed in a program using the programming language's primitive data types. It is a collection of primitive data types. Examples of composite data types are String and Array.

2(iii)Assignment Questions

Define User-defined data type

Show SolutionHide Solution↓

The data type defined by the user to perform some specific task is known as a user-defined data type. For example, the classes created by the user are user defined data types.

3Assignment Questions

Why is a class called a composite data type? Explain.

Show SolutionHide Solution↓

In a class, one can assemble items of different data types to create a composite data type. The class can also be considered as a new data type created by the user, that has its own functionality. The classes allow these user-defined types to be used in programs. Hence, a class is called a composite data type.

4Assignment Questions

What is a wrapper class? Name three wrapper classes in Java.

Show SolutionHide Solution↓

A wrapper class allows us to convert a primitive data type into an object type. Each of Java's eight primitive data types­ has a wrapper class dedicated to it. These are known as wrapper classes because they wrap the primitive data type into an object of that class.

The three wrapper classes are Integer, Float and Double.

5Assignment Questions

Explain the terms, Autoboxing and Auto-unboxing in Java.

Show SolutionHide Solution↓

The automatic conversion of primitive data type into an object of its equivalent wrapper class is known as Autoboxing. For example, the below statement shows the conversion of an int to an Integer.

Integer a = 20;

Here, the int value 20 is autoboxed into the wrapper class Integer variable myinteger.

Auto-unboxing is the reverse process of Autoboxing. It is the automatic conversion of a wrapper class object­ into its corresponding primitive type. For example,

Integer myinteger = 20;   
int myint = myinteger;

Here, the object myInteger is automatically unboxed into primitive type int variable myint when the assignment takes place.

6Assignment Questions

How do you convert a numeric string into a double value?

Show SolutionHide Solution↓

The wrapper class Double has a method parseDouble() which is used to parse a numeric string into a double value.

Syntax:

Double.parseDouble(String s);

Example:

String str = "437246.643";
double d = Double.parseDouble(str);
7Assignment Questions

Describe wrapper class methods available in Java to parse string values to their numeric equivalents.

Show SolutionHide Solution↓

The wrapper class methods available in Java to parse string values to their numeric equivalents are described below:

  1. parseInt(string) — It is a part of wrapper class Integer. It parses the string argument as a signed integer. The characters in the string must be digits or digits separated with a decimal. The first character may be a minus sign (-) to indicate a negative value or a plus sign (+) to indicate a positive value.
    Syntax:
    int parseInt(String s)

  2. parseLong(string) — It is a part of wrapper class Long. It parses the string argument as a signed long. The characters in the string must be digits or digits separated with a decimal. The first character may be a minus sign (-) to indicate a negative value or a plus sign (+) to indicate a positive value.
    Syntax:
    long parseLong(String s)

  3. parseFloat(string) — It is a part of wrapper class Float. It returns a float value represented by the specified string.
    Syntax:
    float parseFloat(String s)

  4. parseDouble(string) — It is a part of wrapper class Double. It returns a double value represented by the specified string.
    Syntax:
    double parseDouble(String s)

8Assignment Questions

How can you check if a given character is a digit, a letter or a space?

Show SolutionHide Solution↓

We can check if a given character is a digit, a letter or a space by using the following methods of Character class:

  1. isDigit(char) — It returns true if the specified character is a digit; returns false otherwise.
    Syntax:
    boolean isDigit(char ch)

  2. isLetter(char) — It returns true if the specified character is a letter; returns false otherwise.
    Syntax:
    boolean isLetter(char ch)

  3. isLetterOrDigit(char) — It returns true if the specified character is a letter or a digit; returns false otherwise.
    Syntax:
    boolean isLetterOrDigit(char ch)

  4. isWhitespace(char) — It returns true if the specified character is whitespace; returns false otherwise.
    Syntax:
    boolean isWhitespace(char ch)

9(i)Assignment Questions

Distinguish between isLowerCase() and toLowerCase()

Show SolutionHide Solution↓
isLowerCase()toLowerCase()
isLowerCase( ) function checks if a given character is in lower case or not.toLowerCase( ) function converts a given character to lower case.
Its return type is boolean.Its return type is char.
9(ii)Assignment Questions

Distinguish between isUpperCase() and toUpperCase()

Show SolutionHide Solution↓
isUpperCase( )toUpperCase( )
isUpperCase( ) function checks if a given character is in upper case or not.toUpperCase( ) function converts a given character to upper case.
Its return type is boolean.Its return type is char.
9(iii)Assignment Questions

Distinguish between isDigit() and isLetter()

Show SolutionHide Solution↓
isDigit()isLetter()
isDigit() method returns true if the specified character is a digit; returns false otherwise.isLetter() method returns true if the specified character is a letter; returns false otherwise.
9(iv)Assignment Questions

Distinguish between parseFloat() and parseDouble()

Show SolutionHide Solution↓
parseFloat()parseDouble()
parseFloat() method returns a float value represented by the specified string.parseDouble() method returns a double value represented by the specified string.
10Assignment Questions

Define a class (using the Scanner class) to generate a pattern of a word in the form of a triangle or in the form of a­n inverted triangle, depending upon user's choice.

Sample Input:

Enter a word: CLASS  
Enter your choice: 1	    
Sample Output:	            
C
CL
CLA
CLAS
CLASS

Enter your choice: 2
Sample Output:
CLASS
CLAS
CLA
CL
C
import java.util.Scanner;

public class KboatTriangleMenu
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter a word: ");
        String word = in.nextLine();
        System.out.println("Type 1 for a triangle");
        System.out.println("Type 2 for an inverted triangle");
        System.out.print("Enter your choice: ");
        int choice = in.nextInt();
        int len = word.length();
        
        switch (choice) {
            case 1:
                for(int i = 0; i < len; i++) {
                    for(int j = 0; j <= i; j++) {
                        System.out.print(word.charAt(j));
                    }
                    System.out.println();
                }
                break;
                
            case 2:
                for (int i = len - 1; i >= 0; i--) {
                    for (int j = 0; j <= i; j++) {
                        char ch = word.charAt(j);
                        System.out.print(ch);
                    }
                    System.out.println();
                }
                break;
                
            default:
                System.out.println("Incorrect choice");
                break;
        }
    }
}
BlueJ output of KboatTriangleMenu.java BlueJ output of KboatTriangleMenu.java

Solution not available in the source paper.

11Assignment Questions

Define a class called mobike with the following description:

Instance variables/Data members:
int bno - to store the bike's number
int phno - to store the phone number of the customer
String name - to store the name of the customer
int days - to store the number of days the bike is taken on rent
int charge - to calculate and store the rental charge

Member Methods:
void input() - to input and store the details of the customer
void compute() - to compute the rental charge

The rent for a mobike is charged on the following basis:
First five days Rs 500 per day;
Next five days Rs 400 per day;
Rest of the days Rs 200 per day.

void display () - to display the details in the following format:

Bike No.    Phone No.   No. of days     Charge
import java.util.Scanner;

public class Mobike
{
    private int bno;
    private int phno;
    private int days;
    private int charge;
    private String name;
    
    public void input() {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter Customer Name: ");
        name = in.nextLine();
        System.out.print("Enter Customer Phone Number: ");
        phno = in.nextInt();
        System.out.print("Enter Bike Number: ");
        bno = in.nextInt();
        System.out.print("Enter Number of Days: ");
        days = in.nextInt();
    }
    
    public void compute() {
        if (days <= 5)
            charge = days * 500;
        else if (days <= 10)
            charge = (5 * 500) + ((days - 5) * 400);
        else
            charge = (5 * 500) + (5 * 400) + ((days - 10) * 200);
    }
    
    public void display() {
        System.out.println("Bike No.\tPhone No.\tNo. of days\tCharge");
        System.out.println(bno + "\t" + phno + "\t" + days + "\t" + charge);
    }
    
    public static void main(String args[]) {
        Mobike obj = new Mobike();
        obj.input();
        obj.compute();
        obj.display();
    }
}
BlueJ output of Mobike.java

Solution not available in the source paper.

Press ↓ to reveal a solution and move to the next question. Back to Logix Computer Applications.

Free sample bank