OneCompiler

q6

674

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class BookingService {

static Scanner scanner = new Scanner(System.in);

public static void main(String[] args) {
    // Sample sender details for demonstration purposes
    String senderName = "John Doe";
    String senderAddress = "123 Main Street, Springfield, USA";
    String senderContact = "+1-555-123-4567";
    
    System.out.println("Welcome to the Booking Service!");
    System.out.println("Sender Details:");
    System.out.println("Name: " + senderName);
    System.out.println("Address: " + senderAddress);
    System.out.println("Contact: " + senderContact);
    
    System.out.println("\nPlease enter recipient and parcel details:");
    
    // Capture recipient and parcel details
    System.out.print("Recipient Name: ");
    String recName = scanner.nextLine();

    System.out.print("Recipient Address: ");
    String recAddress = scanner.nextLine();

    System.out.print("Recipient PIN: ");
    String recPin = scanner.nextLine();

    System.out.print("Recipient Mobile: ");
    String recMobile = scanner.nextLine();

    System.out.print("Parcel Weight (in grams): ");
    double parWeight = scanner.nextDouble();
    scanner.nextLine(); // Clear the input buffer

    System.out.print("Parcel Contents Description: ");
    String parContentsDescription = scanner.nextLine();

    System.out.print("Delivery Type (Standard/Express): ");
    String parDeliveryType = scanner.nextLine();

    System.out.print("Packing Preference (Yes/No): ");
    String parPackingPreference = scanner.nextLine();

    System.out.print("Pickup Time (HH:mm): ");
    String parPickupTime = scanner.nextLine();

    System.out.print("Drop-off Time (HH:mm): ");
    String parDropoffTime = scanner.nextLine();

    // Calculate service cost
    double serviceCost = calculateServiceCost(parWeight, parDeliveryType, parPackingPreference);

    // Record payment time (current date and time)
    String paymentTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());

    // Display captured and calculated details
    System.out.println("\nBooking Details:");
    System.out.println("Sender Name: " + senderName);
    System.out.println("Sender Address: " + senderAddress);
    System.out.println("Sender Contact: " + senderContact);
    System.out.println("Recipient Name: " + recName);
    System.out.println("Recipient Address: " + recAddress);
    System.out.println("Recipient PIN: " + recPin);
    System.out.println("Recipient Mobile: " + recMobile);
    System.out.println("Parcel Weight: " + parWeight + " grams");
    System.out.println("Parcel Contents: " + parContentsDescription);
    System.out.println("Delivery Type: " + parDeliveryType);
    System.out.println("Packing Preference: " + parPackingPreference);
    System.out.println("Pickup Time: " + parPickupTime);
    System.out.println("Drop-off Time: " + parDropoffTime);
    System.out.println("Service Cost: $" + serviceCost);
    System.out.println("Payment Time: " + paymentTime);

    System.out.println("\nBooking completed successfully!");
}

// Method to calculate service cost
private static double calculateServiceCost(double weight, String deliveryType, String packingPreference) {
    double baseCost = 5.0; // Base cost in dollars
    double costPerGram = 0.01; // Cost per gram
    double deliveryMultiplier = deliveryType.equalsIgnoreCase("Express") ? 1.5 : 1.0;
    double packingCost = packingPreference.equalsIgnoreCase("Yes") ? 2.0 : 0.0;

    return baseCost + (weight * costPerGram) * deliveryMultiplier + packingCost;
}

}