0% found this document useful (0 votes)
723 views1 page

Resort Booking Java Code

This Java code accepts customer booking details from input as a string separated by colons for name, number of adults, children, and days. It then validates the input, parses the string to integers, and calculates the total booking cost based on per day rates for adults and children. If valid, it prints the confirmation with total cost, otherwise it prints an error.

Uploaded by

Amulya Rajesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
723 views1 page

Resort Booking Java Code

This Java code accepts customer booking details from input as a string separated by colons for name, number of adults, children, and days. It then validates the input, parses the string to integers, and calculates the total booking cost based on per day rates for adults and children. If valid, it prints the confirmation with total cost, otherwise it prints an error.

Uploaded by

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

import java.util.

Scanner;

public class ResortBooking {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

System.out.println("Enter customer details (name:adults:children:days):");


String input = scanner.nextLine();

String[] details = input.split(":");

if (details.length != 4) {
System.out.println("Invalid input");
scanner.close();
return;
}

String name = details[0];


int adults = Integer.parseInt(details[1]);
int children = Integer.parseInt(details[2]);
int days = Integer.parseInt(details[3]);

if (adults < 0) {
System.out.println("Invalid input for number of adults");
} else if (children < 0) {
System.out.println("Invalid input for number of children");
} else if (days <= 0) {
System.out.println("Invalid input for number of days");
} else {
int adultCost = 1000;
int childCost = 650;

int totalCost = (adults * adultCost + children * childCost) * days;


System.out.println(name + " your booking is confirmed and the total
cost is Rs " + totalCost);
}

scanner.close();
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy