Web & Social Media Analytics Previous Year Question Paper.pdf
@author public class Person{ String sname, .pdf
1. /**
* @author
*
*/
public class Person
{
String sname, iname;
int fid, sid;
}
/**
* @author
*
*/
public class Student extends Person
{
String sname;
int sid;
int no_of_credits, tot_grade_pts;
/**
* @param sname
* @param sid
*/
public Student(String sname, int sid)
{
this.sname = sname;
this.sid = sid;
}
/**
* @return
*/
public String get_name()
{
return sname;
}
public int get_sid()
2. {
return sid;
}
public boolean two_equal(int sid)
{
if ((this.sid) == sid)
return true;
else
return false;
}
public void set_credits(int credits)
{
no_of_credits = credits;
}
public int get_credits()
{
return no_of_credits;
}
public void set_tot_gpts(int gpts)
{
tot_grade_pts = gpts;
}
public int get_tgpts()
{
return tot_grade_pts;
}
public float get_GPA()
{
return ((tot_grade_pts) / (no_of_credits));
}
}
/**
* @author
*
*/
public class Instructor extends Person
4. int creg_code, max_students, no_of_students;
ArrayList reg_students = new ArrayList();
/**
* @param cname
* @param creg_code
* @param max_students
*/
Course(String cname, int creg_code, int max_students)
{
this.cname = cname;
this.creg_code = creg_code;
this.max_students = max_students;
}
/**
* @param instructor_name
*/
void set_instructor(String instructor_name)
{
this.instructor_name = instructor_name;
}
/**
* method to search student id
*
* @param sid
* @return
*/
public boolean search_student(int sid)
{
if (reg_students.contains(sid))
return true;
else
return false;
}
/**
* method to add student id
*
5. * @param sid
*/
public void add_student(int sid)
{
try {
if ((reg_students.size()) == max_students)
{
throw new MyException();
}
else
reg_students.add(sid);
}
catch (Exception e)
{
System.out.println("Course has maximum students");
}
}
/**
* method to remove student id
*
* @param sid
*/
public void rem_student(int sid)
{
try {
if (reg_students.contains(sid))
reg_students.remove(new Integer(sid));
else
throw new MyException();
} catch (Exception e)
{
System.out.println("NO STUDENT FOUND WITH THE GIVEN id");
}
}
}
/**
6. * @author
*
*/
public class MyException extends Exception
{
public MyException() {
// TODO Auto-generated constructor stub
super(" Invalid Data");
}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Registrar
{
/**
* @param args
* @throws NumberFormatException
* @throws IOException
*/
public static void main(String args[]) throws NumberFormatException,
IOException
{
Course c1 = new Course("default_course", 123, 10);
int ch, regcode, max_stu, sid;
String cname, sname;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
do {
System.out
.println(" 1. create a course 2. add a student 3. remove a student 4. exit");
System.out.print("Enter your choice: ");
ch = Integer.parseInt(br.readLine());
switch (ch)
{
case 1:
System.out.print("Enter course name:");
7. cname = br.readLine();
System.out.print("Eter registration code :");
regcode = Integer.parseInt(br.readLine());
System.out.print("Enter max students :");
max_stu = Integer.parseInt(br.readLine());
Course c = new Course(cname, regcode, max_stu);
break;
case 2:
System.out.print("Enter student name: ");
sname = br.readLine();
System.out.print("Enter id : ");
sid = Integer.parseInt(br.readLine());
c1.add_student(sid);
break;
case 3:
System.out.print("Enter student id: ");
sid = Integer.parseInt(br.readLine());
c1.rem_student(sid);
break;
}
} while (ch != 4);
}
}
OUTPUT:
1. create a course
2. add a student
3. remove a student
4. exit
Enter your choice: 1
Enter course name:computers
Eter registration code :1211
Enter max students :30
1. create a course
2. add a student
3. remove a student
4. exit
8. Enter your choice: 2
Enter student name: srinivas
Enter id : 1
1. create a course
2. add a student
3. remove a student
4. exit
Enter your choice: 2
Enter student name: rajesh
Enter id : 2
1. create a course
2. add a student
3. remove a student
4. exit
Enter your choice: 3
Enter student id: 1
1. create a course
2. add a student
3. remove a student
4. exit
Enter your choice: 4
NOTE:
DONT HAVE TIME TO IMPLEMENT SERIALIZATION THINGS
Solution
/**
* @author
*
*/
public class Person
{
String sname, iname;
int fid, sid;
}
/**
9. * @author
*
*/
public class Student extends Person
{
String sname;
int sid;
int no_of_credits, tot_grade_pts;
/**
* @param sname
* @param sid
*/
public Student(String sname, int sid)
{
this.sname = sname;
this.sid = sid;
}
/**
* @return
*/
public String get_name()
{
return sname;
}
public int get_sid()
{
return sid;
}
public boolean two_equal(int sid)
{
if ((this.sid) == sid)
return true;
else
return false;
}
public void set_credits(int credits)
10. {
no_of_credits = credits;
}
public int get_credits()
{
return no_of_credits;
}
public void set_tot_gpts(int gpts)
{
tot_grade_pts = gpts;
}
public int get_tgpts()
{
return tot_grade_pts;
}
public float get_GPA()
{
return ((tot_grade_pts) / (no_of_credits));
}
}
/**
* @author
*
*/
public class Instructor extends Person
{
String iname;
int fid;
String dept;
/**
* @param iname
* @param fid
*/
public Instructor(String iname, int fid)
{
this.iname = iname;
12. this.max_students = max_students;
}
/**
* @param instructor_name
*/
void set_instructor(String instructor_name)
{
this.instructor_name = instructor_name;
}
/**
* method to search student id
*
* @param sid
* @return
*/
public boolean search_student(int sid)
{
if (reg_students.contains(sid))
return true;
else
return false;
}
/**
* method to add student id
*
* @param sid
*/
public void add_student(int sid)
{
try {
if ((reg_students.size()) == max_students)
{
throw new MyException();
}
else
reg_students.add(sid);
13. }
catch (Exception e)
{
System.out.println("Course has maximum students");
}
}
/**
* method to remove student id
*
* @param sid
*/
public void rem_student(int sid)
{
try {
if (reg_students.contains(sid))
reg_students.remove(new Integer(sid));
else
throw new MyException();
} catch (Exception e)
{
System.out.println("NO STUDENT FOUND WITH THE GIVEN id");
}
}
}
/**
* @author
*
*/
public class MyException extends Exception
{
public MyException() {
// TODO Auto-generated constructor stub
super(" Invalid Data");
}
}
import java.io.BufferedReader;
14. import java.io.IOException;
import java.io.InputStreamReader;
public class Registrar
{
/**
* @param args
* @throws NumberFormatException
* @throws IOException
*/
public static void main(String args[]) throws NumberFormatException,
IOException
{
Course c1 = new Course("default_course", 123, 10);
int ch, regcode, max_stu, sid;
String cname, sname;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
do {
System.out
.println(" 1. create a course 2. add a student 3. remove a student 4. exit");
System.out.print("Enter your choice: ");
ch = Integer.parseInt(br.readLine());
switch (ch)
{
case 1:
System.out.print("Enter course name:");
cname = br.readLine();
System.out.print("Eter registration code :");
regcode = Integer.parseInt(br.readLine());
System.out.print("Enter max students :");
max_stu = Integer.parseInt(br.readLine());
Course c = new Course(cname, regcode, max_stu);
break;
case 2:
System.out.print("Enter student name: ");
sname = br.readLine();
System.out.print("Enter id : ");
15. sid = Integer.parseInt(br.readLine());
c1.add_student(sid);
break;
case 3:
System.out.print("Enter student id: ");
sid = Integer.parseInt(br.readLine());
c1.rem_student(sid);
break;
}
} while (ch != 4);
}
}
OUTPUT:
1. create a course
2. add a student
3. remove a student
4. exit
Enter your choice: 1
Enter course name:computers
Eter registration code :1211
Enter max students :30
1. create a course
2. add a student
3. remove a student
4. exit
Enter your choice: 2
Enter student name: srinivas
Enter id : 1
1. create a course
2. add a student
3. remove a student
4. exit
Enter your choice: 2
Enter student name: rajesh
Enter id : 2
1. create a course
16. 2. add a student
3. remove a student
4. exit
Enter your choice: 3
Enter student id: 1
1. create a course
2. add a student
3. remove a student
4. exit
Enter your choice: 4
NOTE:
DONT HAVE TIME TO IMPLEMENT SERIALIZATION THINGS