Bike Rent Program in Java

Question :

Calculate Price*Duration after the deduction of discounts in a Bike renting Company

  • Name should be only in alphabets.. If not Print Invalid
  • Discount eligible only when the Duration is 5 or more
  • Discount table will be given for each card (like Visa, Rupay, Mastercard)
  • You have to apply discount for based on the option they used.. (This data is as 1,2,3 where option 1 is visa card option 2 is Rupay)
  • If Card option is given as 4,5,6,,… OR 0,-1,-2,,,.. Print “Try again” and go back to get card option until it’s a valid one..

Sample input 1 :

Enter your name : Sam
Enter the time duration: 13
List of payment options
1)Visa card
2)Rupay card
3)Master card
Choose an option : 2

Sample output 1 :

Dear Sam your bill amount is 1294.80

Sample input 2 :

Enter your name : Tom
Enter the time duration: 15
List of payment options
1)Visa card
2)Rupay card
3)Master card
Choose an option : 3

Sample output 2 :

Dear Tom your bill amount is 1,800.00

Code :

import java.util.*;
public class Main
{
	public static void main(String[] args) {
	Scanner sc=new Scanner(System.in);
	System.out.println("Enter your name");
	String s=sc.nextLine();double sal=0;double disc=0;
		for(int i=0;i<s.length();++i)
		{
			if(!Character.isLetter(s.charAt(i)))
			{
				System.out.println("Invalid Name");
				return;
			}
		}
	System.out.println("Enter the time duration");
	int n=sc.nextInt();int n1;
		if(n<=0 || n>24)
		{
			System.out.println("Invalid duration");
			return;
		}
	System.out.println("List of payment options");
	System.out.println("1)Visa card");
	System.out.println("2)Rupay card");
	System.out.println("3)Master card");
	System.out.println("Chosse an option");
		while(true)
		{
		n1=sc.nextInt();
			if(n1<0||n1>3)
			{
				System.out.println("Try again");
			}
			else
			{
				break;
			}
		}
		if( n1==1)
		{
			if(n>=5)
			{
				sal=120*n;
				disc=(sal*0.25);
				sal=sal-disc;
			}
			else
			{
				sal=n*120;
			}
		}
		if(n1==2)
		{
			if(n>=5)
			{
				sal=120*n;
				disc=(sal*0.17);
				sal=(120*n)-disc;
			}
			else
			{
				sal=n*120;
			}
		}
		if(n1==3)
		{
			sal=n*120;
		}
	System.out.print("Dear "+s+" your bill amount is ");
	System.out.printf("%.2f", sal);
	}
}

Recommended:

  1. Java Program of Java – Python Count
  2. Java Program of Hy-Fly Taxi
  3. Java Program for Harima Realtor’s Example
  4. Numerology Name Checking
  5. OMR Evaluation
  6. Java program to Sum of Even Elements
  7. Alternate Number differences in Java

Leave a Comment

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