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 = "";
if(n>0)
{
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";*/
}
else
{
tmpDvd = "No DVDs found! ";
}
return tmpDvd;
}
while the following is in the runner class ;
case 7:
//Show all DVDs in DvdShop
System.out.println(myDvdShop.showAllDvds());
for(int i=0; i < dList.size; i++)
{
System.out.println(dList[i] + " ");
}
break;
Can you please help?? thanks.