Answer to Question #262647 in Java | JSP | JSF for Thuy

Question #262647

Consider an example of online taxi services (i.e., Grab). The company has a list of customers and drivers.







When a customer requests a cab, then a driver accepts and visits the customer for a ride. Which







pattern can be used to implement this scenario? Explain with a UML diagram and also explain the list of







classes and methods involved in this pattern. After that, you must use an IDE (Eclipse) to implement







your design.







Note: You must submit a report and your code.

1
Expert's answer
2021-11-08T05:32:56-0500


SOLUTION TO THE ABOVE QUETION


SOLUTIN CODE


package com.company;
import java.util.*;

class Grab{
    private String customer_name;
    private String driver_name;
    private int driver_phone_number;
    private int customer_phone_number;
    private String vehicle_number_plate;
    //paarameterised constructor to initialize the driver names and customer_names
    public Grab(String c, String d)
    {
        this.customer_name = c;
        this.driver_name = d;
    }

    //set vehicle number plate
    public void setVehicle_number_plate(String n)
    {
        this.vehicle_number_plate = n;
    }
    //get vehicle number plate
    public String getVehicle_number_plate()
    {
        return vehicle_number_plate;
    }

    //set driver phone number
    public void setDriver_phone_number(int dn)
    {
        this.driver_phone_number = dn;
    }
    //get driver phone number
    public int getdriver_phone_number()
    {
        return driver_phone_number;
    }
    //set customer phone number
    public void setCustomer_phone_number(int dn)
    {
        this.customer_phone_number = dn;
    }
    //get customer phone number
    public int getCustomer_phone_number()
    {
        return customer_phone_number;
    }

    //dispaly method
    public void dispaly(int option)
    {
        if(option==1)
        {
            System.out.println("Dear customer "+customer_name+" our driver "+driver_name+" from "
                    +"Grab campany is coming to pick you up at your place,\n his phone number is "
                    +getdriver_phone_number()+" and the vehicle number plate is "+getVehicle_number_plate());
        }
        else {
            System.out.println("Dear Driver "+driver_name+" pick up our customer "+customer_name+" at his place "
                    +"her phone number is "+getCustomer_phone_number());
        }

    }

}

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        //create an object of the class Grab
        Grab g = new Grab("kelly","daniel");
        g.setVehicle_number_plate("KCC 188C");
        g.setDriver_phone_number(798268135);
        g.setCustomer_phone_number(712072537);

        System.out.println("Enter the person you want to send notification to: ");
        System.out.println("1.Customer");
        System.out.println("2.Driver");
        System.out.print("Enter option: ");
        int option = sc.nextInt();
        if(option==1 || option == 2)
        {
            g.dispaly(option);
        }
        else {
            System.out.println("Inavlid option");
        }
    }
}


SAMPLE OUTPUT PROGRAM





UML DIAGRAM



Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS