0% found this document useful (0 votes)
11 views12 pages

Java Assignment

The document outlines the specifications for a Java console application for a Travel Agency system that manages tour packages, itineraries, customers, bookings, payments, and cancellations. It includes class requirements, business rules, console interface requirements, and expected output behavior, along with a UML class diagram and code implementation. The application must adhere to object-oriented principles and provide a menu-driven interface for user interactions.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views12 pages

Java Assignment

The document outlines the specifications for a Java console application for a Travel Agency system that manages tour packages, itineraries, customers, bookings, payments, and cancellations. It includes class requirements, business rules, console interface requirements, and expected output behavior, along with a UML class diagram and code implementation. The application must adhere to object-oriented principles and provide a menu-driven interface for user interactions.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

DEPARTMENT OF COMPUTER SCIENCE JAVA PROGRAMMING

QUESTION:
Travel Agency – Tours & Bookings – Specification Document
Problem Statement:
Design and implement a Java console application for a Travel Agency system that
manages tour packages, itineraries, customers, bookings, payments, and
cancellations. The application should demonstrate object-oriented principles and
maintain accurate availability.
Class Requirements:
1. TourPackage
2. ItineraryItem
3. Customer
4. Booking
5. Traveler
6. Payment
7. Cancellation
Business Rules:
1. Bookings can be confirmed only if seats are available in the package.
2. Payment completion is required to finalize booking.
3. Cancellations apply fees based on policy and timing.
4. Each itinerary item belongs to a specific tour package.
5. Availability updates on booking and cancellation.
Console Interface Requirements:
1. Menu-driven program: Add Tour Package / Add Itinerary Item / Add Customer
/ Create Booking / Record Payment / Cancel Booking / Display Packages &
Availability / Exit
2. Input validations must be performed for all user entries.
3. Encapsulation must be followed for all attributes.
Expected Output Behavior:
• Show booking confirmation and payment receipt.

ARUL SIVAM 717825P501


DEPARTMENT OF COMPUTER SCIENCE JAVA PROGRAMMING

• Show cancellation summary with fees and refunds.


• Show updated availability per tour package.
Questions for Students:
1. Draw the UML Class Diagram for the above system.
2. Implement the Classes with necessary Data Members and Methods for System
and Business Rules.
3. Use Aggregation, Inheritance and Polymorphism wherever required.
4. Implement the main method for Menu Driven System.
UML DIAGRAM:

ARUL SIVAM 717825P501


DEPARTMENT OF COMPUTER SCIENCE JAVA PROGRAMMING

CODE:

import [Link];

import [Link].*;

