"depot M213"
This commit is contained in:
65
TD7/src/ip/IP.java
Executable file
65
TD7/src/ip/IP.java
Executable file
@ -0,0 +1,65 @@
|
||||
package ip;
|
||||
|
||||
public class IP {
|
||||
private String ip;
|
||||
|
||||
public IP(String s) {
|
||||
if (ipValide(s))
|
||||
ip = s;
|
||||
}
|
||||
|
||||
public String getIP() {
|
||||
return ip;
|
||||
}
|
||||
|
||||
public IP getPasserelle(IP masque) {
|
||||
String ipPass = "";
|
||||
|
||||
switch (masque.ip) {
|
||||
case "255.0.0.0" :
|
||||
ipPass = this.ip.substring(0, this.ip.indexOf(".")+1)+"255.255.255";
|
||||
break;
|
||||
case "255.255.0.0" :
|
||||
ipPass = this.ip.substring(0, this.ip.indexOf(".")+1);
|
||||
String temp = ip.substring(ip.indexOf(".")+1);
|
||||
ipPass += temp.substring(0, temp.indexOf(".")+1)+"255.255";
|
||||
break;
|
||||
case "255.255.255.0" :
|
||||
ipPass = this.ip.substring(0, ip.lastIndexOf(".")+1)+"255";
|
||||
break;
|
||||
}
|
||||
|
||||
return new IP(ipPass);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return ip;
|
||||
}
|
||||
|
||||
public static boolean ipValide(String ip) {
|
||||
if (ip.substring(0, 1).equals(".") || ip.substring(ip.length()-1).equals(".")) {
|
||||
System.out.println("Bad first or last character");
|
||||
return false;
|
||||
}
|
||||
|
||||
String[] ipSep = ip.split("\\.");
|
||||
if (ipSep.length != 4) {
|
||||
System.out.println("Bad ip length "+ipSep.length);
|
||||
return false;
|
||||
}
|
||||
for (String s : ipSep) {
|
||||
if (s.length() == 0) {
|
||||
System.out.println("Empty ip field");
|
||||
return false;
|
||||
}
|
||||
|
||||
int num = Integer.parseInt(s);
|
||||
if ((num<0) || (num>255)) {
|
||||
System.out.println("Bad ip field");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
47
TD7/src/ip/MainIp.java
Executable file
47
TD7/src/ip/MainIp.java
Executable file
@ -0,0 +1,47 @@
|
||||
package ip;
|
||||
|
||||
public class MainIp {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
String[] tabIp = new String[10];
|
||||
boolean[] tabRetatt = new boolean[tabIp.length];
|
||||
boolean[] tabRetour = new boolean[tabIp.length];
|
||||
|
||||
|
||||
tabIp[0] = "";
|
||||
tabIp[1] = "127.0.0.1";
|
||||
tabIp[2] = "127.231.1.1";
|
||||
tabIp[3] = "1.2.3.4";
|
||||
tabIp[4] = "12.2.3";
|
||||
tabIp[5] = "12.3.213.123.123";
|
||||
tabIp[6] = "1231.12.2.3";
|
||||
tabIp[7] = ".1.2.3";
|
||||
tabIp[8] = "1.2.3.";
|
||||
tabIp[9] = "1.2..3";
|
||||
|
||||
tabRetatt[0] = false;
|
||||
tabRetatt[1] = true;
|
||||
tabRetatt[2] = true;
|
||||
tabRetatt[3] = true;
|
||||
tabRetatt[4] = false;
|
||||
tabRetatt[5] = false;
|
||||
tabRetatt[6] = false;
|
||||
tabRetatt[7] = false;
|
||||
tabRetatt[8] = false;
|
||||
tabRetatt[9] = false;
|
||||
|
||||
for (int i = 0; i < tabRetatt.length; i++) {
|
||||
tabRetour[i] = IP.ipValide(tabIp[i]);
|
||||
}
|
||||
|
||||
System.out.println("attendu - retourne :");
|
||||
|
||||
for (int i = 0; i < tabRetatt.length; i++) {
|
||||
System.out.println(tabRetatt[i] + " - " + tabRetour[0]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
66
TD7/src/monney/Monnaie.java
Executable file
66
TD7/src/monney/Monnaie.java
Executable file
@ -0,0 +1,66 @@
|
||||
package monney;
|
||||
|
||||
public class Monnaie {
|
||||
|
||||
private int amount;
|
||||
private String currency;
|
||||
|
||||
/**
|
||||
* @return the currency
|
||||
*/
|
||||
public String getCurrency() {
|
||||
return currency;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param currency the currency to set
|
||||
*/
|
||||
public void setCurrency(String currency) {
|
||||
this.currency = currency;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the amount
|
||||
*/
|
||||
public int getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param amount the amount to set
|
||||
*/
|
||||
public void setAmount(int amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public Monnaie (int a, String s) {
|
||||
this.amount = a;
|
||||
this.currency = s;
|
||||
}
|
||||
|
||||
public void add(Monnaie m) {
|
||||
if(this.currency.equals(m.currency) == true)
|
||||
{
|
||||
this.amount += m.amount;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
Monnaie m = (Monnaie)o;
|
||||
if ( this == null || m == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.currency == m.currency && this.amount==m.amount) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
16
TD7/src/premierTest/MaClasse.java
Executable file
16
TD7/src/premierTest/MaClasse.java
Executable file
@ -0,0 +1,16 @@
|
||||
package premierTest;
|
||||
|
||||
public class MaClasse {
|
||||
|
||||
public static int calculer(int a, int b) {
|
||||
int res = a + b;
|
||||
if (a == 0) {
|
||||
res = b * 2;
|
||||
}
|
||||
if (b == 0) {
|
||||
res = a * a;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
28
TD7/src/premierTest/MaClasseTest.java
Executable file
28
TD7/src/premierTest/MaClasseTest.java
Executable file
@ -0,0 +1,28 @@
|
||||
package premierTest;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
|
||||
public class MaClasseTest {
|
||||
|
||||
@BeforeEach
|
||||
public void avantTest() {
|
||||
System.out.println("----------Debut Test-------------");
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void apresTest() {
|
||||
System.out.println("-----------Fin Test--------------");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCalculer() throws Exception {
|
||||
assertEquals(2, MaClasse.calculer(1,1));
|
||||
System.out.println(MaClasse.calculer(1,1));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user