И чужой код пробовал и местами менял, всё равно по этому не пропускает(
public class AdvertisementManager {
private final AdvertisementStorage storage = AdvertisementStorage.getInstance();
private int timeSeconds;
public AdvertisementManager(int timeSeconds) {
this.timeSeconds = timeSeconds;
}
public void processVideos() {
List<Advertisement> availableVideos = storage.list();
List<Advertisement> showVideos = new ArrayList<>();
int totalTime = 0;
for (Advertisement video : availableVideos) {
if (video.getDuration() < timeSeconds) {
if ((totalTime + video.getDuration()) < timeSeconds) {
totalTime = totalTime + video.getDuration();
showVideos.add(video);
} else
totalTime = totalTime;
}
}
if (availableVideos.isEmpty()) {
throw new NoVideoAvailableException();
}
Collections.sort(availableVideos, new Comparator<Advertisement>() {
@Override
public int compare(Advertisement o1, Advertisement o2) {
long pricePerVideoDiff = o2.getAmountPerOneDisplaying() - o1.getAmountPerOneDisplaying();
if (pricePerVideoDiff != 0) {
return (int) pricePerVideoDiff;
} else {
return (int) (o1.getAmountPerOneDisplaying() * 1000 / o1.getDuration() - o2.getAmountPerOneDisplaying() * 1000 / o2.getDuration());
}
}
});
totalTime = timeSeconds;
StatisticManager.getInstance().register(new VideoSelectedEventDataRow(
availableVideos, availableVideos.size(), totalTime));
for (Advertisement adVideo : availableVideos) {
if (adVideo.getDuration() <= totalTime && adVideo.getHits() > 0) {
ConsoleHelper.writeMessage(String.format("%s is displaying... %d, %d", adVideo.getName(),
adVideo.getAmountPerOneDisplaying(), adVideo.getAmountPerOneDisplaying() * 1000 / adVideo.getDuration()));
adVideo.revalidate();
totalTime -= adVideo.getDuration();
}
}
}
}
public class Advertisement {
private Object content;
private String name;
private long initialAmount;
private int hits;
private int duration;
private long amountPerOneDisplaying;
public Advertisement(Object content, String name, long initialAmount, int hits, int duration) {
this.content = content;
this.name = name;
this.initialAmount = initialAmount;
this.hits = hits;
this.duration = duration;
amountPerOneDisplaying = initialAmount/hits;
}
public Object getContent() {
return content;
}
public int getDuration() {
return duration;
}
public long getAmountPerOneDisplaying() {
return amountPerOneDisplaying;
}
public String getName() {
return name;
}
public void revalidate() {
if (hits <= 0) throw new UnsupportedOperationException();
else hits--;
}
public int getHits() {
return hits;
}
public double getAmountPerSecond() {
return (double)amountPerOneDisplaying / duration;
}
}
public class Tablet extends Observable {
private final int number;
public static Logger logger = Logger.getLogger(Tablet.class.getName());
public Tablet(int number) {
this.number = number;
}
public Order createOrder() {
Order order = null;
try
{
order = new Order(this);
ConsoleHelper.writeMessage(order.toString());
if(!order.isEmpty())
{
try
{
new AdvertisementManager(order.getTotalCookingTime()*60).processVideos();
}
catch (NoVideoAvailableException e)
{
logger.log(Level.INFO, "No video is available for the order " + order);
}
setChanged();
notifyObservers(order);
}
}
catch (IOException e)
{
logger.log(Level.SEVERE, "Console is unavailable.");
}
return order;
}
@Override
public String toString() {
return "Tablet{" + "number=" + number + '}';
}
public class ConsoleHelper {
private static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
public static void writeMessage(String message) {
System.out.println(message);
}
public static String readString() throws IOException {
return reader.readLine();
}
public static List<Dish> getAllDishesForOrder() throws IOException {
List<Dish> orderedDishes = new ArrayList<>();
if (Dish.values().length > 0) {
writeMessage(Dish.allDishesToString());
String nextDish;
while (!"exit".equalsIgnoreCase(nextDish = readString())) {
try {
orderedDishes.add(Dish.valueOf(nextDish));
} catch (IllegalArgumentException e) {
ConsoleHelper.writeMessage("No such dish: " + nextDish);
}
}
}
return orderedDishes;
}
}
package com.javarush.task.task27.task2712;
import com.javarush.task.task27.task2712.ad.AdvertisementManager;
import com.javarush.task.task27.task2712.ad.NoVideoAvailableException;
import com.javarush.task.task27.task2712.kitchen.Order;
import java.io.IOException;
import java.util.Observable;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Tablet extends Observable {
private final int number;
public static Logger logger = Logger.getLogger(Tablet.class.getName());
public Tablet(int number) {
this.number = number;
}
public Order createOrder() {
Order order = null;
try
{
order = new Order(this);
ConsoleHelper.writeMessage(order.toString());
if(!order.isEmpty())
{
try
{
new AdvertisementManager(order.getTotalCookingTime()*60).processVideos();
}
catch (NoVideoAvailableException e)
{
logger.log(Level.INFO, "No video is available for the order " + order);
}
setChanged();
notifyObservers(order);
}
}
catch (IOException e)
{
logger.log(Level.SEVERE, "Console is unavailable.");
}
return order;
}
@Override
public String toString() {
return "Tablet{" + "number=" + number + '}';
}
}