UML Diagram to JAVA code [problem 4]

Table of Contents

UML Diagram

Problem4
Problem4

Address class java code

public class Address {
	private String city;
	private String country;

	public Address(String city,String country)
	{
		this.city=city;
		this.country=country;
	}
	public void display()
	{
		System.out.println("City :"+city+"\n"+"Country :"+country);
		
	}
}

Person class java code


public class Person {
	
	protected String name;
	protected String phone;
	Address address;
	public Person(String name,String phone,Address address)
	{
		this.name=name;
		this.phone=phone;
		this.address=address;
	}
	
	public void display()
	{
		System.out.println("\nName :"+name);
		System.out.println("Phone"+phone);
		address.display();
	}

}

PersonMain class java code


public class PersonMain {
	public static void main(String[] args)
	{
		Address ads = new Address("Dhaka","Bangladesh");
		Teacher tr = new Teacher("Rafiqul Islam","017****85",ads,"Professor");
		Student st = new Student("Nurnobi Hosen","01770634816",ads,"183-15-11820",3.25);
		
		tr.display();
		st.display();
	}

}

Student class java code


public class Student extends Person{
	private String studID ;
	private double cgpa;
	
	public Student(String name,String phone,Address address,String studID,double cgpa)
	{
		super(name,phone,address);
		this.studID=studID;
		this.cgpa=cgpa;
	}
	public void display()
	{
		super.display();
		System.out.println("Student ID:"+studID);
		System.out.println("CGPA :" +cgpa);
	}

}

Teacher class java code


public class Teacher extends Person {
	
	private String designation;

	public Teacher(String name,String phone,Address address,String designation)
	{
		super(name,phone,address);
		this.designation=designation;
	}
	public void display()
	{
		super.display();
		System.out.println("Techer Designation :"+designation);
	}
}

output

UML Diagram to JAVA code [problem 4] 1
output