|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
unable to display method properly
how do i display the total annual fee from the driver program?
i know something is missing from the Member class, but not sure what exactly please help. here is the 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; } } |
|
#2
|
|||
|
|||
|
here is the GolfClub.class (not complete yet, just testing some of the functions first)
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 getAllMembers() { String msg="There are "; return msg; } } |
|
#3
|
|||
|
|||
|
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); 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; } } 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; } } |
![]() |
| Viewing: Dev Articles Community Forums > Programming > Java Development > unable to display method properly |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|