[POO] aula06 ex1 added
This commit is contained in:
parent
cdcd19114f
commit
5d47ce98fb
|
@ -0,0 +1,43 @@
|
|||
package aula06;
|
||||
|
||||
import utils.DateYMD;
|
||||
|
||||
public class Bolser extends Student{
|
||||
private Professor supervisor;
|
||||
private double monthlyAmount;
|
||||
|
||||
public Bolser(String name, int cc, DateYMD birthDate, DateYMD registrationDate, Professor supervisor, double monthlyAmount) {
|
||||
super(name, cc, birthDate, registrationDate);
|
||||
this.setSupervisor(supervisor);
|
||||
this.setMonthlyAmount(monthlyAmount);
|
||||
}
|
||||
|
||||
public Bolser(String name, int cc, DateYMD birthDate, Professor supervisor, double monthlyAmount) {
|
||||
this(name, cc, birthDate, null, supervisor, monthlyAmount);
|
||||
}
|
||||
|
||||
public Professor getSupervisor() {
|
||||
return this.supervisor;
|
||||
}
|
||||
public void setSupervisor(Professor supervisor) {
|
||||
if (supervisor == null) {
|
||||
throw new IllegalArgumentException("Supervisor cannot be null");
|
||||
}
|
||||
this.supervisor = supervisor;
|
||||
}
|
||||
|
||||
public double getMonthlyAmount() {
|
||||
return this.monthlyAmount;
|
||||
}
|
||||
public void setMonthlyAmount(double monthlyAmount) {
|
||||
if (monthlyAmount < 0) {
|
||||
throw new IllegalArgumentException("Monthly amount cannot be negative");
|
||||
}
|
||||
this.monthlyAmount = monthlyAmount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%s; CC: %d; Date de nascimento: %s; Data de matrícula: %s; NMec: %d; Supervisor: %s; Montante mensal: %.2f", this.getName(), this.getCc(), this.getBirthDate(), this.getRegistrationDate(), this.getNMec(), this.supervisor, this.monthlyAmount);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
package aula06;
|
||||
|
||||
import utils.DateYMD;
|
||||
|
||||
public class Person {
|
||||
private String name;
|
||||
private int cc;
|
||||
private DateYMD birthDate;
|
||||
|
||||
public Person(String name, int cc, DateYMD birthDate) {
|
||||
this.setName(name);
|
||||
this.setCc(cc);
|
||||
this.setBirthDate(birthDate);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
if (name == null || name.isEmpty()) {
|
||||
throw new IllegalArgumentException("Name cannot be null or empty");
|
||||
}
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getCc() {
|
||||
return this.cc;
|
||||
}
|
||||
public void setCc(int cc) {
|
||||
this.cc = cc;
|
||||
}
|
||||
|
||||
public DateYMD getBirthDate() {
|
||||
return this.birthDate;
|
||||
}
|
||||
public void setBirthDate(DateYMD birthDate) {
|
||||
if (birthDate == null) {
|
||||
throw new IllegalArgumentException("Birth date cannot be null");
|
||||
}
|
||||
this.birthDate = birthDate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%s; CC: %d; Date de nascimento: %s", this.name, this.cc, this.birthDate);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package aula06;
|
||||
|
||||
import java.util.Scanner;
|
||||
import utils.DateYMD;
|
||||
|
||||
public class PersonTest {
|
||||
public static void main(String[] args) {
|
||||
Scanner sin = new Scanner(System.in);
|
||||
|
||||
Student al = new Student ("Andreia Melo", 9855678,new DateYMD(18, 7, 1990), new DateYMD(1, 9, 2018));
|
||||
Professor p1 = new Professor("Jorge Almeida", 3467225, new DateYMD(13, 3, 1967), "Associado", "Informática");
|
||||
Bolser bls = new Bolser ("Igor Santos", 8976543, new DateYMD(11, 5, 1985), p1, 900);
|
||||
bls.setMonthlyAmount(1050);
|
||||
System.out.println("Student:"+ al.getName());
|
||||
System.out.println(al);
|
||||
System.out.println("Bolser:"+ bls.getName() + ", NMec: " + bls.getNMec() + ", Bolsa:" + bls.getMonthlyAmount()+ ", Orientador:" + bls.getSupervisor());
|
||||
System.out.println(bls);
|
||||
|
||||
sin.close();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package aula06;
|
||||
|
||||
import utils.DateYMD;
|
||||
|
||||
public class Professor extends Person {
|
||||
private String category;
|
||||
private String department;
|
||||
|
||||
public Professor(String name, int cc, DateYMD birthDate, String category, String department) {
|
||||
super(name, cc, birthDate);
|
||||
this.setCategory(category);
|
||||
this.setDepartment(department);
|
||||
}
|
||||
|
||||
public String getCategory() {
|
||||
return this.category;
|
||||
}
|
||||
public void setCategory(String category) {
|
||||
if (category == null || category.isEmpty()) {
|
||||
throw new IllegalArgumentException("Category cannot be null or empty");
|
||||
}
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
public String getDepartment() {
|
||||
return this.department;
|
||||
}
|
||||
public void setDepartment(String department) {
|
||||
if (department == null || department.isEmpty()) {
|
||||
throw new IllegalArgumentException("Department cannot be null or empty");
|
||||
}
|
||||
this.department = department;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%s; CC: %d; Date de nascimento: %s; Categoria: %s; Departamento: %s", this.getName(), this.getCc(), this.getBirthDate(), this.category, this.department);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package aula06;
|
||||
|
||||
import utils.DateYMD;
|
||||
import java.time.LocalDate;
|
||||
|
||||
public class Student extends Person {
|
||||
private DateYMD registrationDate;
|
||||
private int nMec;
|
||||
public static int currentNMec = 100;
|
||||
|
||||
public Student(String name, int cc, DateYMD birthDate, DateYMD registrationDate) {
|
||||
super(name, cc, birthDate);
|
||||
this.setRegistrationDate(registrationDate);
|
||||
this.setNMec(Student.currentNMec++);
|
||||
}
|
||||
|
||||
public Student(String name, int age, DateYMD birthDate) {
|
||||
this(name, age, birthDate, null);
|
||||
}
|
||||
|
||||
public int getNMec() {
|
||||
return this.nMec;
|
||||
}
|
||||
public void setNMec(int nMec) {
|
||||
this.nMec = nMec;
|
||||
}
|
||||
|
||||
public DateYMD getRegistrationDate() {
|
||||
return this.registrationDate;
|
||||
}
|
||||
public void setRegistrationDate(DateYMD registrationDate) {
|
||||
LocalDate now = LocalDate.now();
|
||||
this.registrationDate = registrationDate == null ? new DateYMD(now.getDayOfMonth(), now.getMonthValue(), now.getYear()) : registrationDate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%s; CC: %d; Date de nascimento: %s; Data de matrícula: %s; NMec: %d", this.getName(), this.getCc(), this.getBirthDate(), this.registrationDate, this.nMec);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue