Summary of Classes

Java Classes:

  1. System
    1. System.out.println(s) displays the String s on the screen, followed by a newline.

      For example, if x is an int with the value 5, then System.out.println("x = " + x) displays x = 5 on the screen.

    2. System.out.print(s) works just like the println method above except that the trailing newline is not printed.

  2. Math
    1. Math.min(x, y) returns the smaller of the two numbers x and y.

    2. Math.max(x, y) returns the larger of the two numbers x and y.

  3. String
    1. s.length() returns the number of characters in the String s.

      For example, if s is "hot chocolate", then s.length() evaluates to 13.

    2. s.substring(start, end) returns a String consisting of characters from s beginning at index start and ending at index end-1.

      For example, if s is "iced tea", then s.substring(3, 7) evaluates to "d te".

    3. s.equals(t) returns a boolean which is true if the Strings s and t contain exactly the same characters, and false otherwise.

      For example, if s is "orange", then s.equals("orange juice") evaluates to false, but (s + " juice").equals("orange juice") evaluates to true.

      Notice that (s + " juice" == "orange juice") evaluates to false.

    4. s.toLowerCase() returns a String consisting of the same characters as s except that all uppercase characters in s have been converted to their lowercase equivalents.

      For example, if s is "Ice Cream Float!", then s.toLowerCase() evaluates to "ice cream float!".

    5. s.toUpperCase() returns a String consisting of the same characters as s except that all lowercase characters in s have been converted to their uppercase equivalents.

      For example, if s is "MILK shake", then s.toUpperCase() evaluates to "MILK SHAKE".

    6. s.charAt(i) returns the character at position i in the String s.

      For example, if s is "hot chocolate", then s.charAt(0) evaluates to 'h' and s.charAt(4) evaluates to 'c'. To find the last character in a string s, use s.charAt(s.length() - 1).

