-
Object Array ? Do you Worth it
Is anyone who can solve this problem qwith object array. Those classes related
with the programs are, Video Class, Game Class; theese are extended classes
of Item class. And Library class, Member Class, There is also a class called
interface class but I am not sending it in here. All the other class except
Library class seem to work . Can any one sort the library class as well .
I expecting the reply on the DevGuru page and on my e mail add as well. My
add is ashisharyal@hotmail.com
public abstract class Item
{
public String itemTitle;
public int itemID, memberID;
private static int nextID = 1; // static class variable in Item
public boolean addItemOK;
public Item()//default constructor
{
itemTitle=" ";
itemID=0;
memberID=0;
}
public Item(String title )//specific constructor
{
if(!(title.equals(" ")))
{
itemTitle = title;
setItemID();
memberID = 0;
addItemOK = true;
}
else
addItemOK=false;
}
public void setItemID()
{
if (itemID == 0)
itemID = nextID++;
return;
}
public void setMemberID(int mEMBERiD)
{
memberID=mEMBERiD;
}
public String getItemTitle()
{
return itemTitle;
}
public int getItemID()
{
return itemID;
}
public int getMemberID()
{
return memberID;
}
public boolean AddItemOK()
{
return addItemOK;
}
public String toString()
{
String output= "Title: " + itemTitle+ "\n" + "Item ID: "
+ itemID + "\n" + "Member ID: " + memberID;
return output;
}
}//End Item
//____________________________________________________________________
//_________________________________________________________________
//*****************************************************************
public class Video extends Item
{
private char rating;
private int time;
private boolean ratingOK;
public Video()
{
super();
rating = ' ';
time = 0;
}
public Video(String Utitle,char urate,int utime)
{
super(Utitle);
utime=time;
if ((urate=='M')||(urate=='R')||(urate=='G'))
{
rating=urate;
ratingOK =true;
utime=time;
}
else
{
rating=' ';
ratingOK=false;
}
}
public void SetRating(char urate)
{
if ((urate == 'M')||(urate == 'R')||(urate =='G'))
{
rating = urate;
ratingOK = true;
}
else
{
rating = ' ';
ratingOK = false;
}
}
//////////////////////////////////////////////////////////////////
public int getItemID()
{
return super.getItemID();
}
/////////////////////////////////////////////////////////////////
public String getItemTitle()
{
return super.getItemTitle();
}
//////////////////////////////////////////////////////////////////////
public int getMemberID()
{
return super.getMemberID();
}
//////////////////////////////////////////////////////////////////////
public boolean AddItemOK()
{
return super.AddItemOK();
}
///////////////////////////////////////////////////////////////////////
public boolean getRatingOK()
{
return ratingOK;
}
//////////////////////////////////////////////////////////////////////////
public char getRating()
{
return rating;
}
/////////////////////////////////////////////////////////////////
public int getRuntime()
{
return time;
}
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
public String toString()
{
String output= "Video " + super.toString()+ "\n" + "Rating: "
+ rating + "\n" + "Run Time: " + time;
return output;
}
}//Game
/*__ A constructor to initialise a Video with its title, rating
and running time
*__ A constructor to initialise a Game with its title, platform and
rating
*__ Separate get methods to get Video rating and running time and
Game rating and platform
*__ Separate set methods to set Video rating and running time and
Game rating and platform.
*/
public class Game extends Item
{
public char rating;
public char platform;
public boolean ratingOK,platformOK;
public Game()
{ //default constructor of a new Game
super(); // call superclass constructor
//setItemID(itemNum);
rating = ' ';
platform = ' ';
}
public Game(String Utitle, char urate, char Platform)
{
super(Utitle);
if ((urate == 'M')||(urate == 'R')||(urate =='G'))
{
rating = urate;
ratingOK = true;
}
else
{
rating = ' ';
ratingOK = false;
}
if ((Platform == 'N')||(Platform == 'S')||(Platform == 'P'))
{
platform= Platform;
platformOK = true;
}
else
{
platform = ' ';
platformOK = false;
}
}
public void SetRating(char urate)
{
if ((urate == 'M')||(urate == 'R')||(urate =='G'))
{
rating = urate;
ratingOK = true;
}
else
{
rating = ' ';
ratingOK = false;
}
}
//////////////////////////////////////////////////////////////////
public int getItemID()
{
return super.getItemID();
}
/////////////////////////////////////////////////////////////////
public String getItemTitle()
{
return super.getItemTitle();
}
//////////////////////////////////////////////////////////////////////
public int getMemberID()
{
return super.getMemberID();
}
//////////////////////////////////////////////////////////////////////
public boolean AddItemOk()
{
return super.AddItemOK();
}
///////////////////////////////////////////////////////////////////////
public boolean RatingOK()
{
return ratingOK;
}
//////////////////////////////////////////////////////////////////////////
public char getRating()
{
return rating;
}
public void setPlatform( char Platform)
{
if ((Platform == 'N')||(Platform == 'S')||(Platform == 'P'))
{
platform= Platform;
platformOK = true;
}
else
{
platform = ' ';
platformOK = false;
}
}
/////////////////////////////////////////////////////////////////
public boolean PlatformOK()
{
return platformOK;
}
//////////////////////////////////////////////////////////////
public char getPlatform()
{
return platform;
}
//////////////////////////////////////////////////////////////////////
public String toString()
{
String output= "Game " + super.toString()+ "\n" + "Rating: "
+ rating + "\n" + "Platform: " + platform;
return output;
}
}//Game
//______________________________________________________________
//**************************************************************
//______________________________________________________________
//end Game
/*The state of the member class should include:
memberID (int)
surname
givenName
The behaviour of this class should include (at the very least):
A constructor to initialise a Member with their name and set a
unique memberID * see note below
Separate methods to get memberID, surname and givenName
A toString method which adequately describe a Member
*/
public class member
{
private int memberID;
private int nextID=1;
public String surname;
public String givenName;
private boolean addMemberOK;
public member()//default costructor)
{
surname=" ";
givenName=" ";
memberID=0;
}
public member(String Surname,String Name )
{
if (!(Surname.equals(" ")))
{
givenName=Name;
surname=Surname;
setMemberID();
addMemberOK=true;
}
else
addMemberOK=false;
}
private void setMemberID()
{
if( memberID == 0 )
memberID = nextID++;
}//setMemberID
public boolean addMemberOK()
{
return addMemberOK;
}
public int getmemberID()
{
return memberID;
}
public String getSurName()
{
return surname;
}
public String getGivenName()
{
return givenName;
}
}
And the most IMportant Library Class is here
/*__ a constructor method which creates the collections of Items
*and Members and initializes the numItems variable to zero.
__ A method called addItem that adds and item into the collection
(room permitting). If the action succeeds a status should be sent
to the calling program
*/
public class Library
{
public Item[] Item1 =new Item[10];
public member[] member1=new member[5];
public int index;
public int numItems,nofIt, numMembers;
private boolean addItemOK,addMemberOK,ratingOK,platformOK,borrowOK,returnOK;
public String answer=" ",answer1=" ",output="" ;
public Library()//default constructor
{
for (index=0;index<Item1.length;index++)
{
Item1[index].itemTitle=Item.getItemTitle() ;
Item1[index].itemID=Item.getItemID();
Item1[index].memberID=Item.getMemberID();
}
for (index=0;index<member1.length;index++)
{
member1[index].givenName = member.getGivenName();
member1[index].surname=" ";
}
numItems=0;
numMembers=0;
}
public Library(String family, String name, String title)//specific constructor
{
while(numMembers<member1.length)
{
member1[numMembers+1].surname=family;
member1[numMembers+1].givenName=name;
numMembers++;
addMemberOK=true;
}
while(numItems<Item1.length)
{
Item1[numItems+1].itemTitle=title;
numItems++;
addItemOK=true;
}
}
public boolean addVideo(String title, char urate,int utime)
{
Video video1=new Video(title,urate,utime);
ratingOK=video1.getRatingOK();
if(video1.AddItemOK())
{
for (index=0;index<Item1.length;index++)
{
video1[index].itemTitle=Video.getItemTitle();
video1[index].rating=Video.getRating();
video1[index].time=Video.getRuntime();
video1[index].itemID=Video.getItemID();
numItems++;
}
}
return ratingOK;
}
//_______________________________________________________________
//***************************************************************
//_______________________________________________________________
public boolean addGame(String title,char urate,char Platform)
{
Game game1=new Game(title,urate,Platform);
ratingOK=game1.RatingOK();
platformOK=game1.PlatformOK();
if(game1.AddItemOK())
{
for(index=0;index<Item1.length;index++)
{
game1.itemTitle[index]=Game.getItemTitle();
game1.itemID[index]=Game.getItemID();
game1.rating[index]=Game.getRating();
game1.platform[index]=Game.getPlatform();
numItems++;
}
}
return platformOK;
}
//___________________________________________________________________________
//********************************************************************
//_____________________________________________________________________
public boolean addMember(String family, String name)
{
//member[] member1=new member(name, family)[5];
addMemberOK=member.addmemberOK();
if(addMemberOk)
{
for(index=0;index<member1.length;index++)
{
member1[index].givenName=member.getGivenName();
member1[index].surname=member.getSurName();
numMembers++;
}
}
return addMemberOK;
}
//_____________________________________________________________________
//*****************************************************************
//_____________________________________________________________________
public String findItem(String title)
{
answer="Title "+" "+"Item ID"+" "+"MemberID\n";
for(index=0;index<numItems;index++)
{
if(title.equalsIgnoreCase(Item1[index].itemTitle))
answer+=Item1[index].itemTitle+" "+Item1[index].itemID+"
"+Item1[index].memberID;
}
return answer;
}
public String findMember(String surname)
{
answer="Name"+" "+"Surname"+" "+"MemberID
\n";
for(index=0;index<numMembers;index++)
{
if(surname.equalsIgnoreCase(member1[index].surname))
answer+=member1[index].givenName+" "+member1[index].surname+"
"+member1[index].memberID;
}
return answer;
}
//____________________________________________________________________________
//*********************************************************************
//______________________________________________________________________________
public String getBorrowed()
{ // get Borrowed method
output = "Item Title" + " " + "Item ID" + " " + "Member
ID\n";
for (int index=0; index<Item1.length; index++)
{
if (Item1[index].memberID != 0)
{
output += Item1[index].itemTitle + " " + Item1[index].itemID
+ " " + Item1[index].memberID+"\n";
}
}
}
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
public boolean borrowItem(int memberid, int itemid)
{
for (int index=0; index<numItems; index++)
{
if (itemid == Item1[index].getItemID())
{
if (Item1[index].memberID == 0)
{
Item1[index].memberID = memberid;
borrowOK = true;
answer1 = "Borrow item sucessfully";
break;
}//end if
else
{
borrowOK = false;
answer1 = " Item outs on loans";
break;
}//end else
}//end if
else
{
borrowOK = false;
answer1 = " Item ID not exist ";
}//end else
}//end for
return borrowOK;
}
///////////////////////////////////////////////////////////////////////////////
public boolean returnItem(int itemid)
{ // Return Item method
for (int index=0; index<numItems; index++)
{
if (itemid == Item.getItemID())
{
if(Item1[index].memberID != 0)
{
Item1[index].memberID = 0;
returnOK = true;
borrowOK= false;
answer1 = "Return item sucessfully";
break;
}
else
{
returnOK = false;
answer1 = " This Item not on loans";
break;
}
}
else
{
returnOK = false;
answer1 = " Item ID not exist ";
}
}
return returnOK;
}
//////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////
public String output()
{
return answer1;
}
}
///////////////////////////////////////////////////////////////////////////////
//______________________________________________________________________________
//*************************************************************************
//______________________________________________________________________________
/*
public String getBorrowed()
{
return;
}
public boolean borrowItem()
{
return;
}
public boolean returnItem()
{
return;
}
}
*/
-
Re: Object Array ? Do you Worth it
What 'doesn't work'? I scanned the code and saw multiple issues/problems.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks