Question 1
Tourists t1 and t2 visit a set of tourist places in India. Tourist t2, besides visiting all the tourist places visited by t1, also visits an additional place. Write a Java program that models this scenario using a copy constructor. The code should take as input the name of Tourist t1 and the two tourist places visited by t1, followed by the name of Tourist t2 and the additional place visited by t2.
- Class
TouristhastName,tPlacesas instance variables.- It should have two parameterized constructors, one to instantiate the instance variables and the other is a copy constructor.
- Implement the copy constructor
public Tourist(Tourist t)so that any later change in the visited places of Touristt2does not affect the visited places oft1. - Override the method
toString()to display the output as shown in the test cases.
- Class
TravellerTesthas the main method.- It accepts the names of the tourists, places visited by
t1and the additional place visited byt2as input.
- It accepts the names of the tourists, places visited by