Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 24th, 2004, 01:42 PM
afterburner14 afterburner14 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 4 afterburner14 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
more golf club problems

i'm unable to make my listByYear method loop and print out all the members. what is wrong??
also how do i adjust the 'find' method so that it compares whatever entered to all names that have the
text which is entered. eg. if i search for 'an' it returns me Jane and Danny...and so on.

Member.class

public class Member
{

private String memberName="";
private char memberType;
private double annualFee=0.0;
private int yearJoined=0;



public Member (String inMemberName, char inMemberType, int inYearJoined)
{
memberName=inMemberName;
memberType=inMemberType;
yearJoined=inYearJoined;

}

public String getMemberName()
{

return memberName;

}

public char getMemberType()
{

return memberType;

}

public double getAnnualFee()
{

return annualFee;

}



public int getYearJoined()
{

return yearJoined;

}


public void setMemberName(String inMemberName)
{

memberName=inMemberName;

}

public void setMemberType(char inMemberType)
{
memberType=inMemberType;

if (memberType=='s'||memberType=='S')
{
memberType='s';
annualFee=100;

}

else
{
memberType='p';
annualFee=500;
}



}

public void setYearJoined(int inYearJoined)
{

yearJoined=inYearJoined;

}

public String getMemberTypeString()
{
if (memberType=='s'||memberType=='S')

return ("Social");

else

return ("Playing");

}

public String toString()
{

return memberName + " ("+getMemberTypeString()+" member) joined in " +yearJoined;

}
}


GolfClub.class

public class GolfClub
{
private final int SIZE=10;
private Member[] member;
private int count;


public GolfClub()
{
member= new Member[SIZE];
count=0;
}

public boolean add(Member membr)
{
if (count==SIZE)

return false;

member[count]=membr;
count++;
return true;
}

public String getAll()
{
String msg="Members : \n";
for (int i=0;i<count;i++)

msg+=member[i].toString() + "\n";

return msg;
}

public double total()
{
double sum=0.0;
for (int i=0;i<count;i++)

sum+=member[i].getAnnualFee();

return sum;
}



public String listByClass()
{
int countTypeP=0;
int countTypeS=0;



for (int i=0;i<count;i++)
{
if (member[i].getMemberType()=='p')

countTypeP++;

else
if (member[i].getMemberType()=='s')

countTypeS++;

}
String type="There are "+countTypeP+" playing members.\nThere are "+countTypeS+" social members.";
return type;
}


public String listByYear(int inYear)
{
String yearJoined="Members joined in "+inYear+"\n";

for (int i=0;i<count;i++)
{
if (member[i].getYearJoined()==inYear)

yearJoined+=member[i].getMemberName()+" (" +member[i].getMemberTypeString()+" member)\n";


return yearJoined;
}
return "No member joined in "+inYear+".";
}


public Member find(String memberName)
{

for (int i=0;i<count;i++)

if (member[i].getMemberName().equalsIgnoreCase(memberName))

return member[i];

return null;
}
}



GolfClubClient.java

public class GolfClubClient
{
public static void main(String[]args)
{
Member mem=null;
GolfClub golfclub=new GolfClub();
String name="";
char choice;
char memtype;
int year;

do
{
choice=doMenu();
switch (choice)
{
case '1':

System.out.println();
System.out.print ("Name :");
name=SavitchIn.readLine();
System.out.print ("Member type - <P>Playing <S>Social :");
memtype=SavitchIn.readLineNonwhiteChar();
System.out.print ("Year joined :");
year=SavitchIn.readLineInt();
mem=new Member(name,memtype,year);
mem.setMemberType(memtype);

if(golfclub.add(mem))
{
System.out.println("Addition Success");
System.out.println();
}
else
{
System.out.println("Collection is full");
System.out.println();
}
break;

case '2':

System.out.println();
System.out.println (golfclub.getAll());
System.out.println();
break;

case '3':

System.out.println();
System.out.println (golfclub.total());
System.out.println();
break;

case '4':

System.out.println();
System.out.println(golfclub.listByClass());
System.out.println();
break;

case '5':

System.out.println();
System.out.print("Year joined :");
int yearJoined=SavitchIn.readLineInt();
System.out.println();
System.out.println(golfclub.listByYear(yearJoined) );
System.out.println();
break;

case '6':

System.out.println();
System.out.print ("Name :");
name=SavitchIn.readLine();
mem=golfclub.find(name);
System.out.println();

if (mem!=null)
{
System.out.println (mem.toString());
System.out.println();
}

else
{
System.out.println ("No members whose name contained '"+name+"'");
System.out.println();
}

break;
}
} while (choice!='0');
}


public static char doMenu()
{
System.out.println("Welcome to the Saujana GolfClub System");
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
System.out.println("Please select from the following menu");
System.out.println("1 Register new member");
System.out.println("2 List all the details of members");
System.out.println("3 Print the total annual fee");
System.out.println("4 List a count of members by classification");
System.out.println("5 List all members who joined in a particular year");
System.out.println("6 List all members whose names contain a specific substring");
System.out.println("7 Delete a member from the collection");
System.out.println("8 Change details for a member, given the name");
System.out.println("9 List all details of member sorted in ascending of name");
System.out.println();
System.out.println("0 Exit");
System.out.println();
System.out.print("Your choice? ");
char ch = SavitchIn.readLineNonwhiteChar();
return ch;
}
}

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > more golf club problems


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT