APISonar


edu.princeton.cs.algs4.Date.Date

> edu > princeton > cs > algs4 > Date > Date
edu APIs princeton APIs cs APIs algs4 APIs Date APIs Date APIs

Example 1
public static void main (String[] args) {
		Date date = new Date(8, 5, 2016);
		
		Exercise19_2_Parsing transaction = new Exercise19_2_Parsing("Turing", date, 22.10);
		StdOut.println(transaction);
		StdOut.println("Expected: Turing spent 22.1 on 8/5/2016");
	}
Example 2
public Exercise19_2_Parsing(String transaction) {
		String[] values = transaction.split(" ");
		who = values[0];
		when = new Date(values[1]);
		amount = Double.parseDouble(values[2]);
	}
Example 3
public static void main (String[] args) {
		Date date = new Date(8, 3, 2016);
		
		Exercise14 transaction1 = new Exercise14("Rene", date, 500);
		Exercise14 transaction2 = new Exercise14("Rene", date, 500);
		Exercise14 transaction3 = new Exercise14("Argento", date, 600);
		Exercise14 transaction4 = transaction3;
		
		StdOut.println("Equals 1: " + transaction1.equals(transaction2) + " Expected: true");
		StdOut.println("Equals 2: " + transaction2.equals(transaction1) + " Expected: true");
		StdOut.println("Equals 3: " + transaction1.equals(transaction3) + " Expected: false");
		StdOut.println("Equals 4: " + transaction3.equals(transaction4) + " Expected: true");
	}
Example 4
public static void main(String[] args) {
        Exercise25_HashCache hashCache = new Exercise25_HashCache();

        Transaction transaction = hashCache.new Transaction("Person 1", new Date(1, 10, 5), 1000);
        StdOut.println(transaction.hashCode() + " Expected: Cache miss");
        StdOut.println(transaction.hashCode() + " Expected: Cache hit");
        StdOut.println(transaction.hashCode() + " Expected: Cache hit");
    }