using System;
using System.Diagnostics;
using System.Collections.Generic;
public class Tarjeta {
public /*required*/ int Num {
get => this._num;
init {
Debug.Assert( value > 0, "num. de tarjeta debe ser positivo" );
this._num = value;
this.calculaCVC();
}
}
public /*required*/ DateOnly Caduca {
get => this._caduca;
init {
Debug.Assert( value > DateOnly.FromDateTime( DateTime.Now ), "caducidad debe ser a futuro" );
this._caduca = value;
}
}
public int CVC { get; private set; }
public Tarjeta(int num, DateOnly caduca)
{
Debug.Assert( num > 0, "num. de tarjeta debe ser positivo" );
Debug.Assert( caduca > DateOnly.FromDateTime( DateTime.Now ), "caducidad debe ser a futuro" );
this.Num = num;
this.Caduca = caduca;
this.calculaCVC();
}
private void calculaCVC()
{
this.CVC = this.Num % 1000;
}
public override string ToString()
{
return $"{this.Num} ({this.Caduca}, {this.CVC})";
}
private int _num;
private DateOnly _caduca;
}
public class Test
{
public static void Main()
{
/*
var t1 = new Tarjeta {
Num = 548901687,
Caduca = new DateOnly( 2034, 11, 5 )
};
*/
var t2 = new Tarjeta( 548901687, new DateOnly( 2034, 11, 5 ) );
// Console.WriteLine( t1 );
Console.WriteLine( t2 );
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uRGlhZ25vc3RpY3M7CnVzaW5nIFN5c3RlbS5Db2xsZWN0aW9ucy5HZW5lcmljOwoKCnB1YmxpYyBjbGFzcyBUYXJqZXRhIHsKCXB1YmxpYyAvKnJlcXVpcmVkKi8gaW50IE51bSB7CgkJZ2V0ID0+IHRoaXMuX251bTsKCQlpbml0IHsKCQkJRGVidWcuQXNzZXJ0KCB2YWx1ZSA+IDAsICJudW0uIGRlIHRhcmpldGEgZGViZSBzZXIgcG9zaXRpdm8iICk7CgkJCXRoaXMuX251bSA9IHZhbHVlOwoJCQl0aGlzLmNhbGN1bGFDVkMoKTsKCQl9Cgl9CgkKCXB1YmxpYyAvKnJlcXVpcmVkKi8gRGF0ZU9ubHkgQ2FkdWNhIHsKCQlnZXQgPT4gdGhpcy5fY2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