class TourPackage {

private int id;

private String name;

private LocalDate startDate, endDate;

private double pricePerSeat;

private int totalSeats, availableSeats;

public TourPackage(int id, String name, LocalDate startDate, LocalDate endDate, double pricePerSeat, int
totalSeats) {

[Link] = id;

[Link] = name;

[Link] = startDate;

[Link] = endDate;

[Link] = pricePerSeat;

[Link] = totalSeats;

[Link] = totalSeats;

public int getId() { return id; }

public String getName() { return name; }

public double getPricePerSeat() { return pricePerSeat; }

public int getAvailableSeats() { return availableSeats; }

public boolean bookSeats(int seats) {

if (availableSeats >= seats) {

availableSeats -= seats;

return true;

return false;

public void releaseSeats(int seats) { availableSeats += seats; }

ARUL SIVAM 717825P501


DEPARTMENT OF COMPUTER SCIENCE JAVA PROGRAMMING

public void showInfo() {

[Link]("%-4d %-20s %3d/%-3d ₹%.2f%n",

id, name, availableSeats, totalSeats, pricePerSeat);

class Customer {

private int id;

private String name, email;

public Customer(int id, String name, String email) {

[Link] = id; [Link] = name; [Link] = email;

public int getId() { return id; }

public String getName() { return name; }

class Traveler {

private String name, passportId;

private int age;

public Traveler(String name, int age, String passportId) {

[Link] = name; [Link] = age; [Link] = passportId;

abstract class Transaction {

protected double amount;

protected LocalDate date;

public abstract String summary();

class Payment extends Transaction {

private String method;

public Payment(double amount, String method) {

[Link] = amount;

[Link] = method;

ARUL SIVAM 717825P501


DEPARTMENT OF COMPUTER SCIENCE JAVA PROGRAMMING

[Link] = [Link]();

public String summary() {

return "Paid ₹" + amount + " via " + method + " on " + date;

class Booking {

enum Status { PENDING, CONFIRMED, CANCELLED }

private static int counter = 1000;

private int id;

private Customer customer;

private TourPackage pack;

private List<Traveler> travelers = new ArrayList<>();

private int seats;

private double totalAmount;

private Payment payment;

private Status status;

public Booking(Customer customer, TourPackage pack, List<Traveler> travelers, int seats) {

[Link] = ++counter;

[Link] = customer;

[Link] = pack;

[Link] = travelers;

[Link] = seats;

[Link] = [Link]() * seats;

[Link] = [Link];

public int getId() { return id; }

public Status getStatus() { return status; }

public double getTotalAmount() { return totalAmount; }

public void addPayment(Payment p) {

ARUL SIVAM 717825P501


DEPARTMENT OF COMPUTER SCIENCE JAVA PROGRAMMING

[Link] = p;

[Link] = [Link];

public void cancel() {

[Link] = [Link];

[Link](seats);

public void showSummary() {

[Link]("Booking #%d - %s - %s - ₹%.2f - %s%n",

id, [Link](), [Link](), totalAmount, status);

// ---------- MAIN APP ----------

public class TravelAgencyApp {

private static Map<Integer, TourPackage> packages = new HashMap<>();

private static Map<Integer, Customer> customers = new HashMap<>();

private static Map<Integer, Booking> bookings = new HashMap<>();

private static Scanner sc = new Scanner([Link]);

public static void main(String[] args) {

while (true) {

[Link]("\n=== TRAVEL AGENCY MENU ===");

[Link]("1. Add Tour Package");

[Link]("2. Add Customer");

[Link]("3. Create Booking");

[Link]("4. Record Payment");

[Link]("5. Cancel Booking");

[Link]("6. Show Packages");

[Link]("7. Exit");

[Link]("Enter choice: ");

int ch = [Link]();

ARUL SIVAM 717825P501


DEPARTMENT OF COMPUTER SCIENCE JAVA PROGRAMMING

[Link]();

switch (ch) {

case 1 -> addPackage();

case 2 -> addCustomer();

case 3 -> createBooking();

case 4 -> recordPayment();

case 5 -> cancelBooking();

case 6 -> showPackages();

case 7 -> { [Link]("Goodbye!"); return; }

default -> [Link]("Invalid choice!");

private static void addPackage() {

[Link]("Enter ID: "); int id = [Link]();

[Link]();

[Link]("Enter Name: "); String name = [Link]();

[Link]("Start Date (YYYY-MM-DD): "); LocalDate s = [Link]([Link]());

[Link]("End Date (YYYY-MM-DD): "); LocalDate e = [Link]([Link]());

[Link]("Price per Seat: "); double price = [Link]();

[Link]("Total Seats: "); int seats = [Link]();

[Link](id, new TourPackage(id, name, s, e, price, seats));

[Link]("✅ Package added!");

private static void addCustomer() {

[Link]("Enter ID: "); int id = [Link](); [Link]();

[Link]("Enter Name: "); String name = [Link]();

[Link]("Enter Email: "); String email = [Link]();

[Link](id, new Customer(id, name, email));

[Link]("✅ Customer added!");

ARUL SIVAM 717825P501


DEPARTMENT OF COMPUTER SCIENCE JAVA PROGRAMMING

private static void createBooking() {

[Link]("Enter Customer ID: "); int cid = [Link]();

[Link]("Enter Package ID: "); int pid = [Link]();

[Link]("Seats to book: "); int seats = [Link]();

[Link]();

Customer c = [Link](cid);

TourPackage p = [Link](pid);

if (c == null || p == null) {

[Link]("❌ Invalid IDs!");

return;

if (![Link](seats)) {

[Link]("❌ Not enough seats available!");

return;

List<Traveler> travelers = new ArrayList<>();

for (int i = 1; i <= seats; i++) {

[Link]("Traveler " + i + " Name: ");

String name = [Link]();

[Link]("Age: "); int age = [Link]();

[Link]();

[Link]("Passport ID: ");

String pidT = [Link]();

[Link](new Traveler(name, age, pidT));

Booking b = new Booking(c, p, travelers, seats);

[Link]([Link](), b);

[Link]("✅ Booking created! ID: " + [Link]() + " | Total: ₹" + [Link]());

ARUL SIVAM 717825P501


DEPARTMENT OF COMPUTER SCIENCE JAVA PROGRAMMING

private static void recordPayment() {

[Link]("Enter Booking ID: "); int id = [Link]();

[Link]();

Booking b = [Link](id);

if (b == null) { [Link]("❌ Invalid ID!"); return; }

if ([Link]() == [Link]) {

[Link]("Already confirmed!");

return;

[Link]("Enter Amount: "); double amt = [Link]();

[Link]();

[Link]("Enter Method: "); String method = [Link]();

Payment p = new Payment(amt, method);

[Link](p);

[Link]("✅ Payment Successful! " + [Link]());

private static void cancelBooking() {

[Link]("Enter Booking ID: "); int id = [Link]();

Booking b = [Link](id);

if (b == null) { [Link]("❌ Invalid ID!"); return; }

if ([Link]() == [Link]) {

[Link]("Already cancelled!");

return;

[Link]();

[Link]("✅ Booking cancelled and seats released.");

private static void showPackages() {

[Link]("\nID Name Avail/Total Price");

[Link]("-----------------------------------------------");

for (TourPackage t : [Link]()) [Link]();

ARUL SIVAM 717825P501


DEPARTMENT OF COMPUTER SCIENCE JAVA PROGRAMMING

OUTPUT:

ARUL SIVAM 717825P501


DEPARTMENT OF COMPUTER SCIENCE JAVA PROGRAMMING

ARUL SIVAM 717825P501


DEPARTMENT OF COMPUTER SCIENCE JAVA PROGRAMMING

Github link : [Link]

ARUL SIVAM 717825P501

You might also like