0% found this document useful (0 votes)
608 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
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
Download as txt, pdf, or txt
0% found this document useful (0 votes)
608 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
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
Download as txt, pdf, or txt
Download as txt, pdf, or txt
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