Show Menu
Cheatography

NU CS 2510

Data

Type
Desc­rip­tion
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
Desc­rip­tion
throw new Illega­lAr­gum­ent­Exc­ept­ion­(St­ring);
used to show an error
Integ­er.t­oS­tri­ng(i) and Double.to­Str­ing(i)
takes and int or a double and makes them strings
"St­rin­g".e­qua­ls(­" 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);
  }
}

Help Us Go Positive!

We offset our carbon usage with Ecologi. Click the link below to help us!

We offset our carbon footprint via Ecologi
 

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