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

JAVA Every social group today has a way to connect with like-minded individuals

ID: 3707433 • Letter: J

Question

JAVA

Every social group today has a way to connect with like-minded individuals (e.g. FarmersOnly.com). You've been tasked with understanding and designing an application that can track Computer Science students and their interests. This app will be used to find other students with similar interests for study sessions. All of the Classes » All of the Attributes . All of the Operations . All of the Relationships (inheritance, realization, association, dependency) Functional Requirements Below, you will find the requirements for the product. Not all of these requirements will be evident in the high-level design! In your design, you are capturing the major concepts, attributes and relationships 1. The user should be presented with a menu of the following activities: a. Load the Members b. Save the Members C. List All Members d. Add a Member e. Remove a Member f. List Member g. Add an Interest to a Member h. Quit 2. Each Member includes a name, and year (1-5) a. A freshman is a 1, sophomore 2, etc. A CS student with a degree is a 5 3. Each Interest includes a topic (e.g. "Assembly Language", "Java", "Digital Design", "Cyber Security", "Web Design", "C++", etc.) and an interest level, from 0-10 (least to most) a. There is no predefined list of Topics, the user can enter anything they want 4. 5. 6. Each Member may have any number of Interests (including none). When adding a new Member, make sure their name is unique When saving the Members, ask the user for a filename. If the file cannot be written, tell the user and ask for another name a. Its ok to overwrite an existing file. No warning is necessary When loading the Members, ask the user for a filename. If the file cannot be read, tell the user and ask for another name When adding an Interest to a Member, if the Interest already exists, replace the Interest with the new one 7. 8.

Explanation / Answer

Programing:

package example;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
public class example{

private Scanner sc=new Scanner(System.in);

public void addMember(String name, int year ){
//JDBC driver name and database URL
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://localhost/STUDENTS";
// Database credentials
static final String USER = "username";
static final String PASS = "password";
public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
try{ //STEP 2: Register JDBC driver
Class.forName("com.mysql.jdbc.Driver");
//STEP 3: Open a connection
System.out.println("Connecting to a selected database...");
conn = DriverManager.getConnection(DB_URL, USER, PASS);
System.out.println("Connected database successfully...");
//STEP 4: Execute a query
System.out.println("Creating statement...");
stmt = conn.createStatement();
String sql = "insert into member(name, year) values (name, year);
stmt.executeUpdate(sql);

  
}

public void deleteMember(String name, int year ){
//JDBC driver name and database URL
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://localhost/STUDENTS";
// Database credentials
static final String USER = "username";
static final String PASS = "password";
public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
try{ //STEP 2: Register JDBC driver
Class.forName("com.mysql.jdbc.Driver");
//STEP 3: Open a connection
System.out.println("Connecting to a selected database...");
conn = DriverManager.getConnection(DB_URL, USER, PASS);
System.out.println("Connected database successfully...");
//STEP 4: Execute a query
System.out.println("Creating statement...");
stmt = conn.createStatement();
String sql = "delete member where name="+name+" and year="+year+");
stmt.executeUpdate(sql);

}

public void updateMember(String name, String interest){
//JDBC driver name and database URL
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://localhost/STUDENTS";
// Database credentials
static final String USER = "username";
static final String PASS = "password";
public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
try{ //STEP 2: Register JDBC driver
Class.forName("com.mysql.jdbc.Driver");
//STEP 3: Open a connection
System.out.println("Connecting to a selected database...");
conn = DriverManager.getConnection(DB_URL, USER, PASS);
System.out.println("Connected database successfully...");
//STEP 4: Execute a query
System.out.println("Creating statement...");
stmt = conn.createStatement();
String sql = "update member set interest ="+interest+"where name="+name+");
stmt.executeUpdate(sql);

  
}

public static void main(String[] args) {

Scanner sc=new Scanner(System.in);
  
  
  
System.out.println("Please select the operation 1.Add member 2.Remove member 3.Add interest to a member");

example e = new example ();
while(sc.nextInt()==1){
System.out.println ("Please enter name of the member");
String name= sc. next();
System.out.println ("Please enter year of the member");
int year=sc. nextInt();
e.addMember(name,year);
System.out.println("Member "+name+" added successfully. Want to add one more member press 1. To quit press 0") ;
}System.out.println("Please select the operation 1.Add member 2.Remove member 3.Add interest to a member");


while(sc.nextInt()==2){
System.out.println ("Please enter name of the member");
String name= sc. next();
System.out.println ("Please enter year of the member");
int year=sc. nextInt();
e.deleteMember(name,year);
System.out.println("Member "+name+" a
Deleted successfully. Want to delete one more member press 2. To quit press 0") ;
}System.out.println("Please select the operation 1.Add member 2.Remove member 3.Add interest to a member");

while(sc.nextInt()==3){
System.out.println ("Please enter name of the member");
String name= sc. next();
System.out.println ("Please enter number of interests");
for(int i=0;i<=sc.nextInt();i++)
System.out.println ("Please enter interests with ; separated (ex:java;sql)");
String interest=sc. next();
  
e.updateMember(name,interest);
System.out.println("Member "+name+" a
with interest "+interest +" added successfully. Want to update interest more member press 3. To quit press 0") ;
}System.out.println("Please select the operation 1.Add member 2.Remove member 3.Add interest to a member");}}