Answer to Question #256592 in Java | JSP | JSF for sjk

Question #256592
Complete the class Traveller as per the below requirement


**class Traveller**



Define the following properties. properties should be private:


 -id : int 
 -travelType : String 
 -price : double
 -locations : String


- Define Getters and setters for all properties 


- Define parameterized constructor



-- Create TravelProcess class and define ArrayList of 10 Travellers



Use Switch case and Perform the below Operatios


case-1 add new Traveller with the list
case-2 Display all the traveller details
case-3 Search for a specific traveller and display if found
case-4 Exit
1
Expert's answer
2021-10-26T01:03:29-0400
public class Traveller {
    private int id;
    private String travellerType;
    private double price;
    private String locations;

    public Traveller(int id, String travellerType, double price, String locations) {
        this.id = id;
        this.travellerType = travellerType;
        this.price = price;
        this.locations = locations;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getTravellerType() {
        return travellerType;
    }

    public void setTravellerType(String travellerType) {
        this.travellerType = travellerType;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public String getLocations() {
        return locations;
    }

    public void setLocations(String locations) {
        this.locations = locations;
    }
}



import java.util.ArrayList;

public class TravelProcess {
    public static void main(String[] args) {
        ArrayList<Traveller> travellers = new ArrayList<>();
        int operation = 1;
        int id = 0;
        for (int i = 0; i < 10; i++) {
            travellers.add(new Traveller(id++, "Type", 0, "Location"));
        }
        switch (operation) {
            case 1:
                travellers.add(new Traveller(id++, "Type", 0, "Location"));
                break;
            case 2:
                for (Traveller traveller : travellers) {
                    System.out.println(traveller.getId() + " " + traveller.getTravellerType() +
                            " " + traveller.getPrice() + " " + traveller.getLocations());
                }
                break;
            case 3:
                for (Traveller traveller : travellers) {
                    if (traveller.getId() == id) {
                        System.out.println(traveller.getId() + " " + traveller.getTravellerType() +
                                " " + traveller.getPrice() + " " + traveller.getLocations());
                    }
                }
                break;
            case 4:
                System.exit(0);
        }
    }
}

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