Scenario Dave goes for regular walks along different sections of a woodland path. He wishes to record
Question:
Scenario
Dave goes for regular walks along different sections of a woodland path. He wishes to record information about each walk as an instance of a class Walk. A Walk will have a list of strings, in which the first string represents the date of the walk, and the remaining strings in the list represent the places he visited on that walk, in the order he visited them. For example on 16/7/17 Dave started at Spookey Tree and visited Hill Top Town, West Wood, Tree Steps, and Home in that order.
This would be represented by a Walk instance whose ArrayList would hold the strings "16/7/17", "Spookey Tree", " Hill Top Town", "West Wood", " Tree Steps", "Home" in that order.
In this part of the question you will develop code for the Walking class.
Question 1:
(i) An object of this class has a list of strings representing the date and places as described in the scenario above. Write down the declaration of a private instance variable of Walking , called details, which should be declared as a List of String elements.
(ii) make a zero-argument constructor for Walking to initialise details with a suitable empty collection.(iii) make a two-argument constructor for Walking that takes a String argument representing the date of the walk, and a list of Strings representing places visited on that date (in order) and initialises details using these arguments.
(iv) make a public instance method addPlace() that takes a String argument representing a place to be added, adds it to the end of the details list, and returns the number of places now in details.
(v) make a public instance method whichPlace() that takes an int argument representing the position of the place to be found - so for example if the third place visited is required, then the value of this argument would be 3. If the argument is valid (i.e. does represent one of the places in details), the String representing that place should be returned, otherwise "Invalid index" should be returned.
Principles Of Database Management The Practical Guide To Storing Managing And Analyzing Big And Smal
ISBN: 9781107186125
1st Edition
Authors: Wilfried Lemahieu, Seppe Vanden Broucke, Bart Baesens