import java.util.ArrayList;

/**
 * Program demonstrates inheritance, as well as static/non-static methods
 */

/*
Write a main class, SendMail, that calculates how many letters you can send 
based on some initial dollar amount (assume $10). 
Create this many letters (use random numbers [10000, 99999] for destinations) 
and store them in an ArrayList. Finally, use an accessor from the Mail class 
to print out how many letters were sent.
 */
public class SendMail {
	
	public static void main(String[] args) {
		// Initial balance
		double dollars = 10;
		
		// Calculate how many letters can be sent for this balance
		int amountOfMailToSend = (int)(dollars/Letter.LETTER_COST);
		
		// Construct an array list to store the letters
		ArrayList<Letter> letters = new ArrayList<>();
		
		// Send mail
		System.out.println("Sending " + amountOfMailToSend + " letters.");
		for (int i = 0; i < amountOfMailToSend; i++) {
			letters.add(new Letter((int)(Math.random()*9000) + 1000));
		}
		
		// Use the static method getHowManySent to query the number of letters created
		System.out.println("Sent " + Mail.getHowManySent() + " pieces of mail.");
		
		// Verify the ArrayList is of the same size...
		System.out.println("Size of letters ArrayList: " + letters.size() + ".");
	}
}
/*
Design a class named Mail that represents an item of postal mail. The class contains:
- An integer data field that specifies the destination zip code for the recipient.
- A double data field that specifies the cost to send this mail.
- An integer data field that tracks how many Mail objects have been instantiated.
- A constructor that creates a Mail with the specified destination and cost.
- Appropriate getter methods for all data fields.
 */
class Mail {
	// Instance variables
	private int destZipCode;
	private double costToSend;
	
	// Static variable
	private static int howManySent;
	
	// Methods
	
	// Constructor
	public Mail(int destZipCode, double costToSend) {
		this.destZipCode = destZipCode;
		this.costToSend = costToSend;
		
		howManySent++;
	}
	
	// Appropriate getter methods for all data fields
	public int getDestZipCode() {
		return this.destZipCode;
	}
	
	public double getCostToSend() {
		return this.costToSend;
	}
	
	public static int getHowManySent() {
		return howManySent;
	}
}

/*
Design a class, Letter, that extends the Mail class. This class contains:
- A constant that specifies the cost to send any letter.
- A constructor that creates a Letter with a destination.
 */
class Letter extends Mail {
	final public static double LETTER_COST = 0.45;
	
	public Letter(int destination) {
		super(destination, LETTER_COST);
	}
}

