Skip to content
Snippets Groups Projects
Commit 67371a73 authored by Samuel Turpin's avatar Samuel Turpin :computer:
Browse files

ajout du travail du ds2, modification tp09

parent 8d119127
Branches
No related tags found
No related merge requests found
package ds2;
public enum Capacity
{
CLIMBER, VENOM, WHIPTAIL;
@Override
public String toString()
{
String rep = "";
switch (this)
{
case CLIMBER:
rep = "I can attack from trees. . .";
break;
case VENOM:
rep = "I can poison preys. . .";
break;
case WHIPTAIL:
rep = "I can attack from trees. . .";
break;
default:
rep = "NULL CAPACITY";
break;
}
return rep;
}
}
\ No newline at end of file
package ds2;
import java.time.LocalDate;
import java.util.Objects;
import java.util.Random;
public class Dragon
{
private Capacity capacity;
private final String NAME;
private final LocalDate BIRTH;
protected int power;
private Dragon father;
private Dragon mother;
public static final Random rnd = new Random();
boolean isPowerfull = father.power > mother.power;
public Dragon(String n, Dragon fath, Dragon moth)
{
this.capacity = null;
this.NAME = n;
this.BIRTH = LocalDate.now();
this.power = rnd.nextInt(0, isPowerfull ? father.power : mother.power);
this.father = fath;
this.mother = moth;
}
public Dragon(String n)
{
this(n, null, null);
this.power = rnd.nextInt(0, 100);
}
public String getNAME() {
return NAME;
}
public LocalDate getBIRTH() {
return BIRTH;
}
public void setCapacity()
{
if(this.father.power == this.mother.power)
{
Capacity[] c = {this.father.capacity, this.mother.capacity};
this.capacity = c[rnd.nextInt(c.length - 1)];
}
if(this.father.power > this.mother.power)
{
this.capacity = this.father.capacity;
}
else if(this.father.power < this.mother.power)
{
this.capacity = this.mother.capacity;
}
else //Née sous X
{
Capacity[] c = Capacity.values();
this.capacity = c[rnd.nextInt(c.length - 1)];
}
}
@Override
public boolean equals(Object obj)
{
Dragon dr = (Dragon) obj;
return this.NAME.equals(dr.NAME);
}
@Override
public int hashCode()
{
return Objects.hash();
}
}
\ No newline at end of file
package ds2;
import java.util.ArrayList;
import java.util.List;
public class Komodo
{
private List<Dragon> population = new ArrayList<>();
public void add(Dragon d)
{
this.population.add(d);
}
public void remove(Dragon dr)
{
this.population.remove(dr);
}
public void remove(String name)
{
this.population.remove(search(name));
}
public Dragon search(String name)
{
for(Dragon drag : this.population)
{
if(drag.getNAME().equals(name))
{
System.out.println("Dragon found");
return drag;
}
}
System.out.println("Dragon not found");
return null;
}
}
\ No newline at end of file
package tp09;
import java.util.Scanner;
public class LogInManagement
{
public static final String LOGIN = "samuel.turpin.etu";
public static final String PWD = "poneymagique";
public LogInManagement(String log, String pwd)
public boolean getUserPwd()
{
return true;
}
public boolean getUserPwd()
public static void main(String[] args)
{
return true;
boolean connected = false;
Scanner scan = new Scanner(System.in);
while(!connected)
{
String log = scan.next();
String pass = scan.next();
try
{
if(log.equals(LOGIN) && pass.equals(PWD))
{
System.out.println("Mot de passe correct !");
}
} catch (Exception e) {
System.out.println("Erreur du Mot de passe !");
System.out.println("Veuillez réésayer...");
}
}
}
}
\ No newline at end of file
......@@ -2,6 +2,14 @@ package tp09;
public class WrongLoginException extends Exception
{
private String LOGIN;
public boolean init(String base, String log)
{
return false;
}
@Override
public synchronized Throwable initCause(Throwable cause)
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment