Get ICSE class as the basis of all computation solutions for class 10. It will help you to make good preparation before attending the ICSE Board exam. We have provided you with the class as the basis of all computation solutions class 10 to score good marks in your exam.
In ICSE CLass 10, class as the basis of all computation solutions is compulsory to score good marks in computer application. Students Who are planning to score higher marks in class 10 should practice ICSE class as the basis of all computation solutions class 10.
ICSE Class as the Basis of All Computation Solutions Class 10 Computer Applications
A. Tick (✓) the correct option.
1. Which among the following is not a primitive data type?
a. int
b. short
c. String
d. Long
Answer
C
2. Name the operator that is used to allocate memory space for an object.
a. Dot
b. New
c. Both a and b
d. None of these
Answer
B
3. What is the name given to a memory location called in Java?
a. Variable
b. Constant
c. Data Type
d. None of these
Answer
A
4. Which are the data types used in Java?
a. Primitive data type
b. Composite data type
c. Both a and b
d. None of these
Answer
C
5. How are the characteristics of an object represented in a class?
a. Data Members
b. Member Functions
c. Access specifiers
d. None of these
Answer
A
6. Which among the following is used to change the state of an object?
a. Data Members
b. Name of the class
c. Both a and b
d. None of these
Answer
A
7. How is encapsulation implemented in a program?
a. Using a class
b. Using only Functions
c. Using only Variables
d. None of these
Answer
A
8. Information passed to a method through arguments is called _____________.
a. Message
b. Variables
c. Numbers
d. Data
Answer
A
9. What among the following is not a component of a message?
a. An object identifier
b. A method name
c. Arguments
d. Data Members
Answer
D
10. How many objects can you create from a class?
a. One
b. Two
c. Three
d. Any number
Answer
D
SECTION A
A. Answer the following questions.
1. Mention any two attributes required for class declaration.
Ans. i) The keyword ‘class’
ii) The class-name
2. What is a class in Java?
Ans. A class is a mechanism to implement encapsulation. Thus class encloses characteristics represented by data members or variables and behaviour represented by member methods or functions into a single unit. It acts as a blueprint or template for an object.
3. Why is a class called an object factory?
Ans. A class is called an object factory because it acts as a factory for a design or abstraction which produces objects. Each object that is generated from the class will have the same design or abstraction as represented by its data members and member functions.
4. Define Instance Variable. Give an example of the same.
Ans. The data members declared within a class are called instance variables. For example:
class Myclass
{
int a,b;
void getval(int x, int y)
{
a=x;
b=y;
}
}
Here the variables ‘a’ and ‘b’ are instance variables of the class ‘Myclass’.
5. What does the following mean?
Employee stuff = new Employee( );
Ans. An object named ‘stuff’ is being created or memory is being allocated of ‘Employee’ type.
6. How do you declare objects? Show with the help of an example.
Ans. An object is declared using the following general example:
<class-name> <object name>=new <class-constructor>;
For example,
Example ob=new Example();
Here an object named ‘ob’ is being allocated in the memory of ‘Example’ type, which is being initialised with the constructor ‘Example()’.
7. Write Java statement to create an object mp4 of class digital.
Ans. digital mp4=new digital();
8. What is the difference between an object and a class?
Ans. Difference between class and object:
9. What is a variable? How do you initialize a variable?
Ans. Variable is a name given to a memory location in Java.
Initialisation of variables are done during declaration. For example,
int a=5,b=6;
10. What are data types? State its categories.
Ans. Java uses data types to identify data and dictates the method of handling it. It is categorised as Fundamental data type and Composite data type.
11. Why is a class known as a composite data type?
Ans. A composite data type is one which is composed with various primitive data type. A class defined with various primitive data types such as int, double etc. so it is known as a composite data type.
12. Write one difference between primitive data types and composite data types.
Ans.
13. What does a class encapsulate?
Ans. A class encapsulate characteristics represented by data members and behaviour represented by member functions.
14. Why is a class considered to be an abstraction for a group of objects?
Ans. A class is an abstraction because it describes what is created, whereas an object is created itself.
A class acting as an abstraction or blueprint, multiple objects can be created from it.
15. What do you understand by data abstraction? Explain with an example.
Ans. Data Abstraction is the property by virtue of which only the essential details are displayed to the user.
For example, when we ride a bike, we concentrate only driving rather than how the engine is working according to the different switches, lever and steering.
16. Why is an object called an instance of a class?
Ans. An object is called an instance of class as every object created from a class get its own instances of the variables defined in the class.
B. Consider the following code and answer the questions that follow:
class academic
{
int x,y;
void access()
{
int a,b;
academic student=new academic();
System.out.println(“Object Created”);
}
}
a. What is the object name of the class?
b. Name the instance variables used in the class.
c. Write the name of local variables used in the program.
d. Give the type of function being used and its name.
Answer
a. student
b. x and y
c. a and b
d. Procedural function or pure function.
Name: access()
C. Consider the following code and answer the questions that follow:
class vxl
{
int x,y;
void init( )
{
x=5;
y=10;
}
protected void access( )
{
int a=50, b=100;
vxl vin=new vxl( );
vin.int( );
System.out.println(“Object created”);
System.out.println(“I am X=”+vin.x);
System.out.println(“I am Y=”+vin.y);
}
}
a. What is the object name of the class vxl?
b. Name the local variables of class.
c. What is the access specifier of method access( )?
d. Write the output of the above program.
Answer
a. vin
b. a and b
c. protected
d. Output:
Object created
I am X=5
I am Y=10
D. Find the errors in the program given below and rewrite the corrected form:
My class
{
int a;
int b;
void display()
{
System.out.printIn(a+“ ”+b);
}
static void display2()
{
System.out.println(a+“ ”+b);
}
public static void main(String args[ ])
{
My class ob1=new My class( );
display1().ob1;
display2().ob2;
}
}
Answer
class Myclass
{
int a;
int b;
void display1( )
{
System.out.println(a+“ ”+b);
}
void display2( )
{
System.out.println(a+“ ”+b);
}
public static void main(String args[ ])
{
Myclass ob1=new Myclass( );
Myclass ob2=new Myclass( );
ob1.display1();
ob2.display2();
}
}
SECTION B
Write programs for the following:
1. Write a class with name Employee and basic as its data member, to find the gross pay of an employee for the following allowances and deduction. Use meaningful variables.
Dearness Allowance = 25% of the Basic Pay
House Rent Allowance = 15% of Basic Pay
Provident Fund = 8.33% of Basic Pay
Net Pay = Basic Pay + Dearness Allowance + House Rent Allowance
Gross Pay = Net Pay − Provident Fund
Ans.
class Employee
{
double basic;
Employee(double b)
{
basic=b;
}
void calc()
{
double pf,gp,np,hra,da;
da=25/100.0*basic;
hra=15/100.0*basic;
pf=8.33/100*basic;
np=basic+da+hra;
gp=np-pf;
System.out.println(“Gross Pay=”+gp);
}
}
2. Define a class ‘Salary’ described as below:
Data Members:
Name, Address, Phone, Subject Specialisation, Monthly Salary, Income Tax.
Member methods:
i. To accept the details of a teacher including the monthly salary.
ii. To display the details of the teacher.
iii. To compute the annual Income Tax as 5% of the annual salary above ` 1,75,000/-.
Write a main method to create object of the class and call the above member method.
Ans.
import java.util.*;
class Salary
{
String Name, Address,subSpe;
double mSal,it;
long phone;
void input()
{
Scanner sc=new Scanner(System.in);
System.out.println(“Enter your name:”);
Name=sc.nextLine();
System.out.println(“Enter your address:”);
Address=sc.nextLine();
System.out.println(“Enter Subject Specialization:”);
subSpe=sc.nextLine();
System.out.println(“Enter Phone No.:”);
phone=sc.nextLong();
System.out.println(“Enter monthly salary:”);
mSal=sc.nextDouble();
}
void display()
{
System.out.println(“Name:”+Name);
System.out.println(“Address:”+Address);
System.out.println(“Subject Specialization:”+subSpe);
System.out.println(“Phone No.:”+ phone);
System.out.println(“Monthly salary:”+mSal);
}
void calc()
{
double aSal;
aSal=12*mSal;
if(aSal>175000)
it=5/100.0*(aSal-175000);
else
it=0;
}
public static void main(String args[])
{
Salary ob=new Salary();
ob.input();
ob.calc();
ob.display();
}
}
3. Define a class ‘Student’ described as below:
Data members/instance variables: name,age,m1,m2,m3 (marks in 3 subjects), maximum, average Member methods:
i. To accept the details of a student.
ii. To compute the average and the maximum out of three marks.
iii. To display the name, age, marks in three subjects, maximum and average.
Write a main method to create an object of a class and call the above member methods.
Ans.
import java.util.*;
class Student
{
String name;
int age,m1,m2,m3,max;
float avg;
void input()
{
Scanner sc=new Scanner(System.in);
System.out.println(“Enter your name:”);
name=sc.nextLine();
System.out.println(“Enter marks in 3 subjects:”);
m1=sc.nextInt();
m2=sc.nextInt();
m3=sc.nextInt();
System.out.println(“Enter your age:”);
age=sc.nextInt();
}
void display()
{
System.out.println(“Name:”+name);
System.out.println(“Marks:”+m1+“,”+m2+ “and” +m3);
System.out.println(“Maximum Marks:”+max);
System.out.println(“Average:”+ avg);
}
void compute()
{
max=Math.max(Math.max(m1,m2),m3);
avg=(float)(m1+m2+m3)/3;
}
public static void main(String args[])
{
Student ob=new Student();
ob.input();
ob.compute();
ob.display();
}
}
4. Define a class Employee having the following description:
Instance variables:
int pan to store personal account number
String name to store name
double tax_income 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 the given format.
Total Annual Taxable Income Tax Rate
Upto ₹ 1,00,000 No tax
From 1,00,001 to 1,50,000 10% of the income exceeding ₹ 1,00,000
From 1,50,001 to 2,50,000 ₹ 5000 + 20% of the income exceeding ₹ 1,50,000
Above ₹ 2,50,000 ₹ 25,000 + 30% of the income exceeding ₹ 2,50,000
Output:
Pan Number Name Tax-income Tax
__ __ __ __
Ans.
import java.util.*;
class Employee
{
String pan, name;
double tax_income,tax;
void input()
{
Scanner sc=new Scanner(System.in);
System.out.println(“Enter your PAN no.:”);
pan=sc.nextLine();
System.out.println(“Enter your name:”);
name=sc.nextLine();
System.out.println(“Enter taxable income:”);
tax_income=sc.nextDouble();
}
void display()
{
System.out.println(“Pan Number\t\tName\t\tTax-income\t\tTax”);
System.out.println(pan+“\t\t”+name+“\t\t”+tax_income+“\t\t”++ tax);
}
void calc()
{
if(tax_income<=100000)
tax=0;
else if(tax_income>100000 && tax_income<=150000)
tax=10/100.0*(tax_income-100000);
else if(tax_income>150001 && tax_income<=250000)
tax=5000+20/100.0*(tax_income-150000);
else
tax=25000+30/100.0*(tax_income-250000);
}
}
5. Define a class called Mobike with the following description:
Instance variables/ Data members:
bno : to store the bike’s number
phno : to store the phone number of the customer
name : to store the name of the customer
days : to store the number of days the bike is taken on rent
charge : to calculate and store the rental charge
Member methods:
void input () : to input and store the detail of the customer
void compute () : to compute the rental charge. The rent for a Mobike is charged on the following basis
First five days : ₹ 500 per day
Next five days : ₹ 400 per day
Rest of the days : ₹ 200 per day
void display () : to display the details in the following format:
Bike No. Phone No. Name No. of days Charge
– – – – – – – – – – – — – – – – – – – – – – – – –
Ans.
import java.util.*;
class Mobike
{
String bno,phno,name;
int days;
double charge;
void input()
{
Scanner sc=new Scanner(System.in);
System.out.println(“Enter your bike no.:”);
bno=sc.nextLine();
System.out.println(“Enter your phone no.:”);
phno=sc.nextLine();
System.out.println(“Enter your name:”);
name=sc.nextLine();
System.out.println(“Enter no. of days taken for rent:”);
days=sc.nextInt();
}
void display()
{
System.out.println(“Bike No.\t\tPhone No.\t\tName\t\tNo. of days\t\tCharge”);
System.out.println(bno+“\t\t”+phno+“\t\t”+name+“\t\t”+days+“\t\t”+charge);
}
void calc()
{
if(days<=5)
charge=days*500;
else if(days>5 && days<=10)
charge=5*500+(days-5)*400;
else
charge=5*500+5*400+(days-10)*200;
}
}
6. Write a program with the following specifications:
Class name : Student
Data members :
name : To store the name of a student
hindi : To store the marks in hindi subject
english : To store the marks in english subject
maths : To store the marks in mathematics
computer : To store the marks in computer
average : To store the avergae of the marks obtained
grade : To store the grade depending upon the average.
Member methods:
void accept( ) : to accept name and marks in the 4 subjects.
void calcavg( ) : to calculate and store the grade according to the following slabs:
Average marks Grade Obtained
90 and above A++
Between 75 to 89 (both inclusive) A
Between 60 to75 (both inclusive) B
Less than 60 C
Write the main method to create the object of the class and call the above method.
Ans.
import java.util.*;
class Student
{
String name;
int hindi,english,maths,computer;
float average;
String grade;
void accept()
{
Scanner sc=new Scanner(System.in);
System.out.println(“Enter your name.:”);
name=sc.nextLine();
System.out.println(“Enter marks in hindi:”);
hindi=sc.nextInt();
System.out.println(“Enter marks in english:”);
english=sc.nextInt();
System.out.println(“Enter marks in maths:”);
maths=sc.nextInt();
System.out.println(“Enter marks in computer:”);
computer=sc.nextInt();
}
void calcavg()
{
average=(hindi+english+maths+computer)/4f;
if(average>=90)
grade=“A++”;
else if(average>75 && average<90)
grade=“A”;
else if(average>=60 && average<=75)
grade=“B”;
else
grade=“C”;
}
public static void main(String args[])
{
Student ob=new Student();
ob.accept();
ob.calcavg();
}
}
7. Design class called Bank with the following descriptions:
Data members:
name : to store the name of the depositor
acno : to store the account number
type : to store type of the account
bal : to store the balance amount in the account
Member functions:
initialise( ) : to assign the data members with any value.
depo(int a ) : where a is the amount to be deposited and the variable bal is to be updated.
withdraw( int a) : where a is the amount to be withdrawn after checking the balance
(Minimum balance should be ₹ 1000) and the variable bal is to be updated.
print( ) : to print all the details.
Write the main method to create the object of the class and call the above method.
Ans.
import java.util.*;
class Bank
{
String name;
long acno;
float bal;
String type;
void initialise()
{
name=“Saurav Agarwal”;
acno=1001098721;
bal=10000;
type=“Savings”;
}
void depo(int a)
{
bal+=a;
}
void withdraw(int a)
{
if(bal-a<1000)
System.out.println(“Minimum balance should be 1000 rupees”);
else
bal-=a;
}
void print()
{
System.out.println(“Name:”+name);
System.out.println(“Account No.:”+acno);
System.out.println(“Balance:”+bal);
System.out.println(“Type of Account:”+type);
}
public static void main(String args[])
{
Bank ob=new Bank();
Scanner sc=new Scanner(System.in);
ob.initialise();
char c;int a;
System.out.println(“Enter (D)eposit/(W)ithdraw:”);
c=sc.next().charAt(0);
if(c==‘D’)
{
System.out.println(“Enter the amount to deposit:”);
a=sc.nextInt();
ob.depo(a);
}
else if(c==‘W’)
{
System.out.println(“Enter the amount to withdraw:”);
a=sc.nextInt();
ob.withdraw(a);
}
else
System.out.println(“Invalid input”);
ob.print();
}
}
8. Define a class Bill as described below:
Data members are:
name : to store the name of the consumer
consumerno : to store the consumer number
unitconsumed : to store the unit cosumed
Member methods are :
datainput() : to read the data of a person
compute() : to calculate the bill amount as per criteria.
Units Consumed Rate
Up to 100 units 1.20
More than 100 and up to 200 units 2.20
More than 200 and up to 300 units 3.20
Above 300 units 4.00
Display() – To display the output as per the format:
Consumer Name Consumer No Unit Consumed Bill Amount
Ans.
import java.util.*;
class Bill
{
String name;
long consumerno;
int unitconsumed ;
void datainput()
{
Scanner sc=new Scanner(System.in);
System.out.println(“Enter the name:”);
name=sc.nextLine();
System.out.println(“Enter the consumer no.:”);
consumerno=sc.nextLong();
System.out.println(“Enter the unit consumed:”);
unitconsumed=sc.nextInt();
}
float compute()
{
float bill=0;
if(unitconsumed<=100)
bill=unitconsumed*1.2f;
else if(unitconsumed>100 && unitconsumed<=200)
bill=unitconsumed*2.2f;
else if(unitconsumed>200 && unitconsumed<=300)
bill=unitconsumed*3.2f;
else
bill=unitconsumed*4.0f;
return bill;
}
void Display()
{
System.out.println(“Consumer Name\t\tConsumer No\t\tUnit Consumed\t\tBill Amount”);
System.out.println(name+“\t\t”+consumerno+“\t\t”+unitconsumed+“\t\t”+compute());
}
}
9. Write a program with the following specifications:
Class : Empl
Data Members:
Emp_No : To store the employee number
Name : To store the name of the employee
Basic : To store the basic salary of an employee
DA : To store the dearness allowance of an employee.
HRA : To store the House Rent Allowance of an employee
TA : To store the Travelling Allowance of an employee
PF : To store the Provident Fund of an employee
Gross : To store the Gross Salary
Member Methods:
get ( ) : To accept Employee No., Name and Basic Salary of the employees
calcu ( ) : To calculate the Gross Salary based on the following condition:
Write a main method to create the object of the above class and call the above method to calculate and print the Employee No., Name, Gross Salary and PF of an employee.
Ans.
import java.util.*;
class Empl
{
int Emp_No;
String Name;
float Basic,DA,HRA,TA,PF,Gross;
void get()
{
Scanner sc=new Scanner(System.in);
System.out.println(“Enter your employee no.:”);
Emp_No=sc.nextInt();
System.out.println(“Enter your name:”);
Name=sc.nextLine();
System.out.println(“Enter the basic pay:”);
Basic=sc.nextFloat();
}
void calcu()
{
if(Basic>=20000)
{
DA=53/100f*Basic;
TA=12/100f*Basic;
HRA=10/100f*Basic;
PF=8/100f*Basic;
}
else if(Basic>=10000 && Basic<20000)
{
DA=45/100f*Basic;
TA=10/100f*Basic;
HRA=12/100f*Basic;
PF=7.5f/100f*Basic;
}
else
{
DA=40/100f*Basic;
TA=8/100f*Basic;
HRA=14/100f*Basic;
PF=7/100f*Basic;
}
Gross=Basic+DA+TA+HRA+PF-PF;
}
void display()
{
System.out.println(“EMPLOYEE No.\t\tNAME\t\tGROSS SALARY\t\tPF”);
System.out.println(Emp_No+”\t\t”+Name+”\t\t”+Gross+”\t\t”+PF);
}
public static void main(String args[])
{
Empl ob=new Empl();
ob.get();
ob.calcu();
ob.display();
}
}
10. Define a class called Library with the following description:
Instance variables/data members:
int acc_num : stores the accession number of books
String title : stores the title of book
String author : stores the name of author
Member methods:
void input() : to input and store the accession number, title and author
void compute() : to accept the number of days late, calculate and display the fine
charged the rate of ` 2 per day
void display() : to display the details in the following format:
Accession number Title Author
………………………….. …………………… ………………………….
Write the main method to create an object of the class and call the above member methods.
Ans.
import java.util.*;
class Library
{
int acc_num;
String title,author;
void input()
{
Scanner sc=new Scanner(System.in);
System.out.println(“Enter the accession no.:”);
acc_num=sc.nextInt();
System.out.println(“Enter the title:”);
title=sc.nextLine();
System.out.println(“Enter the author:”);
author=sc.nextLine();
}
void compute()
{
Scanner sc=new Scanner(System.in);
int late,fine;
System.out.println(“Enter the no. of days late:”);
late=sc.nextInt();
fine=late*2;
System.out.println(“Fine:”+fine);
}
void display()
{
System.out.println(“Accession number\t\tTitle\t\tAuthor”);
System.out.println(acc_num+“\t\t”+title+“\t\t”+author);
}
public static void main(String args[])
{
Library ob=new Library();
ob.input();
ob.compute();
ob.display();
}
}
11. Define a class called FruitJuice with the following description:
Instance variables/data members:
int product_code – stores the product code number
String flavour – stores the flavour of the juice.(orange, apple, etc.)
String pack_type – stores the type of packaging (tetra-pack, bottle, etc.)
int pack_size – stores package size (200ml, 400ml, etc.)
int product_price – stores the price of the product
Member Methods:
void input() – to input and store the product code, flavour, pack type, pack size and product price
void discount() – to reduce the product price by 10
void display() – to display the product code, flavour, pack type, pack size and product price
Write the main method to create an object of the class and call the above member methods.
Ans.
import java.util.*;
class FruitJuice
{
int product_code,pack_size,product_price;
String flavour,pack_type;
void input()
{
Scanner sc=new Scanner(System.in);
System.out.println(“Enter the product code:”);
product_code=sc.nextInt();
System.out.println(“Enter the flavour:”);
flavour=sc.nextLine();
System.out.println(“Enter the pack type:”);
pack_type=sc.nextLine();
System.out.println(“Enter the pack size:”);
pack_size=sc.nextInt();
System.out.println(“Enter the product price:”);
product_price=sc.nextInt();
}
void discount()
{
product_price-=10;
}
void display()
{
System.out.println(“Product code:”+product_code);
System.out.println(“Flavour:”+flavour);
System.out.println(“Pack type:”+pack_type);
System.out.println(“Pack size:”+pack_size);
System.out.println(“Product price:”+product_price);
}
public static void main(String args[])
{
FruitJuice ob=new FruitJuice();
ob.input();
ob.discount();
ob.display();
}
}
12. Define a class Book with the following specifications.
Instance variables/data members:
BOOK_NO : int type to store the book number
BOOK_TITLE : String type to store the title of the book
PRICE : float type to store the price per copy
Member Methods:
TOTAL_COST() : to calculate the total cost for N number of copies, where N is passed to the function as argument
INPUT() : to read BOO_NO, BOOK_TITLE, PRICE
PURCHASE() : to ask the user to input the number of copies to be purchased. It
invokes TOTAL_COST() and prints the total cost to be paid by the user. Write the main method to create an object of the class and call the above member methods.
Ans.
import java.util.*;
class Book
{
int BOOK_NO;
String BOOK_TITLE;
float PRICE;
void INPUT()
{
Scanner sc=new Scanner(System.in);
System.out.println(“Enter the book no.:”);
BOOK_NO=sc.nextInt();
System.out.println(“Enter the book title:”);
BOOK_TITLE=sc.nextLine();
System.out.println(“Enter the price:”);
PRICE=sc.nextFloat();
}
void TOTAL_COST(int n)
{
float tcost;
tcost=PRICE*n;
System.out.println(“Total Cost:”+tcost);
}
void PURCHASE()
{
Scanner sc=new Scanner(System.in);
System.out.println(“Enter the no. of copies to purchase:”);
int n=sc.nextInt();
TOTAL_COST(n);
}
public static void main(String args[])
{
Book ob=new Book();
ob.INPUT();
ob.PURCHASE();
}
}
13. Define a class Flight with the following description:
Instance variables/data members:
fl_no : to store the flight number of int type
dest : to store the destination of the flight of String type
dist : to store the distance of the flight of float type
fuel : to store the fuel required by the flight of float type
Member Methods:
i calfuel() : to calculate the value of fuel as per the following criteria Distance Fuel
<=1000 500
>1000 and <=2000 1100
>2000 2200
ii feedinfo() to allow user to enter values for Flight Number, Destination, Distance and call function calfuel() to calculate the quantity of Fuel.
iii showinfo() to allow user to view the content of all the data members.
Write the main method to create an object of the class and call the above member methods.
Ans.
import java.util.*;
class Flight
{
int fl_no;
String dest;
float dist,fuel;
void calfuel()
{
if(dist<=1000)
fuel=500;
else if(dist>1000 && dist<=2000)
fuel=1100;
else
fuel=2200;
}
void feedinfo()
{
Scanner sc=new Scanner(System.in);
System.out.println(“Enter the flight no:”);
fl_no=sc.nextInt();
System.out.println(“Enter the destination:”);
dest=sc.nextLine();
System.out.println(“Enter the distance:”);
dist=sc.nextFloat();
calfuel();
}
void showinfo()
{
System.out.println(“Flight no:”+fl_no);
System.out.println(“Destination:”+dest);
System.out.println(“Distance:”+dist);
System.out.println(“Fuel:”+fuel);
}
public static void main(String args[])
{
Flight ob=new Flight();
ob.feedinfo();
ob.showinfo();
}
}
14. Define a class hotel in with the following description
Instance variables/data members:
Rno : Room No of int type
Name : Customer name of String type
Tarrif : stores per day charges of float type
NOD : no of days integer
Member Methods:
CALC() : to calculate and return Amount as NOD*Tarrif and if the value of NOD*Tarrif
is more than 10000 then as 1.05*NOD*Tarrif
Checkin() : to enter the Rno, Name, Tarrif and NOD
Checkout() : to display Rno, Name, Tarrif, NOD and Amount by calling CALC()
Write the main method to create an object of the class and call the above member methods.
Ans.
import java.util.*;
class hotel
{
int Rno,NOD;
String Name;
float Tarrif;
float CALC()
{
float Amount;
Amount=NOD*Tarrif;
if(Amount>10000)
Amount=Amount*1.05f;
return Amount;
}
void Checkin()
{
Scanner sc=new Scanner(System.in);
System.out.println(“Enter the Room no:”);
Rno=sc.nextInt();
System.out.println(“Enter the Name:”);
Name=sc.nextLine();
System.out.println(“Enter the Tarrif:”);
Tarrif=sc.nextFloat();
System.out.println(“Enter the No. of Days:”);
NOD=sc.nextInt();
}
void Checkout()
{
System.out.println(“Room no:”+Rno);
System.out.println(“Name:”+Name);
System.out.println(“Tarrif:”+Tarrif);
System.out.println(“No. of days:”+NOD);
System.out.println(“Amount:”+CALC());
}
public static void main(String args[])
{
hotel ob=new hotel();
ob.Checkin();
ob.Checkout();
}
}
15. Define a class Telephone having the following description:
Instance Variables / Data Members:
int prv, pre – to store the previous and present meter reading
int call – to store the calls made (i.e. pre – prv)
String name – to store name of the customer
double amt – to store the amount
double total – to store the total amount to be paid
Member Methods:
void input ( ) – to input the previous reading, present reading and name of the customer
void cal ( ) – to calculate the amount and total amount to be paid
void display ( ) – to display the name of the customer, calls made, amount and total amount to be paid in the following format:
Name Calls Made Amount Total Amount
…………… …………..…….. ……………….. …………..……….
Write a program to compute the monthly bill to be paid according to the given conditions:
However every customer has to pay ₹ 180 per month as monthly rent for availing the service.
Ans.
import java.util.*;
class Telephone
{
int prv, pre,call;
String name;
double amt,total;
void input()
{
Scanner sc=new Scanner(System.in);
System.out.println(“Enter the previous meter reading:”);
prv=sc.nextInt();
System.out.println(“Enter the present meter reading:”);
pre=sc.nextInt();
System.out.println(“Enter the name:”);
name=sc.nextLine();
}
void cal()
{
call=pre-prv;
if(call<=100)
amt=0;
else if(call>100 && call<=200)
amt=0*100+(call-100)*0.90;
else if(call>200 && call<=400)
amt=0*100+100*0.90+(call-200)*0.80;
else
amt=0*100+100*0.90+200*0.80+(call-400)*0.70;
total=amt+180;
}
void display()
{
System.out.println(“Name\t\tCalls Made\t\tAmount\t\tTotal Amount”);
System.out.println(name+“\t\t”+call+“\t\t”+amt+“\t\t”+total);
}
public static void main(String args[])
{
Telephone ob=new Telephone();
ob.input();
ob.cal();
ob.display();
}
}
16. Define a class named movieMagic with the following description:
Instance variables/data members:
int year – to store the year of release of a movie
String title – to store the title of the movie.
float rating – to store the popularity rating of the movie.
(minimum rating = 0.0 and maximum rating = 5.0)
Member Methods:
(i) void accept() – To input and store year, title and rating.
(ii) void display() – To display the title of a movie and a message based on the rating as per the table below.
Rating Message to be displayed
0.0 to 2.0 Flop
2.1 to 3.4 Semi-hit
3.5 to 4.5 Hit
4.6 to 5.0 Super Hit
Write a main method to create an object of the class and call the above member methods.
Ans.
import java.util.*;
class movieMagic
{
int year;
String title;
float rating;
void accept()
{
Scanner sc=new Scanner(System.in);
System.out.println(“Enter the year:”);
year=sc.nextInt();
System.out.println(“Enter the title:”);
title=sc.nextLine();
System.out.println(“Enter the rating:”);
rating=sc.nextFloat();
}
void display()
{
System.out.println(“Title:”+title);
if(rating>=0.0f && rating<=2.0f)
System.out.println(“Flop”);
else if(rating>=2.1f && rating<=3.4f)
System.out.println(“Semi Hit”);
else if(rating>=3.5f && rating<=4.5f)
System.out.println(“Hit”);
else if(rating>=4.6f && rating<=5.0f)
System.out.println(“Super Hit”);
}
public static void main(String args[])
{
movieMagic ob=new movieMagic();
ob.accept();
ob.display();
}
}
17. Define a class ParkingLot with the following description:
Instance variables/data members:
int vno – To store the vehicle number
int hours – To store the number of hours the vehicle is parked in the parking lot
double bill – To store the bill amount
Member methods:
void input() – To input and store vno and hours
void calculate() – To compute the parking charge at the rate of ` 3 for the first hour or
part thereof, and ` 1.50 for each additional hour or part thereof.
void display() – To display the detail
Write a main method to create an object of the class and call the above methods
Ans.
import java.util.*;
class ParkingLot
{
int vno,hours;
double bill;
void input()
{
Scanner sc=new Scanner(System.in);
System.out.println(“Enter the vehicle number:”);
vno=sc.nextInt();
System.out.println(“Enter the number of hours:”);
hours=sc.nextInt();
}
void calculate()
{
if(hours<=1)
bill=3*hours;
else
bill=3*1+(hours-1)*1.50;
}
void display()
{
System.out.println(“Vehicle number:”+vno);
System.out.println(“Number of hours:”+hours);
System.out.println(“Bill:”+bill);
}
public static void main(String args[])
{
ParkingLot ob=new ParkingLot();
ob.input();
ob.calculate();
ob.display();
}
}
18. Define a class named BookFair with the following description:
Instance variables/Data members:
String Bname – stores the name of the book.
double price – stores the price of the book.
Member Methods:
(i) void Input() – To input and store the name and the price of the book.
(ii) void calculate() – To calculate the price after discount. Discount is calculated based on
the following criteria:
PRICE DISCOUNT
Less than or equal to ₹ 1000 2% of price
More than ₹ 1000 and less than or equal or ₹ 3000 10% of price
More than ₹ 3000 15% of price
(iii) void display() – To display the name and price of the book after discount.
Write a main method to create an object of the class and call the above member methods.
Ans.
import java.util.*;
class BookFair
{
String Bname;
double price;
void input()
{
Scanner sc=new Scanner(System.in);
System.out.println(“Enter the name of the book:”);
Bname=sc.nextLine();
System.out.println(“Enter the price of the book:”);
price=sc.nextDouble();
}
void calculate()
{
double dis=0;
if(price<=1000)
dis=2/100.0*price;
else if(price>1000 && price<=3000)
dis=10/100.0*price;
else
dis=15/100.0*price;
price=price-dis;
}
void display()
{
System.out.println(“Name:”+Bname);
System.out.println(“Price:”+price);
}
public static void main(String args[])
{
BookFair ob=new BookFair();
ob.input();
ob.calculate();
ob.display();
}
}
19. Define a class Electric Bill with the following specifications:
class: ElectricBill
Instance Variable/ data member:
String n – to store the name of the customer
int units – to store the number of units consumed
double bill – to store the amount to paid
Member methods:
• void accept() – to accept the name of the customer and number of units consumed
• void calculate() – to calculate the bill as per the following tariff :
Number of units – Rate per unit
First 100 units – ` 2.00
Next 200 units – ` 3.00
Above 300 units – ` 5.00
A surcharge of 2.5% charged if the number of units consumed is above 300 units.
• void print() – To print the details as follows :
Name of the customer ………
Number of units consumed ……
Bill amount …….
Write a main method to create an object of the class and call the above member methods.
Ans.
import java.util.*;
class ElectricBill
{
String n;
int units;
double bill;
void accept()
{
Scanner sc=new Scanner(System.in);
System.out.println(“Enter the name of the customer:”);
n=sc.nextLine();
System.out.println(“Enter the units consumed:”);
units=sc.nextInt();
}
void calculate()
{
double rate=0;
if(units<=100)
rate=2*units;
else if(units>100 && units<=300)
rate=100*2+(units-100)*3;
else
rate=100*2+200*3+(units-300)*5;
if(units>300)
bill=rate+2.5/100*rate;
else
bill=rate;
}
void print()
{
System.out.println(“Name of the customer:”+n);
System.out.println(“Number of units consumed:”+units);
System.out.println(“Bill amount:”+bill);
}
public static void main(String args[])
{
ElectricBill ob=new ElectricBill();
ob.accept();
ob.calculate();
ob.print();
}
}
20. Design a class RailwayTicket with the following description:
Instance variables/data members:
String name : To store the name of the customer
String coach : To store the type of coach customer wants to travel
long mobno : To store customer’s mobile number
int amt : To store basic amount of ticket
int totalamt : To store the amount to be paid after updating the original amount
Member methods:
• void accept() – To take input for name, coach, mobile number and amount
• void update() – To update the amount as per the coach selected
(extra amount to be added in the amount as follows)
• void display() – To display all details of a customer such as name, coach, total amount and mobile number.
Write a main method to create an object of the class and call the above member methods.
Ans.
import java.util.*;
class RailwayTicket
{
String name, coach;
long mobno;
int amt,totalamt;
void accept()
{
Scanner sc=new Scanner(System.in);
System.out.println(“Enter the name:”);
name=sc.nextLine();
System.out.println(“Enter the type of coach:”);
coach=sc.nextLine();
System.out.println(“Enter the mobile number:”);
mobno=sc.nextLong();
System.out.println(“Enter the amount:”);
amt=sc.nextInt();
}
void update()
{
double rate=0;
if(coach.equals(“First_AC”))
totalamt=amt+700;
else if(coach.equals(“Second_AC”))
totalamt=amt+500;
else if(coach.equals(“Third_AC”))
totalamt=amt+250;
else if(coach.equals(“Sleeper”))
totalamt=amt;
}
void print()
{
System.out.println(“Name of the customer:”+name);
System.out.println(“Type of coach:”+coach);
System.out.println(“Total amount:”+totalamt);
System.out.println(“Mobile Number:”+mobno);
}
public static void main(String args[])
{
RailwayTicket ob=new RailwayTicket();
ob.accept();
ob.update();
ob.print();
}
}
We believe that every student can get good marks by solving class as the basis of all computation solutions. So, let’s start to learn class as the basis of all computation solutions class 10 for your exam.
You can also learn revision note for class 10 computer application prepared by our expert teachers at icseboards.com