Instance variable/ Data members:
int bno : to store the bike 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 out on rent
int charge : to calculate and store the rental charge
Member methods :
void input ( ) : to input and store the details of the customer
void compute ( ) : to compute the rental charge
The rent for a mobike is charged on the following basis:
For first five days : Rs. 500 per day
For the 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.*;
public class Assignment_4
{
static int bno;
static long phno;
static String name;
static int days;
static int charge;
public static void main(String args[])
{
input();
compute();
display();
}
static void input()
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter the name of the customer: ");
name = sc.nextLine();
System.out.print("Enter the mobile number: ");
phno = sc.nextLong();
System.out.print("Enter the bike number: ");
bno = sc.nextInt();
System.out.print("Enter the number of days: ");
days = sc.nextInt();
}
static void compute()
{
if(days > 0 && days <= 5)
{
charge = days * 500;
}
else if(days > 5 && days <= 10)
{
charge = (5 * 500) + ((days - 5) * 400);
}
else if(days > 10)
{
charge = (5 * 500) + (5 * 400) + ((days - 10) * 200);
}
}
static void display()
{
System.out.println("Bike No. \t Phone No. \t\t Name \t \t\tNo. of Days \t Charges");
System.out.println(bno + " \t \t " + phno + " \t \t " + name + " \t \t " + days + " \t \t " + charge);
}
}
No comments:
Post a Comment