trickTruck

 avatar
timor
java
2 years ago
4.5 kB
3
Indexable
Never
import java.util.ArrayList;

public class TrickTruck {
	public static int daysInJune = 30;

	private ArrayList<Payment>[] payments = new ArrayList[daysInJune];
	private ArrayList<Integer> cars;
	private ArrayList<String> drivers;

	/**
	 * constructor
	 */
	public TrickTruck() {

		cars = new ArrayList<Integer>();
		drivers = new ArrayList<String>();
		for (int i = 0; i < daysInJune; i++) {
			payments[i] = new ArrayList<Payment>();
		}
	}

	public ArrayList<Integer> getCars() {
		return cars;
	}

	public ArrayList<String> getDrivers() {
		return drivers;
	}

//	public void getPayments() {
//		int j = 0;
//		for (int i = 0; i < daysInJune; i++) {
//			j = 0;
//			while (j < payments[i].size()) {
//
//				System.out.println(payments[i].get(j).getAmount());
//				System.out.println(payments[i].get(j).getDay());
//				System.out.println(payments[i].get(j).getName());
//				System.out.println(payments[i].get(j).getLicensePlate());
//				j++;
//			}
//		}
//	}

	public void setDriver(ArrayList<String> drivers) {

		this.drivers = drivers;
	}

	public void setCars(ArrayList<Integer> cars) {
		this.cars = cars;
	}

	public void setPayments(Payment payment) {
		payments[payment.getDay() - 1].add(payment);
	}

	/**
	 * 
	 * @param driver- a name of driver that we want to search
	 * @return if he exist true if not false
	 */
	public boolean existDriver(String driver) {

		for (int i = 0; i < drivers.size(); i++) {

			if (driver == drivers.get(i)) {
				return true;
			}
		}
		return false;
	}

	/**
	 * 
	 * @param car- a number of licensePlate that we want to search
	 * @return if it exist true if not false
	 */
	public boolean existCar(int car) {

		for (int i = 0; i < cars.size(); i++) {

			if (car == cars.get(i)) {
				return true;
			}
		}
		return false;
	}

	/**
	 * 
	 * @param nameDriver - the name that we want to know if he work in
	 * @param day        - the specific day
	 * @return if he work we return true if not false
	 */
	public Boolean Worked(String nameDriver, int day) {
		for (int i = 0; i < payments[day - 1].size(); i++) {
			if (nameDriver == payments[day - 1].get(i).getName()) {
				return true;
			}
		}
		return false;
	}

	/**
	 * 
	 * @param payment that we want to add or not if the name driver and the
	 *                licensePlate in the payment are exist in cars and drivers we
	 *                send this payment to "setPayment" to add it and return true if
	 *                not we return false
	 * @return
	 */
	public Boolean addPayment(Payment payment) {
		if (existDriver(payment.getName()) == true && existCar(payment.getLicensePlate()) == true) {
			Payment newPayment = new Payment(payment);
			setPayments(newPayment);
			System.out.println("The payment was successfully added");
			return true;
		} else {
			System.out.println("The payment was not added");
			return false;

		}
	}
/**
 * 
 * @param day in the payment
 * @param licensePlate in the payment
 * @param name in the payment
 * @param amount in the payment
 * this method work the same as "addPayment(Payment payment)"
 * 
 */
	public Boolean addPayment(int day, int licensePlate, String name, double amount) {
		if (existDriver(name) == true && existCar(licensePlate) == true) {
			Payment newPayment = new Payment(day, licensePlate, name, amount);
			setPayments(newPayment);
			System.out.println("The payment was successfully added");
			return true;
		} else {
			System.out.println("The payment was not added");
			return false;

		}
	}
/**
 * 
 * @param licensePlate in the payment
 * we check every day on June the amount of fuel of each car
 * we return the amount
 */
	public double totalFuel(int licensePlate) {
		int j = 0;
		double sumTotalFuel = 0;
		for (int i = 0; i < daysInJune; i++) {
			j = 0;
			while (j < payments[i].size()) {
				sumTotalFuel = sumTotalFuel + payments[i].get(j).getAmount();
				j++;
			}
		}
		return sumTotalFuel;
	}
/**
 * 
 * @param licensePlate in the payment
 * @param day the specific day that we want to search
 * return the amount of fuel that the car used on specific day 
 */
	public double totalFuel(int licensePlate, int day) {

		double SumTotalAtDay = 0;
		for (int i = 0; i < payments[day - 1].size(); i++) {
			SumTotalAtDay = SumTotalAtDay + payments[day - 1].get(i).getAmount();
		}
		return SumTotalAtDay;

	}

}