Since Input of ENTITY and of it's attribute is ok
I am trying to op the value of the entity and it's attribute details
so my modified code abt ENTITY is:
package datamodel;
import java.io.*;
import java.util.*;
public class ENTITY{
String entity_name;
int no_of_attribute;
int no_of_entity;
attribute attr1;
public ENTITY(String ename,int nofattr,int nofentity)throws IOException
{
entity_name=ename;
no_of_attribute=nofattr;
no_of_entity=nofentity;
}
attribute[] attr=new attribute[no_of_attribute];
public void setAttributeValues()throws IOException,java.lang.ArrayIndexOutOfBoundsException
{
System.out.println("We are prompting for entering data....");
for(int i=0;i<no_of_attribute;i++)
{
attr[i]=new attribute();
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter the name of the attribute=");
attr[i].name=br.readLine();
System.out.print("Enter the key of the attribute=");
attr[i].key=br.readLine();
System.out.print("Enter the datatype of the attribute=");
attr[i].datatype= br.readLine();
System.out.print("Enter the not_null property (y/n) of the attribute=");
if(br.readLine().equals("Y") || br.readLine().equals("y"))
{
attr[i].not_nul=true;
}
else
{
attr[i].not_nul=false;
}
System.out.print("Enter the default value of the attribute=");
attr[i].default_value=br.readLine();
System.out.print("Enter the check for the attribute=");
attr[i].check=br.readLine();
System.out.print("Enter the uniqueness(y/n) of the attribute=");
if(br.readLine().equals("Y") || br.readLine().equals("Y"))
{
attr[i].unique=true;
}
else
{
attr[i].unique=false;
}
System.out.print("Enter the comment of the attribute=");
attr[i].comment=br.readLine();
System.out.print("Enter the multivalue(y/n) of the attribute=");
if(br.readLine().equals("Y") || br.readLine().equals("Y"))
{
attr[i].multivalue=true;
}
else
{
attr[i].multivalue=false;
}
}
}
public void getAttributeValues(){
for(int i=0;i<no_of_entity;i++){
System.out.println("Name Of Entity="+this.entity_name);
for(int j=0;j<no_of_attribute;j++){
System.out.println("The name of the attribute="+this.attr[i].name);
System.out.println("The key of the attribute="+this.attr[i].key);
System.out.println("The datatype of the attribute="+this.attr[i].datatype);
System.out.println("The not_null property (y/n) of the attribute="+this.attr[i].not_nul);
System.out.println("The default value of the attribute="+this.attr[i].default_value);
System.out.println("The check for the attribute="+this.attr[i].check);
System.out.println("The uniqueness(y/n) of the attribute="+this.attr[i].unique);
System.out.println("The comment of the attribute="+this.attr[i].comment);
System.out.println("The multivalue(y/n) of the attribute="+this.attr[i].multivalue);
}
}
}
}
where bold is function which op the value stored into the entity
to call the function I have written another change in the erd.java (where the main class remains)code:
package datamodel;
import java.io.*;
import java.util.*;
public class erd {
public static void main(String args[])throws IOException{
String ename;
int nofentity;
int nofattr;
System.out.print("Enter no. of entities=");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
nofentity=Integer.parseInt(br.readLine());
ENTITY[] e=new ENTITY[nofentity];
for(int i=0;i<nofentity;i++)
{
System.out.print("Enter name of entity=");
ename=br.readLine();
System.out.print("Enter no. of attributes=");
nofattr=Integer.parseInt(br.readLine());
e[i]=new ENTITY(ename,nofattr,nofentity);
e[i].setAttributeValues();
[B]e[i].getAttributeValues();[/B]
}
}
}
My problem is when I put the line: attribute[] attr=new attribute[no_of_attribute];
inside of the function public void setAttributeValues()
in the class ENTITY a lot of compilation error is detected because getArrtibuteValues()
does not get the array (because the array is local member of the fn setAttributeValues()
) but after omitting the the function setAttributeValues() all input are inputted smoothly. When I put the line attribute[] attr=new attribute[no_of_attribute];
outside any function(as shown in this code) then ArrayIndexOutOfBoundException
shown in line: attr[i].name=br.readLine();
when I input the values of the arribute of the entity. throwing of the exception doesnot result any fruitful
plz suggest me something what modification I should do in our code of ENTITY class to avoid such exception