Hi! The assignment asks me to make a program that uses Data Lists to store TV show information. It needs to be able to:
Add/enter TV shows and keep track of them
Modify TV shows by asking which show to be modified and search for it using the search key then modify the show that information
Delete TV shows (like the modify option) by searching for a show using the show's name and have it be removed by shifting the array one space
Sort TV shows by asking the user what sort key he/she would like to use (name, day, time) and sorts the list using that key (alphabetically and numerically)
Show all TV shows by outputting all the shows and also gives totals for the number of shows per day
I've written the code and it runs, but not correctly. After first inputting the show info and it sorts it properly the first time, then I delete, modify, and add more shows, it doesn't sort properly after that. It's all messed up! Can you look over my code and help me with this? I've been looking over it for hours, but I can't figure out what the problem is!!
Keep in mind that I MUST use Java 4 (required by my teacher). It's ancient and inefficient and it means that I can't use ArrayList to store my data. Can you please help me out? I don't know where I'm going wrong!
The code's very long and I apologize for it. I understand that you may not have the time to look through it, but I don't really know where the problem is coming from, so I can't highlight just one area...
Keep in mind that I MUST use Java 4 (required by my teacher). It's ancient and inefficient and it means that I can't use ArrayList to store my data.
Err so why does your code contains the following line?
Learning to debug your code is an important part of learning to write code. The thing to do is to add print out statements in one of the sort methods and print out the values of variables so you can see what is happening as the code runs.
BTW when swapping the position of objects you don't need to copy their state to a temporary object, just copy the object reference to a temporary variable and then move the objects themselves.
Right, sorry. I meant that I can't use generics, not ArrayList. Virtual Freudian-slip. My bad!
I don't quite understand what you meant by
Tony Docherty wrote:BTW when swapping the position of objects you don't need to copy their state to a temporary object, just copy the object reference to a temporary variable and then move the objects themselves.
Could you elaborate?
Joined: Aug 07, 2007
If you have an array and you want to swap the positions of two elements at say index i and index j you can just do this: