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

Assume that you have three classes called Student, Address, Name Student class h

ID: 3606628 • Letter: A

Question

Assume that you have three classes called Student, Address, Name

Student class has the following member variables: int starid, String department

Address class has the following member variables: String street, string city, and int zip

Name class has the following member variable: string fName, char mName, and String lName

3.1 Draw UML class diagram for each of the above classes

3.2 Apply the concept of aggregation and draw class relationship among the above classes

3.3 Add a sub class called GraduateStudent inheriting some features from Student class, draw a class relationship including the newly added subclass.

Explanation / Answer

Name.java

public class Name {
//Declaring instance variables
private String fName;
private char mName;
private String lName;


//Parameterized constructor
public Name(String fName, char mName, String lName) {
super();
this.fName = fName;
this.mName = mName;
this.lName = lName;
}

//getters and setters
public String getfName() {
return fName;
}

public void setfName(String fName) {
this.fName = fName;
}

public char getmName() {
return mName;
}

public void setmName(char mName) {
this.mName = mName;
}

public String getlName() {
return lName;
}

public void setlName(String lName) {
this.lName = lName;
}

//toString method is used to display the contents of an object inside it
@Override
public String toString() {
return "Name=" + fName + "," + mName + " " + lName;
}

}

________________

Address.java

public class Address {
//Declaring instance variables
private String street;
private String city;
private int zip;
//Parameterized constructor
public Address(String street, String city, int zip) {
super();
this.street = street;
this.city = city;
this.zip = zip;
}
//getters and setters
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public int getZip() {
return zip;
}
public void setZip(int zip) {
this.zip = zip;
}
//toString method is used to display the contents of an object inside it
@Override
public String toString() {
return "Street=" + street + ", city=" + city + ", zip=" + zip;
}


}

___________________

Student.java

public class Student {
//Declaring instance variables
private int starid;
private String department;
private Address addrs;
private Name name;
//Parameterized constructor
public Student(int starid, String department, Address addrs, Name name) {
super();
this.starid = starid;
this.department = department;
this.addrs = addrs;
this.name = name;
}

//getters and setters
public int getStarid() {
return starid;
}
public void setStarid(int starid) {
this.starid = starid;
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
public Address getAddrs() {
return addrs;
}
public void setAddrs(Address addrs) {
this.addrs = addrs;
}
public Name getName() {
return name;
}
public void setName(Name name) {
this.name = name;
}

//toString method is used to display the contents of an object inside it
@Override
public String toString() {
return " star id=" + starid + ", department=" + department + ", " + addrs + ", " + name;
}

}

_____________________

GraduateStudent.java

public class GraduateStudent extends Student {
//Declaring instance variables
private String thesisTitle;

//Parameterized constructor
public GraduateStudent(int starid, String department, Address addrs,
Name name, String thesisTitle) {
super(starid, department, addrs, name);
this.thesisTitle = thesisTitle;
}

//getters and setters
public String getThesisTitle() {
return thesisTitle;
}

public void setThesisTitle(String thesisTitle) {
this.thesisTitle = thesisTitle;
}

//toString method is used to display the contents of an object inside it
@Override
public String toString() {
return " Thesis Title=" + thesisTitle + super.toString();
}

}

__________________

Test.java

public class Test {

public static void main(String[] args) {

//Creating an instance of Name class  
Name name = new Name("Sachin", 'R', "Tendulkar");

//Creating an instance of Address class
Address addr = new Address("Bandra", "Mumbai", 56455);

//Creating an instance of GraduateStudent class
GraduateStudent gt = new GraduateStudent(1111, "Computer Science", addr, name, "The Rural Development");

//Displaying the GraduateStudnet class info
System.out.println(gt);
}

}

_____________________

Output:

Thesis Title=The Rural Development star id=1111, department=Computer Science, Street=Bandra, city=Mumbai, zip=56455, Name=Sachin,R Tendulkar

_______________Thank YOU