Show Menu

The OOP class Cheat Sheet (DRAFT) by

How to code methods and make UI classes

This is a draft cheat sheet. It is a work in progress and is not finished yet.

PUBLIC Static & Constant fields:

Static fields: ( Underl­ined! )
Constant fields: (All CAPS! )
public static int totalQty
public static final int MARKUP = 75;
NB, to call static methods in UI class, you need to say:
"­class name".t­otalQty

How to make the UI class:

String name = JOptio­nPa­ne.s­ho­wIn­put­Dia­log­("Enter the name of the person­");
String ID = JOptio­nPa­ne.s­ho­wIn­put­Dia­log­("Enter the ID number of the person­");

class name fruitObj = new class name✓(name, ID);
NB, When calling up the fields whe instan­tiating the object, MAKE SURE that the field names are the SAME as the constr­uctor in the OOP class!

Access­or/­Typed methods:

public int getSize()
return size;

Mutato­r/void Methods:

public void setSize (int s)
size = s;

Field types:

Private: ( - )
Public: ( + )
Protected: ( # )
private String name
public int age
protected boolean smoke

PRIVATE static fields

private static int totalQty
NB, each private static field needs its own STATIC ACCESSOR method:
public static int getTot­alQty()
return totalQty;
NB, to call private static field in UI class, use the created accessor method:
"­class name".g­etT­ota­lQty()


Default Constr­uctor:
Public "­class name"
size = 2;
Parame­terized Constr­uctor:
Public "­class name"(int s, char p)
size = s;
pattern = p;

The toString method:

public String toString()
return "The total amount is " + amount + "­\n" + " The date is " + day;