public class Operatevector
{
/*
*<br> Method Description: Generate a 4*4 vector for use.
*<br> input Parameters:
*<br> Output variable: Vector
*<br> Other Notes:
*/
public Vector Buildvector () {
vector vtemps = new vector ();
for (int i=0;i<4;i++) {
vector vtemp = new vector ();
for (int j=0;j<4;j++) {
vtemp.addelement ("Vector (" +i+ ") (" +j+ ")");
}
vtemps.addelement (vtemp);
}
return vtemps;
}
/*
*<br> Method Description: Inserting Data
*<br> input parameter: Vector vtemp the data object to be inserted
*<br> input parameter: int itemp where data is inserted
*<br> input parameter: Object otemp Insert data value
*<br> Output variable: Vector results
*<br> Additional Note: If the insertion position exceeds the actual position of the instance, it returns null
*/
public vector Insert (vector vtemp,int itemp,object otemp) {
if (itemp>vtemp.size ()) {
print ("Data hyper-bounds!");
return null;
}else{
Vtemp.insertelementat (otemp,itemp);
}
return vtemp;
}
/*
*<br> Method Description: Removing Data
*<br> input parameters: Vector vtemp object to be deleted
*<br> input parameter: int ITEMP Deletes the location of the data
*<br> Output variable: Vector
*<br> Other Notes: If you delete the data in the bounds, you will return null
*/
Public Vector Delete (Vector vtemp,int itemp) {
if (itemp>vtemp.size ()) {
print ("Data hyper-bounds!");
return null;
}else{
Vtemp.removeelementat (ITEMP);
}
return vtemp;
}
/*
*<br> Method Description: Modifying Data
*<br> input parameters: vector vtemp to be modified
*<br> input Parameters: int ITEMP Modify the location of the data
*<br> input parameter: Object otemp Modify data value
*<br> Output variable: Vector
*<br> Other Note: If you modify the data in the location hyper-bounds, you will return null
*/
public vector updata (vector vtemp,int itemp,object otemp) {
if (itemp>vtemp.size ()) {
print ("Data hyper-bounds!");
return null;
}else{
Vtemp.setelementat (otemp,itemp);
}
return vtemp;
}
/*
*<br> Method Description: Output information
*<br> input parameter: String stemp output Information name
*<br> input parameter: Object otemp output Information value
*<br> return variable: no
*/
public void print (String stemp,vector otemp) {
System.out.println (stemp+ "Data:");
This.print (otemp);
}
/**
*<br> Method Description: Print output (overload)
*<br> input parameter: Object Opara output
*<br> return type: No
*/
public void print (Object Opara) {
System.out.println (Opara);
}
/**
*<br> Method Description: Print output (overload)
*<br> input parameters: vector vpara display output vector objects
*<br> return type: No
*/
public void print (Vector Vpara) {
for (int i=0;i<vpara.size (); i++) {
System.out.println (Vpara.elementat (i));
}
}
/**
*<br> Method Description: Main method, program entry
*<br> input parameters: string[] args
*<br> return type: No
*/
public static void Main (string[] args)
{
Operatevector ov = new Operatevector ();
Vector vtemp = Ov.buildvector ();
ov.print ("VTemp0", vtemp);
Vector vresult = Ov.insert (vtemp,2, "added data");
ov.print ("Vresult", vresult);
Vector vresultup = Ov.updata (vresult,2, "modified data");
ov.print ("Vresultmp", Vresultup);
Vector Vresultnow = Ov.delete (vresultup,2);
ov.print ("Vresultnow", Vresultnow);
}
}