54 lines
1.7 KiB
Java
Raw Normal View History

2015-09-07 11:44:36 -06:00
// patterns/recycleb/RecycleB.java
2015-11-14 16:18:05 -08:00
// <20>2016 MindView LLC: see Copyright.txt
2015-06-15 17:47:35 -07:00
package patterns.recycleb;
import patterns.trash.*;
import java.util.*;
public class RecycleB {
public static void main(String[] args) {
2015-11-03 12:00:44 -08:00
List<Trash> bin = new ArrayList<>();
2015-06-15 17:47:35 -07:00
// Fill up the Trash bin:
2015-11-03 12:00:44 -08:00
ParseTrash.fillBin("trash", bin);
List<Glass> glassBin = new ArrayList<>();
List<Paper> paperBin = new ArrayList<>();
List<Aluminum> alBin = new ArrayList<>();
// Sort the Trash:
bin.forEach( t -> {
// RTTI to discover Trash type:
if(t instanceof Aluminum)
alBin.add((Aluminum)t);
if(t instanceof Paper)
paperBin.add((Paper)t);
if(t instanceof Glass)
glassBin.add((Glass)t);
});
Trash.sumValue(alBin);
Trash.sumValue(paperBin);
Trash.sumValue(glassBin);
2015-06-15 17:47:35 -07:00
Trash.sumValue(bin);
}
2015-09-07 11:44:36 -06:00
}
/* Output: (First and last 10 Lines)
2015-06-15 17:47:35 -07:00
Loading patterns.trash.Glass
Loading patterns.trash.Paper
Loading patterns.trash.Aluminum
Loading patterns.trash.Cardboard
weight of patterns.trash.Aluminum = 89.0
weight of patterns.trash.Aluminum = 76.0
weight of patterns.trash.Aluminum = 25.0
weight of patterns.trash.Aluminum = 34.0
weight of patterns.trash.Aluminum = 27.0
weight of patterns.trash.Aluminum = 18.0
________...________...________...________...________
weight of patterns.trash.Aluminum = 93.0
weight of patterns.trash.Glass = 93.0
weight of patterns.trash.Paper = 80.0
weight of patterns.trash.Glass = 36.0
weight of patterns.trash.Glass = 12.0
weight of patterns.trash.Glass = 60.0
weight of patterns.trash.Paper = 66.0
weight of patterns.trash.Aluminum = 36.0
weight of patterns.trash.Cardboard = 22.0
Total value = 1086.0599818825722
2015-09-07 11:44:36 -06:00
*/