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

  • Home
  • SEARCH
  • 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 6740629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:37:44+00:00 2026-05-26T11:37:44+00:00

I’ve been given a task to implement a graph in java. It will eventually

  • 0

I’ve been given a task to implement a graph in java. It will eventually be used to test search methods (breadth first, depth first and iterative deepening). The three classes to be made have to implement three corresponding interfaces:

public interface Node {
    public Node createNode(String name, int ID, float weight);
    public Node[] getNeighbours();
    public Edge[] getEdges();
    public void addEdge(Edge e);
    public void removeEdge(Edge e);
    public String getName();
    public int getID();
    public float getWeight();
    public String toString();

public interface Edge {
    public Edge createEdge(String name, int ID, float weight);
    public Node getStartNode();
    public void setStartNode(Node n);
    public Node getEndNode();
    public void setEndNode(Node n);
    public String getName();
    public int getID();
    public float getWeight();
    public String toString();

public interface Graph {
    public Graph createGraph(String name, int ID, Node[] nodes, Edge[] edges, Node root);
    public String getName();
    public Edge[] getEdges();
    public void addEdge(Edge e);
    public Edge getEdge(String name, int ID);
    public void removeEdge(Edge e);
    public Node[] getNodes();
    public void addNode(Node n);
    public Node getNode(String name, int ID);
    public void removeNode(Node n);
    public void setRoot(Node n);
    public Node getRoot();  
    public boolean isTree();        <= optional!
    public String toString();

The main method will be in the graph class.

I’m a bit confused as to why there is create methods for each class rather than constructors.

Also can anyone advise on whether I should store edges using an adjacency matrix or an adjancency list?

Any and all help will be greatly appreciated.

Thanks

  • 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-26T11:37:44+00:00Added an answer on May 26, 2026 at 11:37 am

    I’m with you on questioning the wisdom of placing create methods in the interface. Methods in an interface have to be implemented as instance methods in the implementing classes, and normally methods like this, when they are used in place of constructors, are class methods, namely static factory methods, which cannot appear in interfaces.

    The only reason to have a creation method in a Java interface is if one is doing cloning, which does not appear to be the case here. When you implement these interfaces the creation methods will call your constructor (which you are free to implement any way you want), but these methods are kind of silly because, as instance methods, you will need to have existing objects on which to call them.

    As for your second question, the choice of adjacency matrix, adjacency list, or incidence list is totally up to you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm making a simple page using Google Maps API 3. My first. One marker
I have thousands of HTML files to process using Groovy/Java and I need to
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.