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 6883523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:23:38+00:00 2026-05-27T05:23:38+00:00

I have the following 2 sets in my driver class. How do I attach

  • 0

I have the following 2 sets in my driver class. How do I attach a student to a module? For example, I need jane on module ufce1 and ufce2 and alex on ufce2 only.

Student jane = new Student("jane");
Student alex = new Student("alex");

Set<Student> students = new HashSet<Object>();
students.add(jane);
students.add(alex);

Module ufce1 = new Module("UFCE1");
Module ufce2 = new Module("UFCE2");

Set<Module> modules = new HashSet<Object>();
modules.add(ufce1);
modules.add(ufce2);

Modules class:

public class Module {
    private String name;

    public Module(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    @Override
    public String toString() {
        return name; 
    }
}

Student Class:

public class Student {
    private String name;


    public Student(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    @Override
    public String toString() {
        return name;
    }
}

I tried using arrayLists but these result in duplication i.e. if a user tries adding a student onto a module they are already enrolled onto.

    Module m1 = new Module("m1", "Java");
    Module m2 = new Module("m2", "Software Design");
    Module m3 = new Module("m3", "PHP");
    Module m4 = new Module("m4", "MySQL");
    Module m5 = new Module("m5", "XML");

    ArrayList<Module> modules = new ArrayList<Module>();
    modules.add(m5);
    modules.add(m4);
    modules.add(m3);
    modules.add(m2);
    modules.add(m1);

    jane.addModule(m1);
    jane.addModule(m3);
    alex.addModule(m1);
    alex.addModule(m2);

    m1.addStudent(jane);
    m3.addStudent(jane);
    m1.addStudent(alex);
    m2.addStudent(alex);
  • 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-27T05:23:39+00:00Added an answer on May 27, 2026 at 5:23 am

    I assume Module is a class written by you.

    if so you can have an Set in the Module class and also add addStudent() method in it.

    public class Module{
        private Set<Student> students = new HashSet<Student>();
        public void addStudent(Student student){
              students.add(student);
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following sets of models (abbreviated for clarity): First set: class Web(Link):
I have the following code that sets a cookie: string locale = ((DropDownList)this.LoginUser.FindControl(locale)).SelectedValue; HttpCookie
I have written a KornShell (ksh) script that sets an array the following way:
I have a table with sets of settings for users, it has the following
I have the following set of sets. I don't know ahead of time how
I have the following code in my codebehind Page_Load function that sets the default
I am using the jquery datatable plugin. I have the following code that sets
I have the following problem: Suppose I have some basic counter class Counter .
I have the following: sets = DataSet.all.group_by{ |data| [data.project_id, -, data.thread_id].join( ) } <%
I have the following code: // button sets var sets = ['.diamond-colour','.diamond-cut','.diamond-clarity','.diamond-certificate']; // for

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.