0

I have a ArrayList of objects which stored either a ForSaleProperty object or RentalProperty object;

static ArrayList<Object> obj = new ArrayList<Object>();

My RentalProperty and a ForSaleProperty is subclass of Property

RentalProperty extends Property 
ForSaleProperty extends Property

Inside Property, I have an Address and ViewingArrangement object.

In ViewingArrangement, i have a ContactPerson object an a String openTime variable. I also have the method setOpenTime in ViewingArrangement.

Problem :

How do i access the setOpenTime() method in ViewingArrangement.

In my Object arraylist, i have this

RentalProperty rp1 = new RentalProperty(1500,"6-Jun-16");
Address a1 = new Address(150,"Tampines Ave 5","Singapore",6002);
ContactPerson cp1 = new ContactPerson("Benjamin","Murdoch",2738482);
ViewingArrangement va1 = new ViewingArrangement(cp1,"1000H");
rp1.setAddress(a1);
rp1.setVA(va1);

obj.add(rp1);

So now i want to change the openTime of rp1.

I tried the following but cant access the method in my object.

static void editOpenTime()
{
    int input;
    String newOpenTime;
     listProperty();
     Scanner in = new Scanner(System.in);
     System.out.println("Enter property number : ");
     input = in.nextInt(); in.nextLine();
     System.out.println("Enter new open time for property # : "+input);
     newOpenTime = in.nextLine();

     obj.get(input).

}
Ben Yap
  • 199
  • 1
  • 4
  • 11
  • i cant seems to the list of methods. Do i have to static the methods? public void setTime(String time) { this.time = time; } – Ben Yap May 29 '16 at 07:57

1 Answers1

0

First it is better to use a type that is not Object if possible for type safety. In your case use Property since both extend that.

static ArrayList<Property> properties = new ArrayList<Property>();

Then you can get the VA like follows:

ViewingArrangement va = properties.get(input).getVA();
va.setOpenTime()
divandc
  • 149
  • 5