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 TravellersUse Switch case and Perform the below Operatioscase-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 Exitpublic 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);
}
}
}
Comments