Hallo Ihr Lieben.
und normale Klasse:
Warum wird mir nichts auf der Konsole angezeigt?
Java:
public class DVDShopTest {
IFDVDShop shop = new DVDShop();
DVD dvd0 = new DVD();
DVD dvd1 = new DVD();
DVD dvd2 = new DVD();
DVD dvd3 = new DVD();
@Before
public void setUp() throws Exception {
this.dvd0.setTitle("Asterix");
this.dvd1.setTitle("Obelix");
this.dvd2.setTitle("Caesar");
this.dvd3.setTitle("Cleopatra");
this.dvd0.setPrice(10.40);
this.dvd1.setPrice(6.40);
this.dvd2.setPrice(18.40);
this.dvd3.setPrice(7.40);
this.shop.add(dvd0);
this.shop.add(dvd1);
this.shop.add(dvd2);
this.shop.add(dvd3);
}
@Test
public void testSortByTitle() {
this.shop.sortByTitle();
System.out.println("sortByTitle: " + this.shop);
assertEquals("Caesar", this.shop.getDvdList().get(1).getTitle());
}
@Test
public void testSortByPrice() {
this.shop.sortByPrice();
System.out.println("sortByPrice: " + this.shop);
assertEquals("Caesar", this.shop.getDvdList().get(3).getTitle());
}
}
und normale Klasse:
Java:
public class DVDShop implements IFDVDShop{
ArrayList<DVD> list = new ArrayList<DVD>();
public DVDShop(){
}
@Override
public String toString(){
String s = "";
return s;
}
@Override
public ArrayList<DVD> getDvdList() {
return list;
}
@Override
public boolean add(DVD dvd) {
list.add(dvd);
if(list.contains(dvd)){
return true;
}else{
return false;
}
}
@Override
public void sortByTitle() {
boolean unsortiert = true;
while (unsortiert == true) {
unsortiert = false;
for (int i = 0; i < list.size() - 1; i++) {
int k = (list.get(i).getTitle().compareTo(list.get(i+1).getTitle()));
if (k > 0){
DVD temp = list.get(i);
DVD temp2 = list.get(i + 1);
list.set(i + 1, temp);
list.set(i, temp2);
unsortiert = true;
}
}
}
}
@Override
public void sortByPrice() {
boolean unsortiert = true;
while (unsortiert == true) {
unsortiert = false;
for (int i = 0; i < list.size() - 1; i++) {
double k = (list.get(i).getPrice());
double l = (list.get(i + 1).getPrice());
if (k > l){
DVD temp = list.get(i);
DVD temp2 = list.get(i + 1);
list.set(i + 1, temp);
list.set(i, temp2);
unsortiert = true;
}
}
}
}
}
Warum wird mir nichts auf der Konsole angezeigt?