0% found this document useful (0 votes)
50 views3 pages

Autoboxing and Unboxing

This Java program implements a car rental service with the following functionality: 1. It displays a menu allowing the user to view available car models, search for a specific model, or rent a car. 2. If viewing or searching models, it loops through arrays storing each model's name, stock level, and daily rental rate. 3. To rent a car, it prompts the user to enter their name, number of rental days, and selects a car from the available models if stock permits, then displays a receipt with rental details.

Uploaded by

ARNI SENGUPTA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views3 pages

Autoboxing and Unboxing

This Java program implements a car rental service with the following functionality: 1. It displays a menu allowing the user to view available car models, search for a specific model, or rent a car. 2. If viewing or searching models, it loops through arrays storing each model's name, stock level, and daily rental rate. 3. To rent a car, it prompts the user to enter their name, number of rental days, and selects a car from the available models if stock permits, then displays a receipt with rental details.

Uploaded by

ARNI SENGUPTA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

import java.util.

*;
public class carrent
{
static void main()
{
Scanner sc= new Scanner(System.in);
draw.drawline(100);
System.out.println("CAR RENTAL SERVICE");
draw.drawline(100);
System.out.println("A. Car Models");
System.out.println("B. Search for Model");
System.out.println("C. Rent a Car");
draw.drawline(100);
String car[]= {"Lamborghini Aventador","Audi R8","BMW M8","Tesla
Model X","Lexus GX 460"};//array storing car model
int rent[]= {500,200,150,150,50};//array storing rent
int stock[]= {0,10,10,10,50};//array storing amount of cars available for
the respective
String name= "";
int days=0;
int amt=0;
String date="";
String model="";
boolean run = false;
while(run==false)
{
String op= sc.nextLine();// to accpet users choice
if(op.equalsIgnoreCase("a"))
{
for(int i= 0;i<=4;i++)
{
draw.drawline(100);
System.out.println("Car Model:"+car[i]);
System.out.println(";Number available:"+stock[i]);
System.out.println("Rent(per day) in $: "+rent[i]);
//draw.drawline(100);
}
draw.drawline(100);
}
else if(op.equalsIgnoreCase("b"))
{
System.out.println("Enter model of the car"); ;
boolean sr= false;
while(sr==false)

{
String md= sc.nextLine();
for(int i=0;i<=4;i++)
{
if(md.equalsIgnoreCase(car[i]))
{
draw.drawline(100);
System.out.println("Car Model :"+car[i]);
System.out.println("Number available:"+stock[i]);
System.out.println("Rent (per day) in $:"+rent[i]);
draw.drawline(100);
sr=true;
break;
}
}
if(sr==false)
{
System.out.println("Model not found");
System.out.println("Please enter another model");
}
}
}
else if(op.equalsIgnoreCase("c"))
{
System.out.println("Enter the model of the car you would like to rent");
boolean chk=false;
while(chk==false)
{
String cm= sc.nextLine();
for(int i=0;i<=4;i++)
{
if(cm.equalsIgnoreCase(car[i]))
{
if(stock[i]>0)
{
model=car[i];
System.out.println("Please enter your name");
name= sc.nextLine();
System.out.println("How many days are you renting the car for?");
days= sc.nextInt();
System.out.println("Please enter todays date");
date= sc.nextLine();
amt=rent[i]*days;

stock[i]=stock[i]-1;
chk=true;
break;
}
else
{
System.out.println("Car is not in stock");
System.out.println("Please choose another model");
break;
}
}
}
if(chk==false)
{
System.out.println("enter the correct model");
}
}
draw.drawline(100);
System.out.println("Customer:"+name);
System.out.println("Car Model:"+model);
System.out.println("Date Rented:"+date);
System.out.println("The amount due is $"+amt);
draw.drawline(100);
run=true;
}
}

static void drawline(int x) // THIS LINE IS GIVING ERROR


{
for(int i=0; i<=x; i++)
{
System.out.print("-");
}
System.out.println();
}
}

You might also like