// Path: src/main/java/shopJava/model/Credentials.java
// public class Credentials {
// 
//     public final String username;
//     public final String password;
// 
//     public Credentials(final String username, final String password) {
//         this.username = username;
//         this.password = password;
//     }
// }
// 
// Path: src/main/java/shopJava/model/Order.java
// public class Order {
// 
//     private static final String ID = "_id";
//     private static final String USERNAME = "first";
//     private static final String AMOUNT = "amount";
// 
//     public final int id;
//     public final String username;
//     public final int amount;
// 
//     public Order(final int id, final String username, final int amount) {
//         this.id = id;
//         this.username = username;
//         this.amount = amount;
//     }
// 
//     public Order(final Document doc) {
//         this(doc.getInteger(ID), doc.getString(USERNAME), doc.getInteger(AMOUNT));
//     }
// 
//     @Override
//     public String toString() {
//         return "Order{" +
//                 ID + "=" + id +
//                 ", " + USERNAME + "='" + username + '\'' +
//                 ", " + AMOUNT + "=" + (amount/100.0) +
//                 '}';
//     }
// 
//     public void print() {
//         System.out.print(this);
//     }
// 
//     public void println() {
//         System.out.println(this);
//     }
// 
//     public Document toDocument() {
//         return new Document(ID, id).append(USERNAME, username).append(AMOUNT, amount);
//     }
// }
// 
// Path: src/main/java/shopJava/model/User.java
// public class User {
// 
//     private static final String ID = "_id";
//     private static final String NAME = "name";
//     private static final String PASSWORD = "password";
// 
//     public final String name;
//     public final String password;
// 
//     public User(final String name, final String password) {
//         this.name = name;
//         this.password = password;
//     }
// 
//     public User(Document doc) {
//         this(doc.getString(ID), doc.getString(PASSWORD));
//     }
// 
//     @Override
//     public String toString() {
//         return "User{" +
//                 NAME + "='" + name + '\'' +
//                 ", " + PASSWORD + "='" + password + '\'' +
//                 '}';
//     }
// 
//     public void print() {
//         System.out.print(this);
//     }
// 
//     public void println() {
//         System.out.println(this);
//     }
// 
//     public Document toDocument() {
//         return new Document(ID, name).append(PASSWORD, password);
//     }
// }


import shopJava.model.Credentials;
import shopJava.model.Order;
import shopJava.model.User;
import java.util.List;
import java.util.Optional;
package shopJava.util;



public class Util {

    public static User checkUserLoggedIn(final Optional<User> optUser, final Credentials credentials) {

        if (!optUser.isPresent()) {     // replaces if (user != null)
            throw new RuntimeException(new IllegalAccessException("User unknown: " + credentials.username));
        }
        final User user = optUser.get();
        return checkUserLoggedIn(user, credentials);
    }

    public static User checkUserLoggedIn(final User user, final Credentials credentials) {
        if (!user.name.equals(credentials.username)) {
            throw new RuntimeException(new IllegalAccessException("Incorrect first: " + credentials.username));
        }
        if (!user.password.equals(credentials.password)) {
            throw new RuntimeException(new IllegalAccessException("Bad password supplied for user: " + credentials.username));
        }
        return user;
    }

    public static void sleep(final int seconds) {
        try {
            Thread.sleep(seconds * 1000L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static int average(final int totalAmount, final int orderCount) {
        return orderCount == 0 ? 0 : Math.round((100.0f * totalAmount / orderCount) / 100);
    }

// Path: src/main/java/shopJava/model/Credentials.java
// public class Credentials {
// 
//     public final String username;
//     public final String password;
// 
//     public Credentials(final String username, final String password) {
//         this.username = username;
//         this.password = password;
//     }
// }
// 
// Path: src/main/java/shopJava/model/Order.java
// public class Order {
// 
//     private static final String ID = "_id";
//     private static final String USERNAME = "first";
//     private static final String AMOUNT = "amount";
// 
//     public final int id;
//     public final String username;
//     public final int amount;
// 
//     public Order(final int id, final String username, final int amount) {
//         this.id = id;
//         this.username = username;
//         this.amount = amount;
//     }
// 
//     public Order(final Document doc) {
//         this(doc.getInteger(ID), doc.getString(USERNAME), doc.getInteger(AMOUNT));
//     }
// 
//     @Override
//     public String toString() {
//         return "Order{" +
//                 ID + "=" + id +
//                 ", " + USERNAME + "='" + username + '\'' +
//                 ", " + AMOUNT + "=" + (amount/100.0) +
//                 '}';
//     }
// 
//     public void print() {
//         System.out.print(this);
//     }
// 
//     public void println() {
//         System.out.println(this);
//     }
// 
//     public Document toDocument() {
//         return new Document(ID, id).append(USERNAME, username).append(AMOUNT, amount);
//     }
// }
// 
// Path: src/main/java/shopJava/model/User.java
// public class User {
// 
//     private static final String ID = "_id";
//     private static final String NAME = "name";
//     private static final String PASSWORD = "password";
// 
//     public final String name;
//     public final String password;
// 
//     public User(final String name, final String password) {
//         this.name = name;
//         this.password = password;
//     }
// 
//     public User(Document doc) {
//         this(doc.getString(ID), doc.getString(PASSWORD));
//     }
// 
//     @Override
//     public String toString() {
//         return "User{" +
//                 NAME + "='" + name + '\'' +
//                 ", " + PASSWORD + "='" + password + '\'' +
//                 '}';
//     }
// 
//     public void print() {
//         System.out.print(this);
//     }
// 
//     public void println() {
//         System.out.println(this);
//     }
// 
//     public Document toDocument() {
//         return new Document(ID, name).append(PASSWORD, password);
//     }
// }


// Path: src/main/java/shopJava/util/Util.java
import shopJava.model.Credentials;
import shopJava.model.Order;
import shopJava.model.User;
import java.util.List;
import java.util.Optional;

package shopJava.util;



public class Util {

    public static User checkUserLoggedIn(final Optional<User> optUser, final Credentials credentials) {

        if (!optUser.isPresent()) {     // replaces if (user != null)
            throw new RuntimeException(new IllegalAccessException("User unknown: " + credentials.username));
        }
        final User user = optUser.get();
        return checkUserLoggedIn(user, credentials);
    }

    public static User checkUserLoggedIn(final User user, final Credentials credentials) {
        if (!user.name.equals(credentials.username)) {
            throw new RuntimeException(new IllegalAccessException("Incorrect first: " + credentials.username));
        }
        if (!user.password.equals(credentials.password)) {
            throw new RuntimeException(new IllegalAccessException("Bad password supplied for user: " + credentials.username));
        }
        return user;
    }

    public static void sleep(final int seconds) {
        try {
            Thread.sleep(seconds * 1000L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static int average(final int totalAmount, final int orderCount) {
        return orderCount == 0 ? 0 : Math.round((100.0f * totalAmount / orderCount) / 100);
    }

    public static int totalAmountOf(final List<Order> orders) {