// Arup Guha
// 10/16/2026
// Solution to COP 3330 Exam #2 Question #7

import java.util.*;

public class Phone implements Rechargeable {

	private double charge;
	
	// Directions said to set this to 1.
	public Phone() {
		charge = 1.0;
	}
	
	// Recharges phone for hours number of hours.
	public void recharge(double hours) {
		
		// hours/8 is amount of charge gained, so add that, but you can't get
		// past 1.
		charge = Math.min(1.0, charge + hours/8);
	}
	
	// Uses the Phone for hours number of hours.
	public void use(double hours) {
		
		// Each hour depletes 1.0/24 of the battery...
		charge = Math.max(0, charge - hours/24);
	}
	
	public String toString() {
		return "PHONE "+charge;
	}
	
	/*** Some tests. ***/
	public static void main(String[] args) {

		Random r = new Random();
		
		Phone mine = new Phone();
		for (int i=0; i<5; i++) {
			
			int hrs = r.nextInt(18)+1;
			System.out.println(i+" "+mine+" "+hrs);
			if (i%2 == 0)
				mine.use(hrs);
			else
				mine.recharge(hrs/4);
			
			System.out.println(i+" "+mine);
		}
	}
}