Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Think of a school social network. only the students of the school are allowed to

ID: 3813757 • Letter: T

Question

Think of a school social network. only the students of the school are allowed to register to this network. Develop the back end of such a network in Java with the following functionalities

(1) A student should be able to register to the network

(2) A registered member can request another to be added as their friend

(3) A registered member can request another to be removed from their friend's list

(4) A registered member can be able to see their friend list

(5) A registered member can search for another student's name in the network. If the student is found registered, the network should provide their relation (e.g., friend's friend's friend, etc.)

Document code. Provide scripts (such as configuration files, etc.) as required for running the program

Note: You don't need to consider using a network, rather just write the program to do the functionalities above

Explanation / Answer

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package schoolsocialnetwork;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
import javax.swing.*;
import javax.swing.JTextField;

/**
*
* @author anandan
*/
public class SchoolSocialNetwork {

//
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Graph schoolNetwork = new Graph();
schoolNetwork.setSchoolName("ModelSchool");
String[] options = new String[] {"Register", "Login", "View Registered Students", "Stop Running"};

//Choose your options of registering, logging in, viewing other students and stop

//if you choose stop running, all the students details will go off - it is a single time use.
while(true){
int response = JOptionPane.showOptionDialog(null, "Message", "Choose your option",
JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE,
null, options, options[0]);
//JOptionPane.showMessageDialog(null, "Selected response: " + response);

//while registering collect the student details like name, class & roll number
if(response == 0){
JTextField name = new JTextField(20);
JTextField form = new JTextField(5);
JTextField rollNo = new JTextField(6);
JPanel myPanel = new JPanel();
myPanel.add(new JLabel("Name:"));
myPanel.add(name);
myPanel.add(Box.createHorizontalStrut(15)); // a spacer
myPanel.add(Box.createVerticalStrut(5));
myPanel.add(new JLabel("Class:"));
myPanel.add(form);
myPanel.add(Box.createHorizontalStrut(15)); // a spacer
myPanel.add(Box.createVerticalStrut(5));
myPanel.add(new JLabel("Roll No.:"));
myPanel.add(rollNo);
  
int result = JOptionPane.showConfirmDialog(null, myPanel,
"Please Enter Student Details", JOptionPane.OK_CANCEL_OPTION);
if (result == JOptionPane.OK_OPTION) {
Student nextStudent = new Student();
nextStudent.name = name.getText();
nextStudent.form = name.getText();
nextStudent.rollNo = name.getText();
schoolNetwork.addStudent(nextStudent);
}
}
  

//Due to time restriction, this part is not completed.

if(response == 1){
JPanel myPanel = new JPanel("View your details");
  
JOptionPane.showConfirmDialog(null, myPanel, "Please choose your option",
JOptionPane.OK_CANCEL_OPTION);
}

//view all the students registering through this
if(response == 2){
List<Vertex> studentDetails = schoolNetwork.getStudents();
String studentNames = "";
Enumeration e = Collections.enumeration(studentDetails);
while(e.hasMoreElements()){
Vertex v = (Vertex) e.nextElement();
Student nextStudent = v.student;
studentNames+= nextStudent.name + ", ";
}
JOptionPane.showMessageDialog(null, "The students are " + studentNames,
"Students registered: ", JOptionPane.PLAIN_MESSAGE);
}
  
if(response == 3){
break;
}
}
}
}

class Student {
public String name;
public String form;
public String rollNo;
}

//Store the students details, their networks in a graph data structure.
class Graph<E> {
private String schoolName;
public void setSchoolName(String schoolname){
this.schoolName = schoolname;
}
private List<Vertex<E>> vertices;

public Graph(){
vertices = new ArrayList();
}
  
void addStudent(Student nextStudent) {
Vertex v = new Vertex(nextStudent);
vertices.add(v);
}
  
void removeStudent(Student nextStudent){
Enumeration e = Collections.enumeration(vertices);
while(e.hasMoreElements()){
Vertex<E> v = (Vertex<E>) e.nextElement();
Student currentStudent = v.getStudent();
if(currentStudent.name.equalsIgnoreCase(nextStudent.name)){
vertices.remove(v);
}
}
}
  
List<Vertex<E>> getStudents(){
return vertices;
}

  
}

class Vertex<E>{
public Student student;
List<Vertex<E>> neighbors;
Vertex(Student s){
this.student = s;
this.neighbors = new ArrayList();
}
public Student getStudent(){
return student;
}
  
public List<Vertex<E>> getNeighbors(){
return neighbors;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote