public class ArrayIntList extends AbstractIntCollection implements IntList public class ArrayIntStack extends AbstractIntCollection implements IntStackAdditionally, write a program CollectionMain that demonstrates how the two classes can be used.
Your task is to create a programming system for a ferry. The ferry transports passengers and vehicles (cars, busses, lorries and bicycles). The ferry has space for 200 passengers and 40 cars. A lorry needs as much space as two busses or 8 cars. A car needs as much space as 5 bicycles. There are different fees for different vehicles and an extra fee might be added for passengers. Use the following fees:
public interface Ferry { int countPassengers(); // Number of passengers on board int countVehicleSpace(); // Used vehicle space. One car is 1. int countMoney(); // Earned money Iterator<Vehicle> iterator(); // Vehicle iterator void embark(Vehicle v); // Embark vehicle, warning if not enough space void embark(Passenger p); // Embark passenger, warning if not enough room void disembark(); // Clear (empty) ferry. The money earned remains, // i.e., is not reset to zero boolean hasSpaceFor(Vehicle v); // true if we can embark vehicle v boolean hasRoomFor(Passenger p); // true if we can embark passenger p String toString(); // Nice looking ferry status print out }A vehicle cannot leave the ferry until the ferry has been disembarked and the same vehicle cannot embark twice. The ferry iterator should iterate over all vehicles embarked (not the passengers). Also write a program FerryMain.java, embarking a number of vehicles and passengers, showing the functionality of the methods.
public static void main(String[] args) { // Create and Customize Chart XYChart chart = new XYChartBuilder().width(800).height(600).build(); chart.getStyler().setDefaultSeriesRenderStyle(XYSeriesRenderStyle.Scatter); chart.getStyler().setChartTitleVisible(false); chart.getStyler().setLegendPosition(LegendPosition.InsideSW); chart.getStyler().setMarkerSize(5); // Generate data ListxData = new ArrayList (); List yData = new ArrayList (); Random random = new Random(); int size = 1000; for (int i = 0; i < size; i++) { xData.add(random.nextGaussian() ); yData.add(random.nextGaussian()); } // Display scatter plot chart.addSeries("Gaussian Blob", xData, yData); new SwingWrapper (chart).displayChart(); }
Part 1: Apply predicates Print all numbers: 45 3 24 16 1 1 3 8 7 6 10 12 17 22 30 Print all odd numbers: 45 3 1 1 3 7 17 Print all numbers greater than 10: 45 24 16 12 17 22 30 Part 2: Apply functions Original: [1.0, 16.0, 25.0, 81.0] Square root: [1.0, 4.0, 5.0, 9.0] Power of two: [1.0, 256.0, 625.0, 6561.0]
String text = readText("WarAndPeace.txt"); // My own method String[] words = text.split(" "); // Simple split, will be cleaned up later on System.out.println("Initial word count: "+words.length); // We found 577091 Streamstream = Arrays.stream(words); ... continue here