reset password
Author Message
304374842
Posts: 56
Posted 18:06 Sep 14, 2016 |

I'm having a problem with getting the date to work correctly.  We are supposed to have it input as a String and then separated at the / marks and then printed as mm/dd/yyyy?

My code only prints 0/0/0.  Any suggestion at what I could be doing wrong?

rcamach7
Posts: 31
Posted 18:25 Sep 14, 2016 |

Right, the initial input is taken as a String & then you separate the three digits and store them.

Make sure you're separating the numbers from the string correctly, you can try making another class and testing that out to see if it's working properly. Once you have that working the toString() method should be printing out the correct date, as you're just printing the three ints + "/" where they're needed.

The way I did it was by using the .split method to create an array of strings without the "/" and parsing them into ints.

Last edited by rcamach7 at 18:35 Sep 14, 2016.
304374842
Posts: 56
Posted 19:15 Sep 14, 2016 |

So, the date is separated in the MonsterAttack class not the MonsterMonitor class?  What I'm having problems with is inputting it when I add an attack in the MonsterMonitor class.

rcamach7
Posts: 31
Posted 19:32 Sep 14, 2016 |

Yeah, the date is separated in the MonsterAttack class. From the MonsterMonitor class, you're only sending the date as a String, as with other values you need to send (location, victims, etc). 

Yeah, just send the string and separate it to digits on the MonsterAttack class. 

304374842
Posts: 56
Posted 20:16 Sep 14, 2016 |

Thanks got it!

nmanimt2
Posts: 8
Posted 20:53 Sep 14, 2016 |

Question, and correct me if I'm wrong, what's the point of separating and parsing the string date to three ints, when toString() will basically revert it to the date string, and same format too right mm/dd/yyyy?

304374842
Posts: 56
Posted 08:39 Sep 15, 2016 |

I think he is having us practice different methods is my understanding.

Has anyone else had problems deleting an entry?  I understand that .remove is for the index but I am having a problem referencing the arraylist index to remove.  I can get it to remove index 1 when I put in ID 1, but I can't get it to reference the location.

With arrays we did array(i) and it would refer to the item at that index.  Does it work the same for array lists?