Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 960571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:12:08+00:00 2026-05-16T01:12:08+00:00

I am trying to create a new instance of Couple with the given name

  • 0

I am trying to create a new instance of Couple with the given name and gender and add to the collections of couples, in the addCouple method. I have another class called Couple. In that class I have getters and Setters one for name and the gender. I tried to use the bulk operation for the list:

List<Dating> list1 = new ArrayList<Dating>(this.addCouple);

but I got an error “nonstatic variable this cannot be referenced from a static context”. I then tried to use Collection.sort then printout the list. I got the same error message. So I believe I do not know how to use this.addList. Could someone tell me how to use it. Should I be using this.addList? Thanks in advance.

public class Dating
{

  private List<Male> maleList;
  private List<Female> femaleList; 


  public Dating()
  {

    super();
    maleList = new ArrayList<Single>();
    femaleList = new ArrayList<Single>();
  }


  public void lists()
  { 
   this.addList("Jack","Male",'m');
   this.addList("Mike","Male",'m'); 

   this.addList("Lynda","Female",'f'); 
   this.addList("Katie","Female",'f'); 
  }


   public static void addCouple (String aName, char aGender)
   {
      Collections.sort(this.addList);
      for (Couple group : this.addList)
      {
         System.out.println(" " + group.getName() + " " + group.getGender());
      }

   }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T01:12:09+00:00Added an answer on May 16, 2026 at 1:12 am

    I think you have much bigger problems than that. Classes Male, Female, Single? Those are attributes of a Person class, not classes in and of themselves. Your design needs rework.

    You need Person and Couple classes. You also need a model that reflects the real world. Like it or not, you can have Male-Male and Female-Female couples.

    I’d write it like this. As you can see, List works perfectly:

    Gender.java:

    public enum Gender
    {
        MALE, FEMALE;
    }
    

    MaritalStatus.java:

    public enum MaritalStatus
    {
        SINGLE, MARRIED, DIVORCED, WIDOWED, SEPARATED;
    }
    

    Person.java:

    import java.text.DateFormat;
    import java.util.Date;
    
    public class Person
    {
        private String name;
        private Date birthdate;
        private Gender gender;
        private MaritalStatus maritalStatus;
    
        public Person(String name)
        {
            this(name, new Date(), Gender.MALE, MaritalStatus.SINGLE);
        }
    
        public Person(String name, Gender gender)
        {
            this(name, new Date(), gender, MaritalStatus.SINGLE);
        }
    
        public Person(String name, Date birthdate)
        {
            this(name, birthdate, Gender.MALE, MaritalStatus.SINGLE);
        }
    
        public Person(String name, Date birthdate, Gender gender)
        {
            this(name, birthdate, gender, MaritalStatus.SINGLE);
        }
    
        public Person(String name, Date birthdate, Gender gender, MaritalStatus maritalStatus)
        {
            if ((name == null) || (name.trim().length() == 0))
                throw new IllegalArgumentException("name cannot be blank or null");
    
            this.name = name;
            this.birthdate = ((birthdate == null) ? new Date() : new Date(birthdate.getTime()));
            this.gender = gender;
            this.maritalStatus = maritalStatus;
        }
    
        public String getName()
        {
            return name;
        }
    
        public Date getBirthdate()
        {
            return new Date(birthdate.getTime());
        }
    
        public Gender getGender()
        {
            return gender;
        }
    
        public MaritalStatus getMaritalStatus()
        {
            return maritalStatus;
        }
    
        @Override
        public boolean equals(Object o)
        {
            if (this == o)
            {
                return true;
            }
            if (o == null || getClass() != o.getClass())
            {
                return false;
            }
    
            Person person = (Person) o;
    
            if (!birthdate.equals(person.birthdate))
            {
                return false;
            }
            if (gender != person.gender)
            {
                return false;
            }
            if (maritalStatus != person.maritalStatus)
            {
                return false;
            }
            if (!name.equals(person.name))
            {
                return false;
            }
    
            return true;
        }
    
        @Override
        public int hashCode()
        {
            int result = name.hashCode();
            result = 31 * result + birthdate.hashCode();
            result = 31 * result + gender.hashCode();
            result = 31 * result + maritalStatus.hashCode();
            return result;
        }
    
        @Override
        public String toString()
        {
            return "Person{" +
                   "name='" + name + '\'' +
                   ", birthdate=" + DateFormat.getDateInstance(DateFormat.MEDIUM).format(birthdate) +
                   ", gender=" + gender +
                   ", maritalStatus=" + maritalStatus +
                   '}';
        }
    }
    

    Couple.java:

    public class Couple
    {
        private Person ying;
        private Person yang;
    
        public Couple(Person ying, Person yang)
        {
            this.ying = ying;
            this.yang = yang;
        }
    
        public Person getYing()
        {
            return ying;
        }
    
        public Person getYang()
        {
            return yang;
        }
    
        @Override
        public String toString()
        {
            return "Couple{" +
                   "ying=" + ying +
                   ", yang=" + yang +
                   '}';
        }
    }
    

    Dating.java:

    import java.util.ArrayList;
    import java.util.List;
    
    
    public class Dating
    {
        private List<Person> individuals = new ArrayList<Person>();
        private List<Couple> couples     = new ArrayList<Couple>();
    
        public static void main(String[] args)
        {
            Dating dating = new Dating();
    
            dating.addIndividual(new Person("Jack"));
            dating.addIndividual(new Person("Mike"));
            dating.addIndividual(new Person("Lydia", Gender.FEMALE));
            dating.addIndividual(new Person("Kate", Gender.FEMALE));
    
            System.out.println(dating);
        }
    
        public void addIndividual(Person p)
        {
            this.individuals.add(p);
        }
    
        public void removeIndividual(Person p)
        {
            this.individuals.remove(p);
        }
    
        public Person findIndividual(String name)
        {
            Person found = null;
    
            if (name != null)
            {
                for (Person p : this.individuals)
                {
                    if (name.equals(p.getName()))
                    {
                        found = p;
                        break;
                    }
                }
            }
    
            return found;
        }
    
        @Override
        public String toString()
        {
            return "Dating{" +
                   "individuals=" + individuals +
                   ", couples=" + couples +
                   '}';
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have COM object with few constructors, I'm trying to create new instance and
I'm trying to create a new instance of Setting object calling __construct() method with
Given the below code, I'm trying to create a new instance of a Dictionary(Of
I am trying to create a generic class which new's up an instance of
Trying to create a new instance of the MortgageData object. Professor said to use:
I'm trying to create an instance of a trait using this method val inst
I am trying to create a new instance of Excel using VBA using: Set
When trying to create a new JAXB instance inside a servlet I am getting
I'm trying to create a new instance of a custom object inside a for
I'm trying to perform an action periodically. I want to create a new instance

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.