I need help with my getName method. The error message is invalid method declaration, return type required. And i don't know how to write a method to change the canidate's name. Thank you in advance.

/**
 * Class to create a Candidate object
 * 
 * @author la
 * @version 4/21/07
 */

public class Candidate{

// Add fields
    /**
     * Fields
     * name - Candidate's name, stored in a String
     * party - Candidate's political party, stored in a char
     * as 'r' for Republican, 'd' for Democrat, and 'i' for Independent
     */



// Complete the constructor.    
    /**
     * Constructor
     * 
     * @param anyName - caller inputs Candidate name
     * @param anyParty - caller inputs Candidate's party affiliation
     * stored as a char
     * chars are assigned with single quotes.
     */
    public Candidate(String anyName, char anyParty){
        name = anyName;
        party = anyParty;
    }   

//Complete the three methods and their comments.    
    /**
     * Method to retrieve the Candidate's name for the caller.
     * 
     * @return
     */
    public getName()
    {
        return name;
    }

    /**
     * Method to retrieve the Candidate's party for the caller.
     * 
     * @return
     */

    public char getParty()
    {
        return party;
    }


    /**
     * Method to change the Candidate's party
     * 
     * @param 
     */




}












import java.util.ArrayList;

/**
* These are the fields for the Voting Machine Class.
*/

public class VotingMachine
{
private ArrayList<Candidate> candidateList;

/**
 *  constructor
 */
public VotingMachine()
{
    candidateList = new ArrayList<>();
}

/**
 * This method will store the Candidates for the Candidate List   
 */
public void addNewCandidate(String name, char partySymbol)
{
    Candidate candid = new Candidate(name, partySymbol);
    candidateList.add(candid);
}    

/**
 * This method will display the entire Candidate List.
 */
public void printCandidateInfo()
{
    for (int index=0; index < candidateList.size(); index++)
    {
        System.out.print(candidateList.get(index).getName());
        System.out.println("  " + candidateList.get(index).getParty());
    }
}

/**
 * Method to the number of Candidates in the CandidateList Arraylist.
 */
public int getNumberofFiles()
{
    return candidateList.size();       
}

/**
* Method to select one candidate by first providing an index number.
*/
public void listFile(int index)
{
   System.out.print(candidateList.get(index).getName());
   System.out.println("  " + candidateList.get(index).getParty());
}

/**
 * This method will enable a user to remove a candidate.
 */
public void removeFile(int index)
{
    if(index >= 0 && index < candidateList.size()){
        candidateList.remove(index);
    }
}

public void printCandidateInfo()
{
    for (int index=0; index < candidateList.size(); index++)
    {
        System.out.println(candidateList.get(index));
    }
}

Check line 40. Compare it to line 51.

Wow i'm an idiot.

As for creating a method to set the Candidate's name... You have a constructor that is assigning the 'name' via the 'anyName' param so you already have it. Simply remove the 'party' assignment, remove the 'anyParty' param from the method signature and change the method name to something like 'setName'.

Hope this helps. If so upvote. :-)
-pH

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.