Hi, I am doing an assignment where I need to get the user to enter m or f in gender and return male.
My assignment criteria requires me to have gender as a char and sex as a char. I get error after error and can't do anything. Not a very good programmer lol.
here is my code:
public class Person { // instance variables protected String name; protected char gender; protected Date dateOfBirth; protected String address; protected String natInsceNo; private static int counter; public static int count() { return counter; } /** * Constructor for objects of class Person */ public Person(String nme, char sex, Date dob, String insceNumber) { // initialise instance variables name = nme; dateOfBirth = dob; gender = sex.charAt(0); natInsceNo = insceNumber; counter = 0; } public Person(Person other) { counter++; } public void getGender(char sex) { if ("m".equalsIgnoreCase(gender)) return "Male"; else if ("f".equalsIgnorecCase(gender)) return "Female"; else return "Unknown Gender"; } public void copy(Person other) { //creates another instance of Person name = other.name; gender = other.gender; dateOfBirth = other.dateOfBirth; natInsceNo = other.natInsceNo; } public boolean equals(Person other) { //returns true if the name and national insurance number are the same as the values in other. return name.equals(other.name) && natInsceNo.equals(other.natInsceNo); } }