Vector method

xiaoxiao2021-03-06  73

Use the setElement method like a new reference (or can understand member). For example: a terminal containing a lot of boat, I hope to join a new ship to the terminal, this class: Dock // Dock.java

Package com.tianyu.summer;

Import java.util. *;

Public Class Dock

{

Private int ID;

PRIVATE STRING LOCATION;

PRIVATE BOOLEAN ELECTRICITY

Private Boolean Water;

PRIVATOR SLIPS;

Public Dock (int ANID, STRING Alocation, Boolean AneElectricity, Boolean Awater)

{

SetID (anid);

SetLocation (alocation);

SETELECTRICITY (AneElectricity);

Setwater (awater);

}

Public Void AddSliptodock (Slip aslip)

{

Slips.addelement (aslip); // Connect Dock to Slip (1 ... *)

}

Public Vector getSlips ()

{RETURN SLIPS;

Public void setid (int ANID)

{id = anid;}

Public void setLocation (String Alocation)

{location = alocation;

Public void setElectricity (Boolean AneElectricity)

{electricity;

Public void setwater (Boolean Awater)

{Water = awater;}

Public int getID ()

{RETURN ID;}

Public string getLocation ()

{Return Location;

Public Boolean getElectricity ()

{Return Electricity;

Public boolean getwater ()

{RETURN Water;}

}

Vector.size () uses how many members have included in the VECTOR, return INT

Vector.ementat (i) Return the i-th element, the return type is Object, you must use forced conversion

转载请注明原文地址:https://www.9cbs.com/read-109144.html

New Post(0)