relationships 1

PHOTO EMBED

Wed May 29 2024 09:30:08 GMT+0000 (Coordinated Universal Time)

Saved by @exam123

//Country.java
class Country {
    private String iataCountryCode;
    private String countryName;

    public Country() {
    }

    public Country(String iataCountryCode, String countryName) {
        this.iataCountryCode = iataCountryCode;
        this.countryName = countryName;
    }

    public String getIataCountryCode() {
        return iataCountryCode;
    }

    public void setIataCountryCode(String iataCountryCode) {
        this.iataCountryCode = iataCountryCode;
    }

    public String getCountryName() {
        return countryName;
    }

    public void setCountryName(String countryName) {
        this.countryName = countryName;
    }

    @Override
    public String toString() {
        return String.format("%-25s %s", iataCountryCode, countryName);
    }
}

//Client.java
class Client {
    private Integer clientId;
    private String clientName;
    private String phoneNumber;
    private String email;
    private String passport;
    private Country country;

    public Client() {
    }

    public Client(Integer clientId, String clientName, String phoneNumber, String email, String passport, Country country) {
        this.clientId = clientId;
        this.clientName = clientName;
        this.phoneNumber = phoneNumber;
        this.email = email;
        this.passport = passport;
        this.country = country;
    }

    public Integer getClientId() {
        return clientId;
    }

    public void setClientId(Integer clientId) {
        this.clientId = clientId;
    }

    public String getClientName() {
        return clientName;
    }

    public void setClientName(String clientName) {
        this.clientName = clientName;
    }

    public String getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPassport() {
        return passport;
    }

    public void setPassport(String passport) {
        this.passport = passport;
    }

    public Country getCountry() {
        return country;
    }

    public void setCountry(Country country) {
        this.country = country;
    }

    @Override
    public String toString() {
        return String.format("%-25s %-25s %-25s %-25s %-25s %s", clientId, clientName, phoneNumber, email, passport, country);
    }
}


//ClientBO.java
class ClientBO {
    void viewDetails(Client[] clientList) {
        System.out.printf("%-25s %-25s %-25s %-25s %-25s %-25s %-25s\n", "ClientId", "ClientName", "PhoneNumber", "Email", "Passport", "IATACountryCode", "CountryName");
        for (Client client : clientList) {
            System.out.println(client);
        }
    }

    void printClientDetailsWithCountry(Client[] clientList, String countryName) {
        System.out.printf("%-25s %-25s %-25s %-25s %-25s %-25s %-25s\n", "ClientId", "ClientName", "PhoneNumber", "Email", "Passport", "IATACountryCode", "CountryName");
        boolean found = false;
        for (Client client : clientList) {
            if (client.getCountry().getCountryName().equalsIgnoreCase(countryName)) {
                System.out.println(client);
                found = true;
            }
        }
        if (!found) {
            System.out.println("No clients found for the specified country.");
        }
    }
}


//Main.java
import java.util.*;
import java.io.*;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        Integer n, i, ch;
        String clientName, phoneNumber, email, passport, countryName, iataCountryCode;
        Integer clientId;

        System.out.println("Enter number of clients");
        n = Integer.parseInt(br.readLine());
        Client clientList[] = new Client[n];

        ClientBO clientBo = new ClientBO();

        Country country = new Country();

        for (i = 0; i < n; i++) {
            clientList[i] = new Client();
            System.out.println("Enter client " + (i + 1) + " details:");

            System.out.println("Enter the client id");
            clientId = Integer.parseInt(br.readLine());

            System.out.println("Enter the client name");
            clientName = br.readLine();

            System.out.println("Enter the phone number");
            phoneNumber = br.readLine();

            System.out.println("Enter the email id");
            email = br.readLine();

            System.out.println("Enter the passport number");
            passport = br.readLine();

            System.out.println("Enter the iata country code");
            iataCountryCode = br.readLine();

            System.out.println("Enter the country name");
            countryName = br.readLine();

            country = new Country(iataCountryCode, countryName);

            clientList[i] = new Client(clientId, clientName, phoneNumber, email, passport, country);

        }

        do {
            System.out.println("Menu:");
            System.out.println("1. View client details");
            System.out.println("2. Filter client with country");
            System.out.println("3. Exit");

            ch = Integer.parseInt(br.readLine());

            if (ch == 1) {
                clientBo.viewDetails(clientList);
            } else if (ch == 2) {
                System.out.println("Enter country name");
                countryName = br.readLine();
                clientBo.printClientDetailsWithCountry(clientList, countryName);
            } else
                break;

        } while (ch <= 2);

    }

}

content_copyCOPY