Show Menu
Cheatography

NU CS 2510

Data

Type
Descri­ption
Syntax
Strings
Words
" "
,
Strings
Numbers
Numbers
int
,
double
Boolean
true or false
boolean
,
true
,
false
All of the Syntax column is case sensitive
Inform­ation is data with context

Useful methods and operations

Method
Descri­ption
throw new Illega­lAr­gum­ent­Exc­ept­ion­(St­ring);
used to show an error
Intege­r.t­oSt­ring(i) and Double.to­Str­ing(i)
takes and int or a double and makes them strings
"­Str­ing­".eq­ual­s(" String­")
checks if two strings are equal

Example Template

 /*
   * Fields:
   * this.x, this.y, this.radius
   *
   * Methods:
   * this.sameShape(IShape) -> boolean
   * this.sameCircle(Circle) -> boolean
   *
   * Methods on fields:
   *
   * Fields of parameters:
   *
   * Methods on parameters:
   * that.sameShape(IShape) -> boolean
   */
 

Abstracts and Subclass

// Interface for a Shape
interface IShape {
}
// Abstract of a Shape
abstract class AShape implements IShape {
  String color;
  AShape(String color) {
    this.color = color;
  }
}
// to represent a rectangle
class Rect extends AShape {
  int width;
  int height;
 
  Rect(int width, int height, String color) {
    super(color);
    this.width = width;
    this.height = height;
  }
}
// Subclass square that extends Rectangle
class Square extends Rect {
 
  Square(int size, String color) {
    super(size, size, color);
  }
}
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Data Mining Cheat Sheet
          A-Level Computing Key - Terms & Concepts Cheat Sheet