Array

Use array to store, update, seach pets using methods and constructors

Page 1 of 1

3 Replies - 729 Views - Last Post: 29 March 2009 - 08:29 PM Rate Topic: -----

#1 shimaf  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 26-March 09

Array

Post icon  Posted 26 March 2009 - 05:35 AM

Create a java program for a collection of pets. You need to define your own pet members.
You are required to write the class, declare the members, write the constructors, and methods of it.

This part requires you to make use of array to store the above information.
Add more features to the program in Part A with the following specifications:

i. The program can display individual pet or all pets information.
ii. The program can store all pets information in an array.
iii. The program can search for a particular pet detail.
iv. The program can update the available pet information.
v. Any two features that you can use to manipulate the pet information.



someone should pls help me out with the program, though i have done some part but unable to display, search,
and store pets information using constructors and methods.

you can reach me threeplex90@yahoo.com

Attached File(s)


This post has been edited by shimaf: 26 March 2009 - 05:38 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Array

#2 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: Array

Posted 26 March 2009 - 05:40 AM

Welcome!

Please post your code attempting to implement your assignment.

Don't forget to use the code tags:

:code:

[rules][/rules]
Was This Post Helpful? 0
  • +
  • -

#3 shimaf  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 26-March 09

Re: Array

Posted 26 March 2009 - 06:43 AM

[quote name='n8wxs' date='26 Mar, 2009 - 04:40 AM' post='586062']
Welcome!

Please post your code attempting to implement your assignment.

Don't forget to use the code tags:

:code:

[rules][/rules]

Quote

import javax.swing.*;
class petsinfo
{
public static void main(String args[])
{
int select = 0;//for main menu option
String newid=" ";
String newname=" ";
String newtype=" ";
String newcolor=" ";
int newage=0;
int newheight=0;
double newweight=0.00;
int more=0;//for counter //change

cop info[ ] = new cop[40]; //array to store pet's info.
while(select != 5) //exit options in main menu.//start manin menu 5 option here....
{
select=Integer.parseInt(JOptionPane.showInputDialog
(null,"[1] Add Your Pets Informations: \n [2]. Display Your Pet's Information: \n[3]. Search Your Pet's Information: \n [4]. Update Your Pet's Information: \n [5].) Exit From The System:"));
if(select==1 )//change select
{

newid=JOptionPane.showInputDialog(null,"Please Enter Your Pet's ID");
newname=JOptionPane.showInputDialog(null,"Please Enter Your Pet's Name");
newtype=JOptionPane.showInputDialog(null,"Please Enter Your Pet's Type");
newcolor=JOptionPane.showInputDialog(null,"Please Enter Your Pet's Color");
newage=Integer.parseInt(JOptionPane.showInputDialog(null,"Please Enter Your Pet's Age"));
newheight=Integer.parseInt(JOptionPane.showInputDialog(null,"Please Enter Your Pet's Height"));
newweight=Double.parseDouble(JOptionPane.showInputDialog(null,"PleaseEnter Your Pet's Weight"));
info[more]= new cop(newid,newname,newtype,newcolor,newage,newheight,newweight);
more++;
}
else
if(select == 2) //Display Pet's info:
{
for(int x=0; x < more; x ++)
{
JOptionPane.showMessageDialog(null,
"\n Your Pet's id is :"+info[x].id+
"\n Your Pet's name is :"+info[x].name+
"\n Your Pet's type is :"+info[x].type+
"\n Your Pet's color is :"+info[x].color+
"\n Your Pet's age is :"+info[x].age+
"\n Your Pet's height is :"+info[x].height+"cm"+
"\n Your Pet's weight is :"+info[x].weight+"kg");

}
}

else
if(select == 3)//Search Pet's Info:
{
String petid=JOptionPane.showInputDialog(null,"Please Enter Your Pet's ID");
for(int x=0; x < more; x ++)
{
if(info[x].id.equals(petid))
{

JOptionPane.showMessageDialog(null,
"\nYour Pet's ID is: " + info[x].id+
"\n Your Pet's Name is: "+info[x].name+
"\n Your Pet's Type is: "+info[x].type+
"\n Your Pet's color is:"+info[x].color+
"\n Your Pet's Age is: " + info[x].age+
"\n Your Pet's Height is: "+info[x].height+"cm"+
"\n Your Pet's Weight is: "+info[x].weight+"kg");

}
}
}

else
if(select == 4)//Update Pet's Info
{
String petid=JOptionPane.showInputDialog(null,"Please Enter Your pet's ID");
for(int x=0; x < more; x ++)
{
if(info[x].id.equals(petid))
{

newid=JOptionPane.showInputDialog(null,"Please Re-Enter Your Pet's ID");
newname=JOptionPane.showInputDialog(null,"Please Re-Enter Your Pet's Name");
newtype=JOptionPane.showInputDialog(null,"Please Re-Enter Your Pet's Type");
newcolor=JOptionPane.showInputDialog(null,"Please Re-Enter Your Pet's Color");
newage=Integer.parseInt(JOptionPane.showInputDialog(null,"Please Re-Enter Your Pet's Age"));
newheight=Integer.parseInt(JOptionPane.showInputDialog(null,"Please Re-Enter Your Pet's Height"));
newweight=Double.parseDouble(JOptionPane.showInputDialog(null,"Please Re-Enter Your Pet's Weight"));

info[more]= new cop(newid,newname,newtype,newcolor,newage,newheight,newweight);
more++;
}
}
}
}
}
}


The problem i cannot make use of constructor to make the program display, update and search.

Need help pls on how to make that work, whenever i run the program it displays error message.

This post has been edited by shimaf: 26 March 2009 - 06:52 AM

Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8346
  • View blog
  • Posts: 31,904
  • Joined: 06-March 08

Re: Array

Posted 29 March 2009 - 08:29 PM

It is not [ quote] and [ /quote]
but [ code] and [ /code]
:code:
go back and edit your post to correct your posting
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1