Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JAVA help You are to design a Java application to manage your contact informatio

ID: 3541033 • Letter: J

Question

JAVA help

You are to design a Java application to manage your contact information. Each contact may have the following data: name addresses e-mails phones group Each contact may have multiple addresses, e-mails and phones, and may belong to a group. One of them is designated as the primary. The following operations are required on the contact information: add delete update search (by name/phone/e-mail/group) All the data must be saved in an XML file and kept updated. Generate an exception for any input error.

Explanation / Answer

#include<iostream>

#include<exception>

using namespace std;

int main()

{

int size,*s,i;

cout<<" USING ARRAY OF BOUNDS";

cout<<" Enter the size of an array:";

cin>>size;

try

{

s=new int [size];

if(!s)

throw(size);

else

{

cout<<" Enter the elements:";

for(i=0;i<size;i++)

{

cin>>s[i];

}

cout<<" The elements you entered are:";

for(i=0;i<size;i++)

{

cout<<" The element number-"<<i<<":"<<s[i];

}

}

}

catch(int size)

{

cout<<" the size you entered is:"<<size<<"which cannot be created:-)";

}

return 0;

}

you are using command line arguments, two things will create this exception


first one, java always throws a array out of bound exception whenever array is used inside a loop, that is , dynamic indexing will create the exception myArray[i], so throw the exception manually ,



second one, you are not providing enough command line arguments, there are three command line arguments , so while executing program from console you have to provide three number separated by space after the program name.


ex: java command 3 12 34


so 3 will be in ar[0] , 12 in ar[1] and 34 in ar[2]

just let us know you are following same format or not

=======================================