import java.util.*; // comparator, Arrays import java.io.*; // tarvitaan tietojen syöttöön /** * Jarjta.java * * Ohjelma järjestää kolme merkkijonoa aakkosjärjestykseen, taulukkototeutus. * Järjestäminen Javan Array-luokan sort-metodilla. * @author Miika Nurminen * @version 0.1 01/20/03 * */ public class Jarjta implements Comparator { /** määritetään taulukon koko vakiolla */ public static final int KOKO = 4; /** Compares its two arguments for order. Returns a negative integer, * zero, or a positive integer as the first argument is less than, equal * to, or greater than the second.
* * The implementor must ensure that sgn(compare(x, y)) == * -sgn(compare(y, x)) for all x and y. (This * implies that compare(x, y) must throw an exception if and only * if compare(y, x) throws an exception.)
* * The implementor must also ensure that the relation is transitive: * ((compare(x, y)>0) && (compare(y, z)>0)) implies * compare(x, z)>0.
* * Finally, the implementer must ensure that compare(x, y)==0 * implies that sgn(compare(x, z))==sgn(compare(y, z)) for all * z.
*
* It is generally the case, but not strictly required that
* (compare(x, y)==0) == (x.equals(y)). Generally speaking,
* any comparator that violates this condition should clearly indicate
* this fact. The recommended language is "Note: this comparator
* imposes orderings that are inconsistent with equals."
*
* @param o1 the first object to be compared.
* @param o2 the second object to be compared.
* @return a negative integer, zero, or a positive integer as the
* first argument is less than, equal to, or greater than the
* second.
* @throws ClassCastException if the arguments' types prevent them from
* being compared by this Comparator.
*
*/
public int compare(Object o1, Object o2) {
String s1 = o1.toString().toLowerCase();
String s2 = o2.toString().toLowerCase();
return s1.compareTo(s2);
}
/**
* Kysyy käyttäjältä merkkijonon annetulla tulosteella.
*
* @param prompt lause, joka käyttäjä näkee ennen tietojen syöttöä
* @return käyttäjän syöttämä merkkijono ilman rivinvaihtoa
*/
public static StringBuffer kysy(String prompt) {
System.out.print(prompt);
StringBuffer result = new StringBuffer();
// Syöttöpyyntö ja vastauksen lukeminen
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
try {
result.append(in.readLine());
} catch (IOException ex) {
}
return result;
}
/**
* Pääohjelma
*
* @param args Komentorivillä annetut parametetrit
*/
public static void main(String[] args) {
// taulukon järjestämistä käytettäessä ei tarvitse käyttää StringBufferia
String[] jonot = new String[KOKO];
int i;
for (i=0; i