










Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!











public void squares ( int n, int len)
public Picture squares ( int n, Color c1, Color c2)
public static int GCDTail( int A, int B) { if (B == 0) { return A; } else { return GCDTail(B, A % B); } }
public static int GCDWhile ( int A, int B) { // Flesh out this skeleton }
public static int [] copyReverse ( int [] a);
p (^17) -3 42 11 14
int [] q = copyReverse (p)
p (^17) -3 42 11 14
q 14 11 42 -3 17
public static void reverse ( int [] a);
r (^17) -3 42 11 14
reverse (r)
r
public static int weightedSum (IntList L) { return weightedSumTail (L, 1, 0); }
public static int weightedSumTail (IntList L, int index, int total) { if (isEmpty(L)) { return total; } else { return weightedSumTail(tail(L), index + 1, (index*head(L)) + total); } }
public static int isMember ( int n, int [] a) { int i = a.length - 1; while ((i >= 0) && (a[i] != n)) { i = i - 1; } return (i >= 0); // Will only be true if n is in a. }
public static void partialSum ( int [] a) { int sum = 0; for (int i = 0; i < a.length; i++) { sum = sum + a[i]; a[i] = sum; } }
public static void squiggle (Graphics g, int x1, int y1, int x2, int y2) { if ((x1 > 0) || (y1 > 0) || (x2 > 0) || (y2 > 0)) { g.drawLine(x1, y1, x2, y2); squiggle(g, x2, y2, y1/4, x1*2); } }
public static int [] listToArray (IntList L);
public static IntList arrayToList ( int [] a);
public static IntList reverse (IntList L) { if (isEmpty(L)) { return empty(); } else { return postpend(reverse(tail(L)), head(L)); } }
public static IntList postpend (IntList L, int n) { if (isEmpty(L)) { return prepend(n, empty()); } else { return prepend(head(L), postpend(tail(L), n)); } }
reverse( ListArgument ) : ListResult
postpend( ListArgument IntegerArgument ): ListResult
list result [1, 2, 3, 4] [] [2, 3, 4] [1] [3, 4] [2, 1] [4] [3, 2, 1] [] [4, 3, 2, 1]
return twoLists(lesses, greaters);
return twoLists(reverse(lesses), reverse(greaters));
public static IntList [] partitionNonTail ( int pivot, IntList L) { if (IL.isEmpty(L)) { return twoLists(IL.empty(), IL.empty()); } else { IntList [] subresult = partitionNonTail(pivot, IL.tail(L)); // flesh out the missing code here ... } }
lesses = [4, 1, 3, 2] greaters = [7, 6, 8]
public History ( int maxEntries);
public void add ( int amount, boolean cash);
public int size ();
public int min ( boolean cash);
public int max ( boolean cash);
public int average ( boolean cash);
public int number ( boolean cash);
public int percentageByNumber ( boolean cash);
public int percentageByAmount (boolean cash);
public class History {
// Instance Variables: private Purchase [ ] purchases; private int size;
// Constructor Method: public History ( int maxEntries) { purchases = new Purchase[maxEntries]; size = 0; }
// Instance Methods: public void add ( int amount, boolean cash) { if (size < purchases.length) { purchases[size] = new Purchase(amount, cash); size = size + 1; } }
// I still need to finish the other methods! - Emil - }
History h = new History(5); h.add(82, false); h.add(53, true); h.add(178, false);
public Purchase ( int amount, boolean cash) { amount = amount; cash = cash; }
public int numberOfLefts ();
LefistTurtle leo = new LeftistTurtle(); leo.lt(45); leo.rt(30); System.out.println(leo.numberOfLefts());
public void transferFromSavingsToChecking( int transferAmount) { this .savings = this .savings - transferAmount; this .checking = this .checking + transferAmount; }
public void withdrawFromChecking( int withdrawalAmount) { this .checking = this .checking - withdrawalAmount; this .total = this .total - withdrawalAmount; }
}
savings
Account
0
total 0
Account