Computer Applications

Define a class called 'Mobike' with the following specifications:

Data MembersPurpose
int bnoTo store the bike number
int phnoTo store the phone number of the customer
String nameTo store the name of the customer
int daysTo store the number of days the bike is taken on rent
int chargeTo calculate and store the rental charge
Member MethodsPurpose
void input()To input and store the details of the customer
void compute()To compute the rental charge
void display()To display the details in the given format

The rent for a mobike is charged on the following basis:

DaysCharge
For first five days₹500 per day
For next five days₹400 per day
Rest of the days₹200 per day

Output:

Bike No.    Phone No.   Name    No. of days     Charge       
xxxxxxx     xxxxxxxx    xxxx        xxx         xxxxxx       

Java

Java Classes

ICSE 2011

140 Likes

Answer

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.\tName\tNo. of days \tCharge");
        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();
    }
}

Variable Description Table

Program Explanation

Output

Answered By

57 Likes


Related Questions