icse-promo

Question

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 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.| PhoneNo.| No. of days |Charge

Share code with your friends

Share on whatsapp
Share on facebook
Share on twitter
Share on telegram

Code

				
					import java.util.Scanner;
public class mobike
{
    int bno;
    int phno;
    String name;
    int days;
    int charge;

    public void input()
    {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter bike number: ");
        bno = sc.nextInt();
        System.out.print("Enter phone number: ");
        phno = sc.nextInt();
        System.out.print("Enter your name: ");
        name = sc.next();
        System.out.print("Enter number of days: ");
        days = sc.nextInt();
    }

    public void compute()
    {
        if (days <= 5)
        {
            charge = 500 * days;
        }
        else if (days >5 && 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. \t No. of Days \t Charge");
        System.out.println(bno + "\t" + phno + "\t" + days + "\t" + charge);
    }
}


				
			

Coding Store

Leave a Reply

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