Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Resort Booking Java Code

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 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