OOP Mid
OOP Mid
2. Write your name and registration ID on the first page of your Word file.
3. Answer scripts can be uploaded on BlackBoard any time before its deadline.
Therefore, do not wait for the last hour to avoid any unforeseen problems.
5. Use 12 pt. font size and Times New Roman font style along with 1-inch page margins.
6. Follow the requirements of the word limit and the marking criteria while writing your
answers.
7. Provide relevant, original and conceptual answers, as this exam aims to test your ability to
examine, explain, modify or develop concepts discussed in class.
8. Do not copy answers from the internet or other sources. The plagiarism of your answers may
be checked through Turnitin.
9. Recheck your answers before the submission on BlackBoard to correct any content or
language related errors.
10. Double check your word file before uploading it on BlackBoard to ensure that you have
uploaded the correct file with your answers.
Q no. 1 15 Marks
Solution Guidelines:
Create a class Profile having name, emailId, city , country, friendlist[] ( Keep the fields private)
Solutions:
import java.util.*;
class Profile{
private:
String name;
String email_id;
String city;
List<profile> friendlist = new ArrayList<profile>();
String country;
public createProfile(String name , String emailId, String city, String country) {
name = name ;
email_id = emailId;
city = city;
country = country
}
public void addFriends(Profile profile , String Message){
string Message = Message;
//send Message to given profile if it get accepted then we add that profile to friend list
}
public void addFriends(Profile profile){
if(sending_request is accepted){
friendlist.add(profile);
}
public void removeFriend(Profile profile){
for(int i=0;i<this.friendlist.size();i++){
if(this.friendlist[i]==profile){
friendlist.remove(i);
}
}
}
public void showFriends(){
for(int i=0;i<this.friendlist.size();i++){
System.out.println("name :" + this.friendlist[i].name);
}
}
public bool search(Profile profile){
for(int i=0;i<this.friendlist.size();i++){
if(this.friendlist[i]==profile.friendlist[i]){
return true;
}
}
return false;
}
public List<profile> checkMutualFriends(Profile profile){
List<profile> common_friends= new ArrayList<profile>();
for(int i=0;i<this.friendlist.size();i++){
if(this.friendlist[i]==profile.friendlist[i]){
common_friends.add(friendlist[i]);
}
}
return common_friends;
}
}
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
in.close();
}
}
Q no. 2 10 Marks
The pandemic has caused a global suffering. Cooperate sectors, social lifes, and educational
institutes every area is disturbed.
A private Primary School takes the initiative as loss in the studies of students knowing the
importance of Education and decides to upgrade the System. Your Team leader gives you the
responsibility to meet the following requirements of the school.
Create Two Classes:
o Parent o
Teacher
Parent:
Data attributes:
• name
• childName
• childroll_no
• childclass Methods:
Teacher:
Data attributes:
• name
• class_number
• array of assignments
• array of quizes Methods:
• Teacher can upload, assignments and quizzes.
• Can upload Students home – assignments score
Implement code for the above scenario using Object Oriented Programing pillars.
CODE:
//main.java
package Chegg47;
import java.io.FileNotFoundException;
import java.util.*;
public class main {
public static void main(String[] args) {
ArrayList<Teacher> teachers = new ArrayList<Teacher>();
ArrayList<Parent> parents = new ArrayList<Parent>();
for(Parent p:parents) {
System.out.println("\n\n-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\nPARENT NAME:
"+p.getName());
p.viewCampusNews();
p.viewAssignments(teachers);
p.viewQuizes(teachers);
p.viewHomeAssignmentScore();
}
}
}