Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Two problems (Dealing with Classes and Objects)

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Two problems (Dealing with Classes and Objects)

    This is a homework question, the project is due tomorrow and my teacher will not respond.

    We are supposed to make an Advisee class (The first code) and then use the Project 5 driver (the second code) to run it.

    I'm having trouble doing two things.
    1. When I run the program it automatically sets the Advisor's name to the default setting.
    2. I can not get the code to catch duplicate Advisee's entered in.

    I know this is confusing and I'm sorry for having to ask for help, but I need to get this project done. I still need to print off all my code... Thank you so much.

     /**************************************************************************************
    * ------------------------------------------------------------------------------------
    * File name: Advisee.java
    * Project name: CSCI 1250 Project 5
    * ------------------------------------------------------------------------------------
    * Author Name: Austin Stanley
    * Author E-mail: stanleyar@goldmail.etsu.edu
    * Course-Section: CSCI-1250-001
    * Creation Date: 11/16/2012
    * Date of Last Modification: 11/16/2012
    * ------------------------------------------------------------------------------------
    */
     
    /**************************************************************************************
    * Class Name: Advisee <br>
    * Class Purpose: The class for our driver program <br>
    *
    * <hr>
    * Date created: 11/16/2102 <br>
    * Date last modified: 11/16/2012
    * @author Austin Stanley
    */
     
    public class Advisee //The beginning of the Advisee class
    {
    	//***********************CLASS ATTRIBUTES******************************************
    	private String studentName; //Establishg the studentName variable
    	private String studentID; //Establishg the studentID variable
    	private String studentConcentration; //Establishg the studentConcentration variable
    	private int studentNumberOfHours; //Establishg the studentNumberOfHours variable
    	private String studentAdvisorName; //Establishg the studentAdvisorName variable
    	private boolean studentMajor; //Establishg the studentMajor variable
    	private boolean studentIntentToGraduate; //Establishg the studentIntentToGraduate variable
     
    	//**********************CLASS METHODS***********************************************
    	//--------------------------CONSTRUCTORS--------------------------------------------
    	/**********************************************************************************
    	* Method Name: Advisee <br>
    	* Method Purpose: It is a no-arg constructor for this class.
    	* 
    	* <br>
    	*
    	* <hr>
    	* Date created: 11/16/2012 <br>
    	* Date last modified: 11/16/2012 <br>
    	*
    	* <hr>
    	* Notes on specifications, special algorithms, and assumptions:
    	* None
    	*
    	* <hr>
    	*/
    	public Advisee() //No Arg Constructor
    	{
    		setStudentName("XXX XXXXX");
    		setStudentID("XXXXXXXX");
    		setStudentConcentration("XX");
    		setStudentNumberOfHours(0);
    		setStudentAdvisorName("XXX XXXXX");
    		setStudentMajor(false);
    		setStudentIntentToGraduate(false);
    	}//end Advisee()
     
    	/**********************************************************************************
    	* Method Name: Advisee <br>
    	* Method Purpose: A constructor accepting a value for all atributes
    	* 
    	* <br>
    	*
    	* <hr>
    	* Date created: 11/16/2012 <br>
    	* Date last modified: 11/16/2012 <br>
    	*
    	* <hr>
    	* Notes on specifications, special algorithms, and assumptions:
    	* None
    	*
    	* <hr>
    	* @param String stuName
    	* @param String stuID
    	* @param String stuConcentration
    	* @param int stuNumberOfHours
    	* @param String stuAdvisorName
    	* @param boolean stuMajor
    	* @param boolean stuIntentToGraduate
    	*/
    	public Advisee(String stuName, String stuID, String stuConcentration, //Constructor that uses ALL attributes
    					int stuNumberOfHours, String stuAdvisorName, boolean stuMajor, boolean stuIntentToGraduate)
    	{
    		setStudentName(stuName);
    		setStudentID(stuID);
    		setStudentConcentration(stuConcentration);
    		setStudentNumberOfHours(stuNumberOfHours);
    		setStudentAdvisorName(stuAdvisorName);
    		setStudentMajor(stuMajor);
    		setStudentIntentToGraduate(stuIntentToGraduate);
    	}//end publc BookOrder constructor with all seven attributes
     
     
    	/**********************************************************************************
    	* Method Name: Advisee(Advisee nextStudent) <br>
    	* Method Purpose: It is a copy constructor for this class.
    	* 
    	* <br>
    	*
    	* <hr>
    	* Date created: 11/19/2012 <br>
    	* Date last modified: 11/19/2012 <br>
    	*
    	* <hr>
    	* Notes on specifications, special algorithms, and assumptions:
    	* None
    	*
    	* <hr>
    	*/
    	public Advisee(Advisee nextStudent) //Copy Constructor. Used for multiple instances 
    	{
    		setStudentName(nextStudent.studentName);
    		setStudentID(nextStudent.studentID);
    		setStudentConcentration(nextStudent.studentConcentration);
    		setStudentNumberOfHours(nextStudent.studentNumberOfHours);
    		setStudentAdvisorName(nextStudent.studentAdvisorName);
    		setStudentMajor(nextStudent.studentMajor);
    		setStudentIntentToGraduate(nextStudent.studentIntentToGraduate);
    	}//end Advisee(Advisee nextStudent)
     
    	//*********************************SETTERS*****************************************
    	/**********************************************************************************
    	* Method Name: setStudentName <br>
    	* Method Purpose: Set the studentName's attribute.
    	* 
    	* <br>
    	*
    	* <hr>
    	* Date created: 11/16/2012 <br>
    	* Date last modified: 11/16/2012 <br>
    	*
    	* <hr>
    	* Notes on specifications, special algorithms, and assumptions:
    	* None
    	*
    	* <hr>
    	* @param String stuName
    	*/
    	public void setStudentName(String stuName) //The setter for studentName
    	{
    		studentName = stuName;
    	}//end setStudentName
     
    	/**********************************************************************************
    	* Method Name: setStudentID <br>
    	* Method Purpose: Set the studentID's attribute.
    	* 
    	* <br>
    	*
    	* <hr>
    	* Date created: 11/16/2012 <br>
    	* Date last modified: 11/16/2012 <br>
    	*
    	* <hr>
    	* Notes on specifications, special algorithms, and assumptions:
    	* None
    	*
    	* <hr>
    	* @param String stuID
    	*/
    	public void setStudentID(String stuID) //Setter for studentID
    	{
    		studentID = stuID;
    	}//end setStudentID
     
    	/**********************************************************************************
    	* Method Name: setStudentConcentration <br>
    	* Method Purpose: Set the studentConcentration's attribute.
    	* 
    	* <br>
    	*
    	* <hr>
    	* Date created: 11/16/2012 <br>
    	* Date last modified: 11/16/2012 <br>
    	*
    	* <hr>
    	* Notes on specifications, special algorithms, and assumptions:
    	* None
    	*
    	* <hr>
    	* @param String stuConcentration
    	*/
    	public void setStudentConcentration(String stuConcentration)		//Setter for studentConcentration
    	{																	//Will accept lower case but stores upper
    		studentConcentration = stuConcentration;
    		if 		(stuConcentration.equalsIgnoreCase("CS"))
    				 studentConcentration = "CS";
    		else if (stuConcentration.equalsIgnoreCase("IS"))
    				 studentConcentration = "IS";
    		else if (stuConcentration.equalsIgnoreCase("IT"))
    				 studentConcentration = "IT";
    		else 
    				 studentConcentration = "XX";							//XX is the default answer
    	}//end setStudentConcentration
     
    	/**********************************************************************************
    	* Method Name: setStudentNumberOfHours<br>
    	* Method Purpose: Set the studentNumberOfHour's attribute.
    	* 
    	* <br>
    	*
    	* <hr>
    	* Date created: 11/16/2012 <br>
    	* Date last modified: 11/16/2012 <br>
    	*
    	* <hr>
    	* Notes on specifications, special algorithms, and assumptions:
    	* None
    	*
    	* <hr>
    	* @param int stuNumberOfHours
    	*/
    	public void setStudentNumberOfHours(int stuNumberOfHours) //Setter for studentNumberOfHours
    	{
    		studentNumberOfHours = stuNumberOfHours;
    	}//end setStudentNumberOfHours
     
    	/**********************************************************************************
    	* Method Name: setStudentAdvisorName <br>
    	* Method Purpose: Set the studentAdvisorName's attribute.
    	* 
    	* <br>
    	*
    	* <hr>
    	* Date created: 11/16/2012 <br>
    	* Date last modified: 11/16/2012 <br>
    	*
    	* <hr>
    	* Notes on specifications, special algorithms, and assumptions:
    	* None
    	*
    	* <hr>
    	* @param String stuAdvisorName
    	*/
    	public void setStudentAdvisorName(String stuAdvisorName) //Setter for studentAdvisorName
    	{
    		studentAdvisorName = stuAdvisorName;
    	}//end setStudentAdvisorName
     
    	/**********************************************************************************
    	* Method Name: setStudentMajor <br>
    	* Method Purpose: Set the studentMajor's attribute.
    	* 
    	* <br>
    	*
    	* <hr>
    	* Date created: 11/16/2012 <br>
    	* Date last modified: 11/16/2012 <br>
    	*
    	* <hr>
    	* Notes on specifications, special algorithms, and assumptions:
    	* None
    	*
    	* <hr>
    	* @param boolean stuAdvisorName
    	*/
    	public void setStudentMajor(boolean stuMajor) //Setter for studentMajor
    	{
    		studentMajor = stuMajor;
    	}//end setStudentMajor
     
    	/**********************************************************************************
    	* Method Name: setStudentIntentToGraduate <br>
    	* Method Purpose: Set the studentID's attribute.
    	* 
    	* <br>
    	*
    	* <hr>
    	* Date created: 11/16/2012 <br>
    	* Date last modified: 11/16/2012 <br>
    	*
    	* <hr>
    	* Notes on specifications, special algorithms, and assumptions:
    	* None
    	*
    	* <hr>
    	* @param boolean stuIntentToGraduate
    	*/
    	public void setStudentIntentToGraduate(boolean stuIntentToGraduate) //Setter for studentIntentToGraduate
    	{
    		studentIntentToGraduate = stuIntentToGraduate;
    	}//end setStudentIntentToGraduate
     
    	//*************************************GETTERS************************************
     
    	/**********************************************************************************
    	* Method Name: getStudentName <br>
    	* Method Purpose: Return the student name.
    	* 
    	* <br>
    	*
    	* <hr>
    	* Date created: 11/17/2012 <br>
    	* Date last modified: 11/17/2012 <br>
    	*
    	* <hr>
    	* Notes on specifications, special algorithms, and assumptions:
    	* None
    	*
    	* <hr>
    	* @return String studentName
    	*/
    	public String getStudentName() //Getter for Student Name
    	{
    		return studentName;
    	}//end getStudentName
     
    	/**********************************************************************************
    	* Method Name: getStudentID <br>
    	* Method Purpose: Return the student ID.
    	* 
    	* <br>
    	*
    	* <hr>
    	* Date created: 11/17/2012 <br>
    	* Date last modified: 11/17/2012 <br>
    	*
    	* <hr>
    	* Notes on specifications, special algorithms, and assumptions:
    	* None
    	*
    	* <hr>
    	* @return String studentID
    	*/
    	public String getStudentID() //Getter for Student ID
    	{
    		return studentID;
    	}//end getStudentID
     
    	/**********************************************************************************
    	* Method Name: getStudentConcentration <br>
    	* Method Purpose: Return the student's concentration.
    	* 
    	* <br>
    	*
    	* <hr>
    	* Date created: 11/17/2012 <br>
    	* Date last modified: 11/17/2012 <br>
    	*
    	* <hr>
    	* Notes on specifications, special algorithms, and assumptions:
    	* None
    	*
    	* <hr>
    	* @return String studentConcentration
    	*/
    	public String getStudentConcentration() //Getter for Student Concentration
    	{
    		return studentConcentration;
    	}//end getStudentConcentration
     
    	/**********************************************************************************
    	* Method Name: getStudentNumberOfHours <br>
    	* Method Purpose: Return the student's numbers of hours.
    	* 
    	* <br>
    	*
    	* <hr>
    	* Date created: 11/17/2012 <br>
    	* Date last modified: 11/17/2012 <br>
    	*
    	* <hr>
    	* Notes on specifications, special algorithms, and assumptions:
    	* None
    	*
    	* <hr>
    	* @return int studentNumberOfHours
    	*/
    	public int getStudentNumberOfHours() //Getter for Student Number Of Hours
    	{
    		return studentNumberOfHours;
    	}//end getStudentNumberOfHours
     
    	/**********************************************************************************
    	* Method Name: getStudentAdvisorName <br>
    	* Method Purpose: Return the student's advisor name.
    	* 
    	* <br>
    	*
    	* <hr>
    	* Date created: 11/17/2012 <br>
    	* Date last modified: 11/17/2012 <br>
    	*
    	* <hr>
    	* Notes on specifications, special algorithms, and assumptions:
    	* None
    	*
    	* <hr>
    	* @return String studentAdvisorName
    	*/
    	public String getStudentAdvisorName() //Getter for Student Advisor Name
    	{
    		return studentAdvisorName;
    	}//end getStudentAdvisorName
     
    	/**********************************************************************************
    	* Method Name: getStudentMajor <br>
    	* Method Purpose: Return the student's major.
    	* 
    	* <br>
    	*
    	* <hr>
    	* Date created: 11/17/2012 <br>
    	* Date last modified: 11/17/2012 <br>
    	*
    	* <hr>
    	* Notes on specifications, special algorithms, and assumptions:
    	* None
    	*
    	* <hr>
    	* @return boolean studentMajor
    	*/
    	public boolean getStudentMajor() //Getter for Student's Major
    	{
    		return studentMajor;
    	}//end getStudentMajor
     
    	/**********************************************************************************
    	* Method Name: getStudentIntentToGraduate <br>
    	* Method Purpose: Return the student's intent to graduate.
    	* 
    	* <br>
    	*
    	* <hr>
    	* Date created: 11/17/2012 <br>
    	* Date last modified: 11/17/2012 <br>
    	*
    	* <hr>
    	* Notes on specifications, special algorithms, and assumptions:
    	* None
    	*
    	* <hr>
    	* @return boolean studentIntentToGraduate
    	*/
    	public boolean getStudentIntentToGraduate() //Getter for Author
    	{
    		return studentIntentToGraduate;
    	}//end getStudentIntentToGraduate
     
    	/**********************************************************************************
    	* Method Name: getClassification <br>
    	* Method Purpose: To get the students grade classification
    	* 
    	* <br>
    	*
    	* <hr>
    	* Date created: 11/1/2012 <br>
    	* Date last modified: 11/1/2012 <br>
    	*
    	* <hr>
    	* Notes on specifications, special algorithms, and assumptions:
    	* •	for an undergraduate: Freshman < 30 hours, Sophomore 30-59 hours, 
    	* Junior 60-89, Senior 90 and up
    	*
    	* <hr>
    	* @return String classification
    	*/
    	public String getClassification()
    	{
    		String classification = " ";			//Comparing number of hours to see what classification the advisee falls in
    		if 		(getStudentNumberOfHours() < 30)
    				classification = "Freshman";
    		else if (getStudentNumberOfHours() >= 30 && (getStudentNumberOfHours() <= 59))
    				classification = "Sophomore";
    		else if (getStudentNumberOfHours() >= 60 && (getStudentNumberOfHours() <= 89))
    				classification = "Junior";
    		else
    				classification = "Senior";
    		return  classification;
    	}//end getClassification
     
    	/**********************************************************************************
    	* Method Name: metGraduationRequirements <br>
    	* Method Purpose: To see if the student has met all requirements
    	* 
    	* <br>
    	*
    	* <hr>
    	* Date created: 11/1/2012 <br>
    	* Date last modified: 11/1/2012 <br>
    	*
    	* <hr>
    	* Notes on specifications, special algorithms, and assumptions:
    	* student must have completed at least 120 credit hours	
    	* student must have filed an intent to graduate
        * student must have filed a major sheet
      	* <hr>
    	* @return boolean requirements
    	*/
    	public boolean metGraduationRequirements()
    	{
    		boolean requirements = false;
    		int credithours = getStudentNumberOfHours();
    		boolean intent = getStudentIntentToGraduate();		//This method takes all requirements needed to graduate
    		boolean major = getStudentMajor();					//and tests them, if all come back true, it is assigned true
    		if(credithours >= 120 && intent == true && major == true) //if one is false it will remain false
    			requirements = true;
    		return requirements;
    	}//end metGraduationRequirements
     
    	/**********************************************************************************
    	* Method Name: clearedToGraduateMsg <br>
    	* Method Purpose: To return a string stating Yes a student has met everything
    	* Or No, and listing all reasons why they have not.
    	* <br>
    	*
    	* <hr>
    	* Date created: 11/17/2012 <br>
    	* Date last modified: 11/17/2012 <br>
    	*
    	* <hr>
    	* Notes on specifications, special algorithms, and assumptions:
    	* not enough hours;
        * not completed major sheet;
        * not filed intent to graduate
    	*
      	* <hr>
    	* @return String cleared
    	*/
    	public String clearedToGraduateMsg()
    	{
    		String cleared = "";		//Created string to be returned
    		String creditError = "";	//Created string to contain the error message
    		String intentError = "";    //It will add more if an error occurs 
    		String majorError = "";
    		int creditHours = getStudentNumberOfHours(); 	//Store the number of hours in an easier to use variable
    		boolean metGrad = metGraduationRequirements();  //Find the true or false of grad requirements
    		boolean credit;									//True or false of enough credit hours
    		boolean intent = getStudentIntentToGraduate(); //True or false of intent
    		boolean major = getStudentMajor(); 				//True or false of major sheet
    		if(creditHours >= 120)
    			credit = true;			//This just compares credit hours to see if it gets a 
    		else 						//true or a false stored into it
    			credit = false;
     
    		if(credit == false)
    			 creditError = " not enough hours;";	//If credit is false we store an error message
    		else creditError = "";						//If credit is true, it gets nothing
     
    		if(intent == false)
    			 intentError = " not filed intent to graduate;";	//The same procedure, if false, stores 
    		else intentError = "";									//an error message, nothing if true
     
    		if(major == false)
    			 majorError = " not completed major sheet;";		//The same procedure, if false, stores
    		else majorError = "";									//an error message, nothing if true
     
    		if(metGrad == false)		//Check graduation requirements, if it was false previously it will catch the errors
    			cleared = ("No -" + creditError + intentError + majorError); //and assign the appropriate error messages
    		else
    			cleared = ("Yes - all requirements have been met"); //If yes, we present the all have been met message
    		return cleared;
    	}//end clearedToGraduateMsg
     
     
    	/**********************************************************************************
    	* Method Name: toString <br>
    	* Method Purpose: A string that designs the output of all information
    	* 
    	* <br>
    	*
    	* <hr>
    	* Date created: 11/19/2012 <br>
    	* Date last modified: 11/19/2012 <br>
    	*
    	* <hr>
    	* Notes on specifications, special algorithms, and assumptions:
    	* Not a display, just a design
        * 
        * 
    	*
      	* <hr>
    	* @return String 
    	*/
    	public String toString() //This will simply organize information to be presented
    	{			
    		return("\n\n Advisee Information"
    			  +"\n\n------------------------------------------"
    			  +"\n\n Name: " + studentName		//calling any variables we need
    			  +"\n ID: " + studentID
    			  +"\n\n\n Advisor: " + studentAdvisorName
    			  +"\n\n\n Concentration: " + studentConcentration
    			  +"\n Completed Hours: " + studentNumberOfHours
    			  +"\n Classification: " + getClassification() //Cant call Classification as it 
    			  +"\n Cleared for graduation: " + clearedToGraduateMsg()); //needs calculations
    	}//end toString
     
    	/**********************************************************************************
    	* Method Name: equals(Advisee student) <br>
    	* Method Purpose: To compare two advisee's and see if they are the same.
    	* 
    	* <br>
    	*
    	* <hr>
    	* Date created: 11/21/2012 <br>
    	* Date last modified: 11/21/2012 <br>
    	*
    	* <hr>
    	* Notes on specifications, special algorithms, and assumptions:
    	*
        * 
        * 
    	*
      	* <hr>
    	* @return boolean
    	*/
    	public boolean equals(Advisee student)
    	{
    		//Default it is false. Next we compare all variables.
    		return(studentName == student.studentName && studentID == student.studentID && studentAdvisorName == student.studentAdvisorName
    		  && studentConcentration == student.studentConcentration && studentNumberOfHours == student.studentNumberOfHours 
    		  && studentMajor == student.studentMajor && studentIntentToGraduate == student.studentIntentToGraduate);
    		  //Returns a boolean, true or false
    	}//end equals(Advisee student)
     
    }//end Advisee

     /*****************************************************************************************
     * ---------------------------------------------------------------------------------------
     * File name: Project5.java
     * Project name: Project 5
     * ---------------------------------------------------------------------------------------
     * Initially created by: Kellie Price
     * Modified by: Austin Stanley stanleyar@goldmail.etsu.edu
     * Course-Section: CSCI 1250
     * Creation Date: 11/16/12
     * Date of Last Modification: 11/16/12
     * ---------------------------------------------------------------------------------------
     */
     
    import javax.swing.JOptionPane;
     
     
    /****************************************************************************************
     * Class Name: Project5 <br>
     * Class Purpose: This class will manage an advisor's advisees (students)  <br>
     * 
     * <hr>
     * Date created: 11/16/12
     * Date last modified: 11/16/12
     * @author Kellie Price & Austin Stanley
     */
     
    public class Project5
    {
    	public static final int LIMIT = 3; //the limit of the number of advisees
     
    	/*************************************************************************************
    	 * Method Name: 	main<br>
    	 * Method Purpose: Displays a menu that will give the user options for managing their
    	 * 				advisees. The program will end when the users selects the Exit 
    	 *                 option from the menu. <br>
    	 * 
    	 * <hr>
    	 * Date created: 11/16/12 <br>
    	 * Date last modified: 11/16/12 <br>
    	 *
    	 * <hr>
    	 * Notes of specifications, special algorithms, and assumptions: 
    	 * 
    	 * <hr>
    	 *	@param args String[] not used in this program
    	 */
     
    	public static void main(String[] args) 
    	{
    		//TO DO: create a student advisee, called defaultAdvisee, with default values
    		Advisee defaultAdvisee = new Advisee();
     
    		//TO DO: create 3 advisee variables to eventually hold advisee objects 
    		//(do not call the constructors yet)
    		Advisee student1;
    		Advisee student2;
    		Advisee student3;
     
    		String studentAdvisorName;		//the advisor's name
    		int adviseeCount = 0; 	//the number of advisees
     
    		int choice = 0; 			//the user's main menu selection
    		int choice2 = 0; 			//the user's sub-menu selection
     
    		//TO DO: create the 3 student advisee objects by calling the copy constructor to 
    		//copy the contents of the defaultAdvisee object
    		student1 = new Advisee(defaultAdvisee);
    		student2 = new Advisee(defaultAdvisee);
    		student3 = new Advisee(defaultAdvisee);
     
     
    		//display a welcome screen with your information
    		JOptionPane.showMessageDialog(null,"           Welcome to the Advising Manager!\n" 
    						+  "--------Created by Kellie Price and Austin Stanley--------");
     
    		//TO DO: Prompt the user (advisor) for their name and store it in the 
    		//defaultAdvisee object
    		defaultAdvisee.setStudentAdvisorName(JOptionPane.showInputDialog("What is the advisor's name?"));
    		System.out.println(defaultAdvisee);
    		//TO DO: display a menu of options and get the user's selection,
    		//the program should continue until the user chooses to exit
    		do{
    			choice = displayMenu();
    			switch(choice)
    			{
    				case 1: //add an advisee
     
    						//TO DO: request the advisee information from the user and store
    						//it in the appropriate advisee object and update the number of 
    						//advisees in the system.  
    						//NOTES: If the advisee added is the same as an advisee previously 
    						//added, that advisee object should be set back to the 
    						//defaultAdvisee object.  If there are already the maximum
    						//number of advisees, a new advisee should not be added.
    						if(adviseeCount == 0)
    						{
    						getAdviseeInfo(student1);				
    						}
     
    						else if(adviseeCount == 1)
    						{
    						getAdviseeInfo(student2);
    							if(student2.equals(student1))
    							{
    							student2 = new Advisee(defaultAdvisee);
    							}
    						}
     
    						else if(adviseeCount == 2)
    						{
    						getAdviseeInfo(student3);
    							if(student3.equals(student1) || student3.equals(student2))
    							{
    								student3 = new Advisee(defaultAdvisee); 
    							}
    						}
     
    						else if(adviseeCount == 3)
    						{
    						JOptionPane.showMessageDialog(null,"You have reached your maximum number of advisees");
    						}
    						++adviseeCount;
    						break;
     
    				case 2: //change an advisees info
     
    						//TO DO: display the subMenu and get the users selection for which
    						//advisee to modify.  The user should be prompted for all new 
    						//advisee information for the appropriate advisee (just like when
    						//the advisee was first created)
    						choice2 = displaySubMenu(student1, student2, student3, adviseeCount);
    						if(choice2 == 1)
    						{
    							getAdviseeInfo(student1);
    							if(student1.equals(student2) == true || student1.equals(student3) == true)
    							{
    								student1 = new Advisee(defaultAdvisee);  
    							}
    						}
     
    						else if(choice2 == 2)
    						{
    							getAdviseeInfo(student2);
    							if(student2.equals(student1) == true || student2.equals(student3) == true)
    							{
    								student2 = new Advisee(defaultAdvisee); 
    							} 
    						}
     
    						else if(choice2 == 3)
    						{
    							getAdviseeInfo(student3);
    							if(student3.equals(student1) == true || student3.equals(student2) == true)
    							{
    								student3 = new Advisee(defaultAdvisee);  
    							}
    						}
     
    						break;
     
    				case 3: //display all advisees information
     
    						//TO DO: call the appropriate method to display all of the 
    						//advisees
    						displayAllAdvisees(student1, student2, student3, adviseeCount);
     
    						break;
    				case 4: //display all advisees that have been cleared to graduate
     
    						//TO DO: call the appropriate method to display all of the 
    						//advisees who have been cleared to graduate
    						displayAdviseesClearedToGraduate(student1, student2, student3);
     
    						break;
    				case 5: //exiting the program, display an EXIT message
     
    						//TO DO: display a message telling the user to "Have a nice day!"
    						JOptionPane.showMessageDialog(null,"Have a nice day!");
     
    						break;
    			}//end switch
    		} while(choice != 5);
    		//exit the program
    		System.exit(0);
    	}//end main
     
    	/*************************************************************************************
    	 * Method Name: 	displayMenu<br>
    	 * Method Purpose: displays a menu of options to the users and returns the users 
    	 *					selection <br>
    	 * 
    	 * <hr>
    	 * Date created: 11/16/12 <br>
    	 * Date last modified: 11/16/12 <br>
    	 *
    	 * <hr>
    	 * Notes of specifications, special algorithms, and assumptions: 
    	 * 
    	 * <hr>
    	 *	@return int the user's menu selection
    	 */
     
    	public static int displayMenu()
    	{	
    		int selection;
    		//build the menu
    		String menu = 	  " ~~ Please make a selection from the menu below ~~ \n\n"
    						+ "    1. Add a new advisee \n" 
    						+ "    2. Update an advisee's information\n\n"
    						+ "    3. Display all advisees \n"
    						+ "    4. Display advisees who are cleared to graduate \n"
    						+ "    5. Exit \n"
    						+ "\n\n What is your selection? ";
     
    		selection = Integer.parseInt(JOptionPane.showInputDialog(menu));
     
    		//TO DO: add the code here to do input validation on selection.  The method should
    		//not end until the user has entered a valid selection.
    		while(selection <= 0 || selection >= 6)
    		{
    			JOptionPane.showMessageDialog(null,"That was not a valid input");
    			selection = Integer.parseInt(JOptionPane.showInputDialog(menu));
    		}
     
    		//return the user's selection (the integer returned by the JOptionPane)
    		return selection; 
    	}//end displayMenu
     
    	/*************************************************************************************
         * Method Name: 	displaySubMenu<br>
    	 * Method Purpose: displays a submenu of options to the users to present the advisees
    	 *                 available for update and returns the users selection <br>
    	 * 
    	 * <hr>
    	 * Date created: 11/16/12 <br>
    	 * Date last modified: 11/16/12 <br>
    	 *
    	 * <hr>
    	 * Notes of specifications, special algorithms, and assumptions: 
    	 * 
    	 * <hr>
    	 * @param student1 the first Advisee object
    	 * @param student2 the second Advisee object
    	 * @param student3 the third Advisee object
    	 * @param adviseeCount the number of Advisees currently in the system
    	 *	@return int the user's submenu selection
    	 */
     
    	public static int displaySubMenu(Advisee student1, Advisee student2,
    									 Advisee student3, int adviseeCount)
    	{	
    		int selection;
    		String menu ="";
     
    		//build the menu
    		if (adviseeCount <= 0)
    		{	JOptionPane.showMessageDialog(null, "There are no advisees in the system yet");
    			selection = 0;
    		}
    		else
    		{
    			menu += " ~~ Please select which advisee's information you need to update ~~ "
    				 +  "\n\n       1. " + student1.getStudentName();
    			if (adviseeCount >= 2)			
    			  menu  += "\n       2. " + student2.getStudentName();
    			if (adviseeCount >= 3)			
    			  menu  += "\n       3. " + student3.getStudentName();
     
    			menu +=    "\n\n What is your selection? ";
     
    			selection = Integer.parseInt(JOptionPane.showInputDialog(menu));
    		}//end else
     
    		//TO DO: add the code here to do input validation on selection.  The method should
    		//not end until the user has entered a valid selection.
    		while(selection <= 0 || selection >=4)
    		{
    			JOptionPane.showMessageDialog(null,"That was not a valid input");
    			selection = Integer.parseInt(JOptionPane.showInputDialog(menu));
    		}
     
    		//return the user's selection (the integer returned by the JOptionPane)
    		return selection;
    	}//end displaySubMenu
     
    	/*************************************************************************************
         * Method Name: 	getAdviseeInfo<br>
    	 * Method Purpose: prompts the user for the information about an advisee and stores
    	 *                 the information in an Advisee object<br>
    	 * 
    	 * <hr>
    	 * Date created: 11/16/12 <br>
    	 * Date last modified: 11/16/12 <br>
    	 *
    	 * <hr>
    	 * Notes of specifications, special algorithms, and assumptions: 
    	 * 
    	 * <hr>
    	 * @param student an Advisee object to be modified
    	 */
     
    	public static void getAdviseeInfo(Advisee student)
    	{
    		int answer; //users answer indicating yes (0) or no (1)
    		boolean majorSheet = false;
    		boolean intentToGraduate = false;
     
    		//request the student information from the user
    		student.setStudentName(JOptionPane.showInputDialog("What is the student's name?"));
     
    		student.setStudentID(JOptionPane.showInputDialog("What is the student's id?"));
     
    		student.setStudentConcentration
    			(JOptionPane.showInputDialog("What is the student's concentration?"));
     
    		student.setStudentNumberOfHours
    			(Integer.parseInt(JOptionPane.showInputDialog("How many hours has the student "
    							 + "completed?")));
     
    		answer = JOptionPane.showConfirmDialog
    					(null,"Has the student completed a major sheet?", 
    					 "Select Yes or No", JOptionPane.YES_NO_OPTION);
    		if (answer == 0) //user selected yes
    			majorSheet = true;
    		student.setStudentMajor(majorSheet);
     
    		answer = JOptionPane.showConfirmDialog
    					(null,"Has the student filed an intent to graduate?", 
    					 "Select Yes or No", JOptionPane.YES_NO_OPTION);
    		if (answer == 0) //user selected yes
    			intentToGraduate = true;
    		student.setStudentIntentToGraduate(intentToGraduate);
     
    	}//end getStudentInfo
     
    	/*************************************************************************************
         * Method Name: 	displayAllAdvisees<br>
    	 * Method Purpose: accepts all advisee objects for display, but only displays the 
    	 * 				current number of advisees in the system<br>
    	 * 
    	 * <hr>
    	 * Date created: 11/16/12 <br>
    	 * Date last modified: 11/16/12 <br>
    	 *
    	 * <hr>
    	 * Notes of specifications, special algorithms, and assumptions: 
    	 * 
    	 * <hr>
    	 * @param student1 the first Advisee object
    	 * @param student2 the second Advisee object
    	 * @param student3 the third Advisee object
    	 * @param adviseeCount the number of Advisees currently in the system
    	 */	
     
    	public static void displayAllAdvisees(Advisee student1, Advisee student2, 
    										  Advisee student3, int adviseeCount)
     
    	{
    		if (adviseeCount == 0)  //if there are no advisees in the system
    			JOptionPane.showMessageDialog(null,"There are no advisees in the system yet");
    		else
    		{
    			if (adviseeCount >= 1) //if there is at least 1 student, display the 1st one
    				JOptionPane.showMessageDialog(null, student1);
    			if (adviseeCount >= 2) //if there are at least 2 students, display the 2nd one
    				JOptionPane.showMessageDialog(null,student2);
    			if (adviseeCount >= 3) //if there are at least 3 students, display the 3rd one
    				JOptionPane.showMessageDialog(null,student3);
    		}//end else
     
    	}//end displayAllAdvisees
     
    	//TO DO: you are to create a method called displayAdviseesClearedToGraduate.  Instead
    	//of displaying all advisees that are in the system, like the method above, it should
    	//only display those advisees in the system that have been cleared to graduate
    	/*************************************************************************************
         * Method Name: displayAdviseesClearedToGraduate<br>
    	 * Method Purpose: Displays all the advisees that are cleared to graduate 
    	 * 				   Must use the adivsee methods<br>
    	 * 
    	 * <hr>
    	 * Date created: 11/16/12 <br>
    	 * Date last modified: 11/16/12 <br>
    	 *
    	 * <hr>
    	 * Notes of specifications, special algorithms, and assumptions: 
    	 * 
    	 * <hr>
    	 * @param student1 the first Advisee object
    	 * @param student2 the second Advisee object
    	 * @param student3 the third Advisee object
    	 * @param adviseeCount the number of Advisees currently in the system
    	 */
    	 public static void displayAdviseesClearedToGraduate(Advisee student1, Advisee student2,
    														Advisee student3)
    		{
    			boolean student1Cleared = student1.metGraduationRequirements();
    			boolean student2Cleared = student2.metGraduationRequirements();
    			boolean student3Cleared = student3.metGraduationRequirements();
    			if(student1Cleared == true)
    			{
    			JOptionPane.showMessageDialog(null,student1);
    			}
     
    			if(student2Cleared == true)
    			{
    			JOptionPane.showMessageDialog(null,student2);
    			}
     
    			if(student3Cleared == true)
    			{
    			JOptionPane.showMessageDialog(null,student3);
    			}
    			if(student1Cleared == false && student2Cleared == false && student3Cleared == false)
    			{
    			JOptionPane.showMessageDialog(null,"There are no advisees ready to graduate");
    			}
    		}//end displayAdviseesClearedToGraduate
     
    }//end Project5
     
    //Questions


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Two problems (Dealing with Classes and Objects)

    When I run the program it automatically sets the Advisor's name to the default setting
    You don't say if that is a problem and what you want the code to do instead.
    Please explain.

    I can not get the code to catch duplicate Advisee's entered in.
    What code in what method is supposed to do that? I don't find the word: "duplicate" in the code. I would expect a comment stating something about catching duplicates.
    Can you post the output from the program that shows what the program does when it is executed?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Nov 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Two problems (Dealing with Classes and Objects)

    1. The program is supposed to ask the user (The Advisor) his/her name. I'm supposed to store that in the defaultAdvisee (Created in the second set of code) But every time the program is ran, it leaves it as "XXX XXXX" (As it is set in the 1st set of code)

    I need the code to keep what ever the user Types in as his or her name

    2. Sorry for the poor wording. In the 1st set of code I have made an "equals" method. I'm supposed to use the equals method in the second set of code to see if any of the students match up. If they do match up, the previous one is to be set back to the defaultAdvisee.

    If that doesn't make sense still. I'm sorry. I may have to just take what I get...

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Two problems (Dealing with Classes and Objects)

    Try debugging the code by adding some printlns to print out the values that are entered and saved in the variable to see where and why the wrong data is being stored in the name?

    You forgot this:
    Can you post the output from the program that shows what the program does when it is executed?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Nov 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Two problems (Dealing with Classes and Objects)

    ...That's so weird. It reads in the right variable then. Why in the world would it not do it in the Joption things?

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Two problems (Dealing with Classes and Objects)

    You need to post some evidence of what the code is doing and explain what is wrong with the program's output.

    For debugging and testing you should read the user's response into a variable, test and display it before passing the value to some other method to process.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Understanding Classes and Objects
    By AustinStanley in forum What's Wrong With My Code?
    Replies: 6
    Last Post: November 9th, 2012, 11:35 AM
  2. Replies: 17
    Last Post: July 27th, 2012, 12:52 AM
  3. Replies: 3
    Last Post: July 8th, 2012, 03:44 PM
  4. Creating classes with generic objects
    By rbt in forum Collections and Generics
    Replies: 2
    Last Post: April 23rd, 2012, 08:08 PM
  5. Replies: 1
    Last Post: April 14th, 2012, 01:45 PM