ccj Classes:

  1. Console
    1. Console.in.readLine() returns the String typed by the user upto the next newline character.

    2. Console.in.readInt() returns the int typed by the user.

    3. Console.in.readDouble() returns the double typed by the user.

    4. Console.in.readWord() returns the String typed by the user upto, but not including, the first whitespace character. (The whitespace characters are blank, tab and newline.) Any leading whitespace is ignored.

  2. Numeric
    1. Numeric.floor(d) returns the int equivalent of the double d. For example, Numeric.floor(4.87) evaluates to 4.

    2. Numeric.round(d) returns the int nearest to the double d. Fractions of .5 will round up. For example, Numeric.round(4.5) and Numeric.round(4.8) both evaluate to 5.

    3. Numeric.randomInt(a, b) returns a randomly selected integer in the range a to b, inclusive, where a and b are both integers. Arguments may be negative and may appear in any order.

      For example, Numeric.randomInt(-3, 7) evaluates to one of the following integers: -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, or 7.

    4. Numeric.randomDouble(a, b) returns a randomly selected double value in the range a to b, inclusive, where a and b are both doubles. Arguments may be negative and may appear in any order.

      For example, Numeric.randomDouble(2.5, 1.2) could evaluate to any of the following (among many others): 2.25, 1.2, 1.23, 2, etc.

  3. Time
    1. new Time() constructs a Time representing the current time according to the system clock.

    2. new Time(y, m, d) constructs a Time with year y (must be greater than or equal to 1970), month m, and day d at 00:00:00.

    3. new Time(y, m, d, h, n, s) constructs a Time with year y (must be greater than or equal to 1970), month m, day d, hours h, minutes n and seconds s.

    4. t.getSeconds() returns the seconds value of the Time t.

    5. t.getMinutes() returns the minutes value of the Time t.

    6. t.getHours() returns the hours value of the Time t.

    7. t.getDay() returns the day value of the Time t.

    8. t.getMonth() returns the month value of the Time t.

    9. t.getYear() returns the year value of the Time t.

    10. t.addSeconds(n) changes the Time t by adding to it the double n number of seconds. This is a mutating function.

    11. t1.secondsFrom(t2) returns the number of seconds between t1 and t2 as a double.

      For example, the following code fragment prints the number of seconds left today.

      Time now = new Time(),
           midnight = new Time(now.getYear(), 
                               now.getMonth(), 
                               now.getDay()+1);
      System.out.println("There are " + midnight.secondsFrom(now) +
                         " seconds left today.");
      

  4. GraphicsApplet
    1. readMouse(s) displays the String s as a prompt and then returns the Point of the user click on the graphics canvas.

    2. readInt(s) displays the String s as a prompt and then returns the int the user types in the text field.

    3. readDouble(s) displays the String s as a prompt and then returns the double the user types in the text field.

    4. setCoord(a, b, c, d) sets the coordinate system for subsequent drawing: (a, b) is the upper left corner and (c, d) is the lower right corner.

    5. setPenColor(c) changes the current pen color to the Color c for subsequent drawing. All future draw commands will display the object in the current pen color. You may change the pen color as many times as you want. The valid colors are: black, blue, cyan, darkGray, gray, green, lightGray, magenta, orange, pink, red, white, yellow.

    6. clear() clears the drawing canvas.

    7. delay(ms) suspends the execution of the applet for ms milliseconds. For example, to suspend for 2 seconds, use delay(2000) and to suspend for a half second, use delay(500).

  5. Point
    1. new Point() constructs a Point at the origin, i.e. with zero x and y coordinates.

    2. new Point(x, y) constructs a Point at location (x, y), where x and y are of type double.

    3. p.getX() returns a double representing the x-coordinate of the Point p. For example, new Point(1, 2).getX() evaluates to 1.

    4. p.getY() returns a double representing the y-coordinate of the Point p. For example, new Point(1, 2).getY() evaluates to 2.

    5. p.move(dx, dy) moves the x-coordinate of the Point p dx units and the y-coordinate of the Point p dy units. This is a mutating function.

      For example, new Point(1, 2).move(3, 9).getX() evaluates to 4.

    6. p.draw() draws the Point p.

  6. Line
    1. new Line(p, q) constructs a Line between the endpoints p and q.

    2. new Line(p, theta, len) constructs a Line starting at the point p, with an angle of theta from the x-axis and of length len. The angle theta is normally a value in the range 0 to 360, inclusive.

      For example, new Line(new Point(), 45, 5) creates a line of length 5 directed from the origin at a 45 degree angle.

    3. l.getStart() returns the starting point of the line l.

    4. l.getEnd() returns the ending point of the line l.

    5. l.getLength() returns the length of the line. For example, new Line(new Point(), 45, 12).getLength() evaluates to 12.0.

    6. l.move(dx, dy) moves each endpoint of the Line l by dx units in the x direction and dy units in the y direction. This is a mutating function.

    7. l.draw() draws the Line l.

  7. Circle
    1. new Circle() constructs a Circle centered at the origin of radius one.

    2. new Circle(p, r) constructs a hollow Circle centered at the Point p of radius r, where r is a double.

    3. new Circle(p, r, "fill") constructs a filled Circle centered at the Point p of radius r, where r is a double.

    4. c.getRadius() returns the radius of the circle c.

    5. c.getCenter() returns the center point of the circle c.

    6. c.move(dx, dy) moves the center of the Circle c by dx units in the x direction and dy units in the y direction. This is a mutating function.

    7. c.draw() draws the Circle c.

  8. Message
    1. new Message(p, s) constructs a Message with starting Point p and text String s.

    2. m.getStart() returns the starting point of the message m.

    3. m.getText() returns the text String in the message m.

    4. m.move(dx, dy) moves the starting Point of the Message m by dx units in the x direction and dy units in the y direction. This is a mutating function.

    5. m.draw() draws the Message m.

    Rectangle

    1. new Rectangle() constructs a Rectangle defined by the points (0,1) and (1,0).

    2. new Rectangle(p, q) constructs a hollow Rectangle defined by the Point p and the Point q, which are assumed to be opposing corner points, in any order, of the rectangle.

    3. new Rectangle(p, q, "fill") constructs a filled Rectangle defined by the Point p and the Point q.

    4. new Rectangle(p, w, h) constructs a hollow Rectangle of width w and height h, whose upper left corner is the Point p. Both w and h are doubles.

    5. new Rectangle(p, w, h, "fill") constructs a filled Rectangle of width w and height h, whose upper left corner is the Point p. Both w and h are doubles.

    6. r.getWidth() returns the width of the rectangle r.

    7. r.getHeight() returns the height of the rectangle r.

    8. r.move(dx, dy) moves the points of the Rectangle r by dx units in the x direction and dy units in the y direction. This is a mutating function.

    9. r.draw() draws the Rectangle r.


Last modified: Wed Feb 10 23:27:29 EST 1999 by asengupt@cs.indiana.edu.