ICSE Computer Science Java Programs | IT Developer
IT Developer

Java Programs - Solved 2011 ICSE Computer Science Paper



Share with a Friend

Solved 2011 ICSE Computer Science Paper

Class 10 - ICSE Computer Science Solved Papers

Class & Object - Mobike Program - ICSE 2011 Computer Science

Define a class 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 functions/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: 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 Name No. of days Charge
———– ————– ——— —————– ———–

import java.util.Scanner; class Mobike{ int bno; int phno; String name; int days; int charge; public void input(){ Scanner in = new Scanner(System.in); System.out.print("Bike number: "); bno = Integer.parseInt(in.nextLine()); System.out.print("Phone number: "); phno = Integer.parseInt(in.nextLine()); System.out.print("Name: "); name = in.nextLine(); System.out.print("Number of days: "); days = Integer.parseInt(in.nextLine()); } public void compute(){ if(days <= 5) charge = 500 * days; else if(days <= 10) charge = 2500 + (days - 5) * 400; else charge = 4500 + (days - 10) * 200; } public void display(){ System.out.println("Bike No. Phone No. Name No. of days Charge"); System.out.println(bno + "\t" + phno + "\t" + name + "\t" + days + "\t" + charge); } public static void main(String args[]){ Mobike obj = new Mobike(); obj.input(); obj.compute(); obj.display(); } }

Output

 
 OUTPUT 1: 
Bike number: 1001
Phone number: 1234567890
Name: Anand Rao
Number of days: 12

Bike No. Phone No. Name No. of days Charge
1001    1234567890  Anand Rao   12  4900