hi there, i have to do a school project and it's about a dvd rental system. I have the following classes ; Client, SalesPerson(both inherit from the class Person), Loan class, DVD class, Runner, DvdShop.
Now my problem is how do I sort the DVDs when the user inputs his choice in the menu to show all dvds .
I have tried to do the code but it gives me an error. I don't know what's wrong with it. Here is what I tried so far;
P.S. DVDs ARE ADDED TO THE ARRAYLIST NAMED dList which I have declared at the beginning as ; ArrayList dList = new ArrayList () ;
the following is in the DvdShop class;
public String showAllDvds()
int temp = 0;
int n = dList.size();
String tmpDvd = "";
for(int i = 0; i < n; i++)
for(int j = 0; j < (n-i); j++)
if(dList[j-1] > dList[j])
//swap the elements
temp = dList[j-1];
dList[j-1] = dList[j];
dList[j] = temp;
/* DVD tmpDVD = (DVD) dList.get(i);
tmpDvd += "DVD " + (id+1) + ": " + tmpDVD.toString() + "\n";*/
tmpDvd = "No DVDs found! ";
while the following is in the runner class ;
//Show all DVDs in DvdShop
for(int i=0; i < dList.size; i++)
System.out.println(dList[i] + " ");
Can you please help?? thanks.