User Tools

Site Tools


2019_2020:s2:etudefilrouge:verslecode

This is an old revision of the document!


Vers le code

Reprenez le diagramme de classes et pour les classes qui sont utilisées dans le test, générer et complétez l'implémentation.

Voici un exemple de tests que vous pouvez faire :

public class TestValidation {
 
	public static void main(String[] args) {
		//(il y en a 4, ordonnés dans l'ordre chronologique des anniversaires : Hercule, Geek00, D.D., Yvette), celui de Hercule.
		Birthday aBirthday = new Birthday(LocalDate.of(2000, 02, 12),"a'");
		Birthday bBirthday = new Birthday(LocalDate.of(2000, 04, 12),"b'");
		Birthday herculeBirthday = new Birthday(LocalDate.of(2000, 02, 18),"Hercule'");
		Birthday geekBirthday = new Birthday(LocalDate.of(2000, 02, 19),"Geek00'");
		Birthday dDBirthday = new Birthday(LocalDate.of(2000, 02, 20),"D.D'");
		Birthday yvetteBirthday = new Birthday(LocalDate.of(2000, 03, 1),"Yvette'");
		List<Birthday> birthdayList = 
				new ArrayList<>(Arrays.asList(herculeBirthday, geekBirthday,dDBirthday,yvetteBirthday, aBirthday, bBirthday));
		birthdayList.removeIf( (b -> ( (b.numberOfDaysAfterToday()<0) || 
				               (b.numberOfDaysAfterToday()>15) ) ) )  ;
 
		System.out.println(birthdayList);
 
 
		////Pénélope sélectionne parmi les anniversaires qui lui sont proposés pour les 15 jours à venir 
		//Elle écrit : “Bon anniversaire ! “
		Message message = new Message(geekBirthday, "Bon anniversaire");
		System.out.println(message);
		System.out.println(geekBirthday);
 
 
	}

et pour comparer des dates si besoin :

import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
 
public class Birthday {
	private LocalDate aDate;
	private String aName;
 
	public Birthday(LocalDate pDate, String pName) {
		aDate = pDate;
		aName = pName;
	}
 
	public int numberOfDaysAfterToday() {
		LocalDate now = LocalDate.now();
		LocalDate thisYearDate = LocalDate.of(now.getYear(), aDate.getMonth(), aDate.getDayOfMonth());
		return (int) ChronoUnit.DAYS.between(now, thisYearDate);
	}
2019_2020/s2/etudefilrouge/verslecode.1581871912.txt.gz · Last modified: 2020/02/16 17:51 by blay