Question

***Programming language is Java. After looking at this scenario please look over the requirements at the...

***Programming language is Java. After looking at this scenario please look over the requirements at the bottom (in bold) THIS IS ALL THAT WAS PROVIDED. PLEASE SPECIFY ANY QUESTIONS IF THIS IS NOT CLEAR (don't just say more info, be specific)***

GMU in partnership with a local sports camp is offering a swimming camp for ages 10-18. GMU plans to make it a regular event, possibly once a quarter. You have been tasked to create an object-oriented solution to register, enroll and track the participants for the swimming camp classes. Because of limited space a maximum of 60 participants are allowed at a given time. However, it is possible that this number will change in the future based on the success of the camp and availability of additional space.

• Your object-oriented solution should provide participants registration. For each participant, it should capture name, age, sex, cell phone number and email address. Cell phone numbers are only accepted when they are in the format: yyy.yyy.yyyy, such as 703.993.3565.

All email addresses must be validated according to the following rules:

o The characters ‘@’ and ‘.’ must both be in the email address

o Only one ‘@’ is permitted in the email address

o The last occurrence of ‘.’ must follow the ‘@’ in the email address

o There must be at least 2 characters in the email address after the last ‘.’

o The email address must begin with a letter or digit

o The email address must be limited to the following characters: letters, digits, ‘_’, ‘@’, and ‘.’

The training is organized into 4 different swimming strokes and style classes:

1. Freestyle

2. Breaststroke

3. Backstroke

4. Butterfly

Each participant can enroll into any of the 4 classes, however they may only be enrolled in up to three classes at a time. Participants are only permitted to be enrolled into classes after they have been added/registered to the system. The camp is divided into 4 different zones: EAST, WEST, NORTH and SOUTH. All 4 strokes/styles classes are offered in all zones. A participant must enroll for all stroke/style classes at one zone. For example, a participant cannot take Freestyle in WEST zone and Butterfly in NORTH zone. Each swimming stroke class is billed at a rate of $100 per stroke with the exception of Butterfly, which costs $150.

Some participants are sponsored by GMU approved organizations. These participants will get a percentage discount in the total cost paid to enroll. The object-oriented solution you create must allow for the creation of a sponsored participant. Sponsored Participants function in the same way as regular participants, but they must also track the name of the organization and the percentage discount obtained. For example, a sponsored participant enrolled in 2 stroke/style classes (Backstroke and Butterfly) with a 10% discount percentage, will pay $225.00. (($100 + $150) * .10). The percentage discount is different for each organization. Your solution must collect this information during registration

Based on the provided information, create an efficient, object-oriented solution with good design principles that will allow the camp organizer to track all participants being added and enrolling in different swimming classes. To do this, the solution should have a menu with the following capabilities:

• Register: This capability will allow a user to add, but not enroll to any specific swimming class, either as a regular participant or as a sponsored participant. The participant must be of ages 10 to 18. The system will capture the participant’s name, age, sex, cell phone number and email address. Providing all of this information is the only way a participant is added and registered to the system.

• Enroll: This capability will allow a user to select any participant that has been registered, but not enrolled to enroll in different swimming classes based on the rules described above. The application must prevent a participant already enrolled from being enrolled again.

• Remove Enrolled participant: This capability will allow a user to select any enrolled participant and remove them from the solution.

• Print Participant Record: This capability will allow a user to select any participant and print a well-formatted report containing all information about the participant, including the total amount the participant pays for his/her courses, regardless if the participant is a sponsored participant or a regular participant.

• Quit: This capability will allow a user to end working with the solution. It will print a message thanking the user for using the solution.

Other Requirements:

Your solution must use object-oriented techniques, including appropriate constants, constructors, accessors, validating mutators, and special purpose methods, including a toString() method. No points earned for a procedural solution.

• Your solution must contain reasonably appropriate validation. Try to think about what might be considered appropriate as you are designing your solution beyond what has already been explicitly provided.

• Your solution must demonstrate use of arrays

• Your solution must demonstrate the concept of inheritance.

• Your solution must be designed as a modular solution using methods other than main, with each method performing one task.

• Your solution must not import any Java library other than JOptionPane.

• Your solution may not use regular expressions for validation.

Homework Answers

Answer #1

program code to copy

GMUworkshops.java


import javax.swing.JOptionPane;

public class GMUworkshops 
{

        public static void main(String[] args) 
        {
     // constant 
                final int MAX_PARTICIPANTS = 50;
      
      // create array of objects
                participant[] array = new participant[MAX_PARTICIPANTS];
      
            // copied array for linear search and removal of a participant 
                participant[] arrayEdited = array;
     
                int currentSize = participant.getNumParticipants();
     // currentSize of partially filled array
   
          // maintains a menu that allows a user to select from options such as : create flight, remove flight, sell flight ticket, display flights, and exit the program
                int menuChoice = getMenuOption();
                while (menuChoice != 5) 
                {
                        switch(menuChoice) 
                        {
                                case 1: 
                                if (partnered() == false) 
                                {
               // call method to create an object that will become populated with user input
               // method is called register
                  array[currentSize] = register(array, currentSize);
                  currentSize++; 
               // increment
                                } 
                                else 
                                {
               // partnered option
                  array[currentSize] = registerPartnered(array, currentSize);
                  currentSize++;
                                }
               
                                break;    
               
                                case 2:
                           
                                enroll(array, currentSize);
               // given participant list, choose a participant to enroll in classes
                                break;  
               
               
                                case 3:
               // call method to remove a participant by linear search
                                removeParticipant(array, arrayEdited, currentSize);
                                currentSize--;
               // decrement
                                JOptionPane.showMessageDialog(null, "New participant list");
                                printRecord(array, currentSize);
               // print new list
                                break;    
               
                                case 4:
                                printRecord(array, currentSize);
                                break;  // call additional method to print personal information and the cost
            
            default:
               // Program should never reach this condition if logic is correct
               throw new RuntimeException("Unknown error in menu choice");
        }
        menuChoice = getMenuOption();
         // reprompt for the menu options that are maintained 
    }
     
     // exit message
    if (menuChoice == 5) 
        {
        JOptionPane.showMessageDialog(null, "Thank you for using the GMU workshop application.");
    }
}
     
     
//Method purpose : ask the user whether or not the participant is employed by an organization that is partnered with GMU
//Parameter(s) passed : none 
//Return types : boolean
public static boolean partnered() 
{
    String p;
      // loop to make sure that user input is valid according to data definition class validation
        do 
        {
        p = JOptionPane.showInputDialog("Is the participant's organization partnered with GMU? Y or N?");
         // user input for data
         
        if (!p.equalsIgnoreCase("y") && !p.equalsIgnoreCase("n")) 
                {
         //error message
            JOptionPane.showMessageDialog(null, "You must enter Y for yes or N for no.");
         
        }
    } while(!p.equalsIgnoreCase("y") && !p.equalsIgnoreCase("n"));
     
    if (p.equalsIgnoreCase("y")) 
        {
         return true;
    } 
        else 
        {
        return false;
    }
     
}
   
 //Method purpose : find the participant the user wishes to remove from the  list
//Parameter(s) passed : none 
//Return types : void/none 
public static void removeParticipant (participant[] array, participant[] arrayEdited, int currentSize) 
{
    int index = 0;
    boolean found = false;
    printRecord(array, currentSize);
                  // priming read to remove a flight from the flight list 
    int searchValue =   Integer.parseInt(JOptionPane.showInputDialog("Enter participant number"));
      
               // linear search to loop through partially filled array to remove a flight that is in the array, and the parameters for user input to prevent out of bounds error or return of null
    while       (!found && index <=currentSize+1)  
        {
               // parameters to search each index of the partially filled array for flight user wishes to remove
                if      (searchValue > 0 || searchValue <= array.length) 
                {
            found       = true;
        }
        else 
                {         // increment counter to search next index of array
            index++;
        }        
    }
            
            // parameters when course the user wishes to remove is found
    if  (found) 
        {
               // loop to adjust the courses schedule and remove the course the user wishes
         array[(searchValue-1)] = array[currentSize-1];
                     // array copies to print out the adjusted and shortened arrays after the arrays have been shortened
         arrayEdited = array;   
         found = false;
                  // decrement the partially filled array size to the adjusted sized array after a course has been removed   
    }         // error message when the flight a user wishes to remove is not on the list 
    else 
        {
         JOptionPane.showMessageDialog(null,    "Error. Participant not on the list.");
    }
}
     
  // enroll method 
  
public static void enroll(participant[] array, int currentSize) 
{
   
      enrollment(array, currentSize);
      
}   
     
    //Method purpose : ask the user which participant they wish to enroll in classes from a list
//Parameter(s) passed : none 
//Return types : boolean    
public static int enrollment(participant[] array, int currentSize) 
{
    printRecord(array, currentSize);
    int participantChoice = 0;
      
    if (participant.getNumParticipants() > 0) 
        {
        do 
                {
            try 
                        {
               participantChoice = Integer.parseInt(JOptionPane.showInputDialog("Which participant would you like to enroll? "));
            } 
                        catch(NumberFormatException x) 
                        {
               participantChoice = -1;
            }
         
            if (participantChoice < 0 || participantChoice > array.length) 
                        {
               JOptionPane.showMessageDialog(null, "Invalid participant number. Try again.");         
            }
            
        } while(participantChoice < 0 || participantChoice > array.length);
      
      
    }
    
      return participantChoice;
}
     
     
   //Method purpose : to print a receipt of all participant infomration 
//Parameter(s) passed : none 
//Return types : void/none     
public static void printRecord(participant[] arrayEdited, int currentSize) 
{
   
      if (currentSize < 1) 
          {
         JOptionPane.showMessageDialog(null,"There are no participants created.");
      }
      // error message 
      
      
      else {
         String output = "";
         output += "P# | Name | Sex | Age | Cellphone # | Email Address | Total Bill \n";
         for (int x = 0; x < currentSize; x++) {
            output += (x+1) + " . " + arrayEdited[x].toString() + "\n";
         }
         // append the array of objects to a string 
         JOptionPane.showMessageDialog(null, output);
        
      }   
         
      
   }  
      
     
     
  //Method purpose : create a participant for the participant list
//Parameter(s) passed : none 
//Return types : an object    
   public static participant register(participant[] array, int currentSize) {
     
      participant oneParticipant = new participant();
     
     // establish object and now populate their personal info
     
     // aName
      boolean aName;
      // loop to make sure that user input is valid according to data definition class validation
      do {
         aName = oneParticipant.setName(JOptionPane.showInputDialog("Enter the name of the participant : "));
         // user input for data
         
         if (!aName) {
         //error message
            JOptionPane.showMessageDialog(null, "You must enter a name.");         
         }
      } while(!aName);
     
     
     // aSex
      boolean aSex;
      // loop to make sure that user input is valid according to data definition class validation
      do {
         aSex = oneParticipant.setSex(JOptionPane.showInputDialog("Enter the sex of the participant : "));
         // user input for data
         
         if (!aSex) {
         //error message
            JOptionPane.showMessageDialog(null, "You must enter a sex.");         
         }
      } while(!aSex);
     
     
     // aAge
      boolean aAge;
      // loop to make sure that user input is valid according to data definition class validation
      do {
         aAge = oneParticipant.setAge(Integer.parseInt(JOptionPane.showInputDialog("Enter the age of the participant : ")));
         // user input for data
         
         if (!aAge) {
         //error message
            JOptionPane.showMessageDialog(null, "You must enter an age.");         
         }
      } while(!aAge);
   
     
     // aCellphoneNumber
      boolean aCellphoneNumber;
      // loop to make sure that user input is valid according to data definition class validation
      do {
         aCellphoneNumber = oneParticipant.setCellphoneNumber(validateCellphoneNumber());            // user input for data
         
         if (!aCellphoneNumber) {
         //error message
            JOptionPane.showMessageDialog(null, "You must enter a cellphone number.");         
         }
         
      } while(!aCellphoneNumber);
      
      
     // aEmailAddress
      boolean aEmailAddress;
      do {
         aEmailAddress = oneParticipant.setEmailAddress(validateEmailAddress());
         // user input for data
         
         if (!aEmailAddress) {
         //error message
            JOptionPane.showMessageDialog(null, "You must enter an email address.");         
         }
      } while(!aEmailAddress);
     
     // return the object of a participant 
     
      return oneParticipant;
   }
   
   
     //Method purpose : create a participant for the participant list
//Parameter(s) passed : none 
//Return types : an object        
   public static participant registerPartnered(participant[] array, int currentSize) {
     
      partneredParticipant oneParticipant = new partneredParticipant();
     
     // establish object and now populate their personal info
     
     // aName
      boolean aName;
      // loop to make sure that user input is valid according to data definition class validation
      do {
         aName = oneParticipant.setName(JOptionPane.showInputDialog("Enter the name of the participant : "));
         // user input for data
         
         if (!aName) {
         //error message
            JOptionPane.showMessageDialog(null, "You must enter a name.");         
         }
      } while(!aName);
     
     
     // aSex
      boolean aSex;
      // loop to make sure that user input is valid according to data definition class validation
      do {
         aSex = oneParticipant.setSex(JOptionPane.showInputDialog("Enter the sex of the participant : "));
         // user input for data
         
         if (!aSex) {
         //error message
            JOptionPane.showMessageDialog(null, "You must enter a sex.");         
         }
      } while(!aSex);
     
     
     // aAge
      boolean aAge;
      // loop to make sure that user input is valid according to data definition class validation
      do {
         aAge = oneParticipant.setAge(Integer.parseInt(JOptionPane.showInputDialog("Enter the age of the participant : ")));
         // user input for data
         
         if (!aAge) {
         //error message
            JOptionPane.showMessageDialog(null, "You must enter an age.");         
         }
      } while(!aAge);
   
     
     // aCellphoneNumber
      boolean aCellphoneNumber;
      // loop to make sure that user input is valid according to data definition class validation
      do {
         aCellphoneNumber = oneParticipant.setCellphoneNumber(validateCellphoneNumber());            // user input for data
         
         if (!aCellphoneNumber) {
         //error message
            JOptionPane.showMessageDialog(null, "You must enter a cellphone number.");         
         }
         
      } while(!aCellphoneNumber);
      
      
     // aEmailAddress
      boolean aEmailAddress;
      do {
         aEmailAddress = oneParticipant.setEmailAddress(validateEmailAddress());
         // user input for data
         
         if (!aEmailAddress) {
         //error message
            JOptionPane.showMessageDialog(null, "You must enter an email address.");         
         }
      } while(!aEmailAddress);
     
     // return the object of a participant 
     
      return oneParticipant;
   }



     //Method purpose : valid the email address that is prompted in the register method 
//Parameter(s) passed : none 
//Return types : String
   public static String validateEmailAddress() {
   
      String email = JOptionPane.showInputDialog("Enter your email address : ");
      int position1 = email.indexOf('@');
      int position2 = email.indexOf('.');
      int position3 = (email.length()-(position2+1));
      
      boolean validEmailAddress = true;
      
      if ((position1 < 0) || (position2 < 0) || (position2 < position1)) {
         JOptionPane.showMessageDialog(null, "Invalid email address!");
         throw new IllegalArgumentException("A valid email address must be provided");
      } 
      
      return email;
   }


  //Method purpose : valid the cellphone number that is prompted in the register method 
//Parameter(s) passed : none 
//Return types : String
   public static String validateCellphoneNumber() {
   
      String cellphoneNumber = JOptionPane.showInputDialog("Enter your cellphone number with the format XXX.XXX.XXXX");
   
      String cellphoneNumber2 = cellphoneNumber.replace(".", "");
   
      boolean validCellphoneNumber = true;
   
      if (cellphoneNumber2.length() != 10 && cellphoneNumber.length() != 12) {
         validCellphoneNumber = false;
      }
      
      int y = 0;
      while (validCellphoneNumber && (y < cellphoneNumber2.length())) {
      
         if(!Character.isDigit(cellphoneNumber2.charAt(y)) ) {
            validCellphoneNumber = false;
         } else {
            ++y;
         }
      }
      
      if (!validCellphoneNumber) {
         JOptionPane.showMessageDialog(null, "You did not enter a valid cell phone number"); 
         throw new IllegalArgumentException("A valid cellphone number must be provided");
      }
      
      return cellphoneNumber2;
   
   }


       //Method purpose : maintains a menu that allows a user to select from options such as register, enroll, remove enrolled participant, print participant record, and quit the program
//Parameter(s) passed : none 
//Return types : int
   public static int getMenuOption() {
      int menuChoice;
      
      do {
         try {
            menuChoice = Integer.parseInt(JOptionPane.showInputDialog(
               "Enter your selection:" + "\n(1) Register" + "\n(2) Enroll" + "\n(3) Remove Enrolled Participant" + "\n(4) Print Participant Record" + "\n(5) Quit" ));
         }
         catch (NumberFormatException e) {
            menuChoice = 0;
         }
         if (menuChoice < 1 || menuChoice > 5) {
            JOptionPane.showMessageDialog(null, "Invalid choice. Please enter a valid menu option.");
         }
      } while (menuChoice < 1 || menuChoice > 5);
      
      return menuChoice;
   }
   


}

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

participant.java

public class participant {

// instance variable
   private String name;
   // instance variable
   private String sex;
   // instance variable
   private int age;
   // instance variable
   private String cellphoneNumber;
   // instance variable
   private String emailAddress;

   // constant
   public static final int MAX_PARTICIPANTS = 50;
   // static variable number of participants
   public static int numParticipants;


// Method purpose : constructor, set default values for an object
//Parameter(s) passed : none 
//Return types : none
   public participant() {
      this.name = "";
      this.sex = "";
      this.age = 0;
      this.cellphoneNumber = "";
      this.emailAddress = "";
   
      ++numParticipants;
   }

    //Method purpose : accessor, gets the value of name from an object of the class and returns it back to the calling method
//Parameter(s) passed : none 
//Return types : String 
   public String getName() { 
      return this.name; }

    //Method purpose : accessor, gets the value of sex from an object of the class and returns it back to the calling method
//Parameter(s) passed : none 
//Return types : String 
   public String getSex() { 
      return this.sex; }
      
 //Method purpose : accessor, gets the value of age from an object of the class and returns it back to the calling method
//Parameter(s) passed : none 
//Return types : int
   public int getAge() { 
      return this.age; }
      
 //Method purpose : accessor, gets the value of cellphone number from an object of the class and returns it back to the calling method
//Parameter(s) passed : none 
//Return types : String
   public String getCellphoneNumber() { 
      return this.cellphoneNumber; }
      
//Method purpose : accessor, gets the value of email address from an object of the class and returns it back to the calling method
//Parameter(s) passed : none 
//Return types : String
   public String getEmailAddress() { 
      return this.emailAddress; }


 //Method purpose : accessor, gets the value of number of participants from an object of the class and returns it back to the calling method
//Parameter(s) passed : none 
//Return types : int 
   public static int getNumParticipants() { 
      return numParticipants; }
      
        


   //Method purpose : mutator, sets the value of name within an object of the class based on information passed into it
//Parameter(s) passed : String name
//Return types : boolean
   public boolean setName(String name) {
      if (name == null || name.equals("")) {
         
         throw new IllegalArgumentException("A name must be provided");
         // parameters for user input
               // exception handling and error message
      }
      this.name = name;
      return true;
   }
   
   
 //Method purpose : mutator, sets the value of sex within an object of the class based on information passed into it
//Parameter(s) passed : String sex
//Return types : boolean
   public boolean setSex(String sex) {
      if (sex.equalsIgnoreCase("F") || sex.equalsIgnoreCase("M")) {
       
         this.sex = sex;
         return true;
      } else {
         throw new IllegalArgumentException("A name must be provided");
      }
      
   }
    
//Method purpose : mutator, sets the value of age within an object of the class based on information passed into it
//Parameter(s) passed : int age
//Return types : boolean
   public boolean setAge(int age) {
      if (age < 35 || age > 50) {
      
         throw new IllegalArgumentException("Age must be between 35 and 50.");
         // parameters for user input
               // exception handling and error message
      }
      this.age = age;
      return true;
   }
    
//Method purpose : mutator, sets the value of cellphone number within an object of the class based on information passed into it
//Parameter(s) passed : String cellphoneNumber 
//Return types : boolean 
   public boolean setCellphoneNumber(String cellphoneNumber) {
      if (cellphoneNumber == null || cellphoneNumber.equals("")) {
         throw new IllegalArgumentException("A name must be provided");
         // parameters for user input
               // exception handling and error message
      }
      this.cellphoneNumber = cellphoneNumber;
      return true;
   }
    
  //Method purpose : mutator, sets the value of email address within an object of the class based on information passed into it
//Parameter(s) passed : String emailAddress 
//Return types : boolean 
   public boolean setEmailAddress(String emailAddress) {
      if (emailAddress == null || emailAddress.equals("")) {
         throw new IllegalArgumentException("A name must be provided");
         // parameters for user input
               // exception handling and error message
      }
      this.emailAddress = emailAddress;
      return true;
   }
    
    //Method purpose : compute the cost of workshop(s) participants are enrolled in 
//Parameter(s) passed : none
//Return types : double
   public double calculateTotalCost() {
      return 0.0;
   }
   
   //Method purpose : print a receipt of the name, age, sex, cellphone number, email address, bill, and workshop(s) enroll
//Parameter(s) passed : none
//Return types : void/none 
   public String toString() {
   
      return  " | " + this.getName()
            + " | " + this.getSex()
            + " | " + this.getAge()
            + " | " + this.getCellphoneNumber()
            + " | " + this.getEmailAddress()
            //+ "\n" 
            
         
            + " | " + this.calculateTotalCost()
            ;
   
   }

}

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

partneredParticipant.java


public class partneredParticipant extends participant {

// instance variable
   private String organizationName;
   // instance variable
   private double discount;

   // Method purpose : constructor, set default values for an object
//Parameter(s) passed : none 
//Return types : none
   public partneredParticipant() {
      super();
      this.organizationName = "";
      this.discount = 0.0;
   
   }

      //Method purpose : accessor, gets the value of organization name from an object of the class and returns it back to the calling method
//Parameter(s) passed : none 
//Return types : String 
   public String getOrganizationName() { 
      return this.organizationName; }
      
            //Method purpose : accessor, gets the value of the discount from an object of the class and returns it back to the calling method
//Parameter(s) passed : none 
//Return types : double
   public double getDiscount() {
      return this.discount; 
   }
      
         //Method purpose : mutator, sets the value of the organization name within an object of the class based on information passed into it
//Parameter(s) passed : String organizationName
//Return types : boolean 
   public boolean setOrganizationName(String organizationName) {
      if (organizationName == null || organizationName.equals("")) {
         throw new IllegalArgumentException("A organizationName must be provided");
         // parameters for user input
               // exception handling and error message
      }
      this.organizationName = organizationName;
      return true;
   }


   //Method purpose : mutator, sets the value of the discount within an object of the class based on information passed into it
//Parameter(s) passed : double discount
//Return types : boolean
   public boolean setDiscount(double discount) {
      if (discount < 0.0 || discount > 100.0) {
         throw new IllegalArgumentException("A organizationName must be provided");
         // parameters for user input
               // exception handling and error message
      }
      this.discount = discount;
      return true;
   }

       //Method purpose : compute the cost of workshop(s) participants are enrolled in 
//Parameter(s) passed : none
//Return types : double
   public double calculateTotalCost() {
      return 2.0;
      
      // incorporate the dscount array 
   }
   
      public double calculateFakeCost() {
      return 33.0; }
      
      
      //Method purpose : print a receipt of the name, age, sex, cellphone number, email address, bill, and workshop(s) enroll
//Parameter(s) passed : none
//Return types : void/none 
   public String toString() { 
            
      return  " | " + super.getName()
            + " | " + super.getSex()
            + " | " + super.getAge()
            + " | " + super.getCellphoneNumber()
            + " | " + super.getEmailAddress()
            //+ "\n" 
            
            // overriden method? to allow the add on information
            // make separate toString in order to print the other info out as a add on not repeatedly
            // + "\n\nNumber of workshop participants: " + this.getNumParticipants()
            + " | " + this.calculateTotalCost()
            ;
   
   }



}

sample output

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT