0% found this document useful (0 votes)
27 views10 pages

OOP Solutions: Student & Advisor Classes

Uploaded by

Hossam Bakr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views10 pages

OOP Solutions: Student & Advisor Classes

Uploaded by

Hossam Bakr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Lap 5 oop solution

OCTOBER 17, 2024


Experiment 1: Student Class UML Diagram

Challenge : class diagram for the Book class

Experiment 2 : java code for advisor class


package studentinformation;

public class StudentInformation {

public static class Student {


// Private attributes
private int studentID;
private String studentName;
private float studentGPA;

// Constructor
public Student(int studentID, String studentName, float studentGPA) {
[Link] = studentID;
[Link] = studentName;
[Link] = studentGPA;
}

// Overriding the toString() method to display student details


@Override
public String toString() {
return "ID: " + studentID + "\n"
+ "Name: " + studentName + "\n"
+ "GPA: " + studentGPA + "\n";
}
}

public static class Advisor {


// Private attributes
private int advisorID;
private String advisorName;
private String advisorDept;

// Constructor
public Advisor(int advisorID, String advisorName, String advisorDept) {
[Link] = advisorID;
[Link] = advisorName;
[Link] = advisorDept;
}

// Overriding the toString() method to display advisor details


@Override
public String toString() {
return "ID: " + advisorID + "\n"
+ "Name: " + advisorName + "\n"
+ "Department: " + advisorDept + "\n";
}
}

public static void main(String[] args) {


// Creating Student objects
Student student1 = new Student(101, "Ahmed", 4.5f);
Student student2 = new Student(102, "Fatima", 4.7f);

// Creating Advisor objects


Advisor advisor1 = new Advisor(11, "Maytham", "Computer Science");
Advisor advisor2 = new Advisor(21, "Sara", "Information Systems");

// Printing student information


[Link]("Students Information:");
[Link]("----------------------");
[Link]([Link]());
[Link]("----------------------");
[Link]([Link]());
[Link]("----------------------");

// Printing advisor information


[Link]("Advisors Information:");
[Link]("----------------------");
[Link]([Link]());
[Link]("----------------------");
[Link]([Link]());
}
}

Screenshot for the output :


Challenge 2 : Code for StudentInformation class

package studentinformation;

public class StudentInformation {

public static class Student {


private int studentID;
private String studentName;
private float studentGPA;

// Constructor
public Student(int studentID, String studentName, float studentGPA) {
[Link] = studentID;
[Link] = studentName;
[Link] = studentGPA;
}

// Using [Link]() in toString method


@Override
public String toString() {
return [Link]("ID: %d\nName: %s\nGPA: %.1f\n", studentID,
studentName, studentGPA);
}
}

public static class Advisor {


private int advisorID;
private String advisorName;
private String advisorDept;

// Constructor
public Advisor(int advisorID, String advisorName, String advisorDept) {
[Link] = advisorID;
[Link] = advisorName;
[Link] = advisorDept;
}

// Using [Link]() in toString method


@Override
public String toString() {
return [Link]("ID: %d\nName: %s\nDepartment: %s\n", advisorID,
advisorName, advisorDept);
}
}
public static void main(String[] args) {
Student student1 = new Student(101, "Ahmed", 4.5f);
Student student2 = new Student(102, "Fatima", 4.7f);

Advisor advisor1 = new Advisor(11, "Maytham", "Computer Science");


Advisor advisor2 = new Advisor(21, "Sara", "Information Systems");

// Printing student information


[Link]("Students Information:");
[Link]("----------------------");
[Link](student1);
[Link]("----------------------");
[Link](student2);
[Link]("----------------------");

// Printing advisor information


[Link]("Advisors Information:");
[Link]("----------------------");
[Link](advisor1);
[Link]("----------------------");
[Link](advisor2);
}
}
Screenshot for the output :

Experiment 3 : drawing the association between classes


Challenge 3 : UML Diagram for Donor class

public class Donor {


// Private attributes
private int donorID;
private String donorName;
private int birthYear;
private String bloodGroup;
// Constructor
public Donor(int donorID, String donorName, int birthYear, String bloodGroup) {
[Link] = donorID;
[Link] = donorName;
[Link] = birthYear;
[Link] = bloodGroup;
}

// Setters
public void setDonorID(int donorID) {
[Link] = donorID;
}

public void setDonorName(String donorName) {


[Link] = donorName;
}

public void setBirthYear(int birthYear) {


[Link] = birthYear;
}

public void setBloodGroup(String bloodGroup) {


[Link] = bloodGroup;
}

// Getters
public int getDonorID() {
return donorID;
}

public String getDonorName() {


return donorName;
}

public int getBirthYear() {


return birthYear;
}

public String getBloodGroup() {


return bloodGroup;
}

// Overriding the toString() method to display donor details


@Override
public String toString() {
return [Link]("Donor ID: %d\nName: %s\nBirth Year: %d\nBlood Group:
%s",
donorID, donorName, birthYear, bloodGroup);
}
public static void main(String[] args) {
// Create a Donor object
Donor donor1 = new Donor(1001, "John Doe", 1985, "O+");

// Print the donor information


[Link](donor1);
}
}

You might also like