// Arup Guha
// 10/12/2026
// Example of the Comparable Interface

import java.util.*;

public class Cat implements Comparable<Cat> {

	private String name;
	private int cuteness;
	
	// Standard constructor.
	public Cat(String myName, int cuteLevel) {
		name = myName;
		cuteness = cuteLevel;
	}
	
	// Our definition of how to compare cats.
	public int compareTo(Cat other) {
		
		// My main criteria is cuteness. This returns a negative integer if
		// my cuteness (this) is greater than other's cuteness. So, I am
		// sorting from most cute to least cute.
		if (this.cuteness != other.cuteness)
			return other.cuteness - this.cuteness;
			
		// If two cats are the same cuteness, then I just sort by
		// lexicographical order by name.
		return name.compareTo(other.name);
	}
	
	// String representation of the object.
	public String toString() {
		return name+" cuteness "+cuteness;
	}
	
	// Cats can increase their cuteness!
	public void increaseCute() {
		cuteness++;
	}
	
	// Returns a random 5 letter name using rndObj.
	public static String rndName(Random rndObj) {
		
		// Store the answer here.
		char[] name = new char[5];
		
		// Fill in each letter one by one.
		for (int i=0; i<5; i++) {
			
			// Random 0 to 25.
			int tmp = rndObj.nextInt(26);
			
			// First letter is upper case, rest is lowercase.
			char c = i == 0 ? (char)(tmp+'A') : (char)(tmp+'a');
			
			// Store the letter.
			name[i] = c;
		}
		
		// Returns the string version of this.
		return new String(name);
	}
	
	public static void main(String[] args) {
		
		Random rndObj = new Random();
		
		// Make random cats.
		Cat[] list = new Cat[20];
		for (int i=0; i<20; i++)
			list[i] = new Cat(rndName(rndObj), rndObj.nextInt(10)+1);
		
		// Print it.
		for (int i=0; i<20; i++)
			System.out.println(list[i]);
		System.out.println("---------------------------");
		
		// Sort it.
		Arrays.sort(list);
		
		// Print to show it.
		for (int i=0; i<20; i++)
			System.out.println(list[i]);
		System.out.println("---------------------------");
		
		// Increase cuteness.
		for (int i=0; i<5; i++)
			list[19].increaseCute();
		
		// Resort it.
		Arrays.sort(list);
		
		// Print last time.
		for (int i=0; i<20; i++)
			System.out.println(list[i]);
	}
}