Define a class called Mobike, Class and Object based Program

Define a class called Mobike with the following description:

Instance variables/Data members:

      int bno             – to stores the bike’s number.

      int phno           – to stores the hone number of the customer

      String name    – to stores the name of the customer

      int days            – to stores 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 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.                    No. of days                  Charge

————               ——————–           ———-                        ——————

Write a main( ) method where user will create an object of the class and call all the member functions.

import java.util.*;

class Mobike
	int bno;
	int phno;
	String name;
	int days;
	int charge;

	void input( )
		Scanner sc = new Scanner(;
		System.out.println("Enter Bike Number =");
		bno = sc.nextInt();
		System.out.println("Enter Phone Number =");
		phno = sc.nextInt();
		System.out.println("Enter Name =");
		name = sc.nextLine();
		System.out.println("Enter days =");
		days = sc.nextInt();

	void display( )
		System.out.println("Bike No.\t\tPhone No.\t\tNo. of days\t\tCharge");

	void compute( )
			charge = days*500;
		else if (days >= 6 && days <= 10)
			charge = 2500+(days-5)*400;
			charge = 2500+2000+(days-10)*200;

	public static void main(String args[ ])
		Mobike ktm = new Mobike( );
		ktm.input( );
		ktm.compute( );
		ktm.display( );

Click to comment

Leave a Reply

Your email address will not be published. Required fields are marked *

To Top