Skip to content
Snippets Groups Projects
Commit f3957213 authored by Ethan Robert's avatar Ethan Robert
Browse files

tpQU-05::exo-pattern

parent 7b1bd1bf
No related branches found
No related tags found
No related merge requests found
Showing
with 148 additions and 0 deletions
package tpOO.tp10;public class IJob {
}
package tpOO.tp10;
public class IPriority {
}
package tpOO.tp10;public interface IScheduler {
}
package tpOO.tp10;public class JobDisplay {
}
package tpOO.tp10;public class JobDynamic {
}
package tpOO.tp10;public class JobIO {
}
package tpOO.tp10;public class JobLoop {
}
package tpOO.tp10;public class PriorityScheduler {
}
package tpOO.tp10;public class PrioritySchedulingQueue {
}
package tpOO.tp10;public class RandomObject {
}
package tpOO.tp10;public class SchedulingQueue {
}
package tpOO.tp10;
public class Task {
}
package tpOO.tp10;public class UsePriorityScheduler {
}
package tpQU.tp05;
public class Fraction extends Number {
private int num;
private int denom;
public Fraction (int num, int denom) {
this.num = num;
this.denom = denom;
}
public String toString() {
return "" + this.num + "/" + this.denom;
}
@Override
public double doubleValue() {
return (double) this.num / (double) this.denom;
}
@Override
public int intValue() {
return this.num / this.denom;
}
@Override
public float floatValue() {
return (float) this.doubleValue();
}
@Override
public long longValue() {
return (long) this.intValue();
}
}
package tpQU.tp05;
public class NumberFactory {
public static Number number(int n) {
return (Number) n;
}
public static Number number(float n) {
return (Number) n;
}
public static Number number(long n) {
return (Number) n;
}
public static Number number(double n) {
return (Number) n;
}
public static Number number(int n1, int n2) {
return new Fraction(n1, n2);
}
public static Number number(String n) throws NumberFormatException {
return NumberFactory.number(Double.parseDouble(n));
}
}
package tpQU.tp05;
import java.util.ArrayList;
import java.util.Collection;
public class Tabular {
private Number[] tab;
public Tabular(int size) {
this.tab = new Number[size];
}
public void set (int i, Number number) {
if (i < this.tab.length && i >= 0) {
this.tab[i] = number;
}
}
public Number max() {
Number max = this.tab[0];
for (Number elt : this.tab) {
if (elt != null) {
if (elt.floatValue() > max.floatValue()) {
max = elt;
}
}
}
return max;
}
public String toString () {
String string = "{";
for (int i = 0 ; i < this.tab.length ; i++) {
string += this.tab[i].toString();
if (i != this.tab.length - 1) {
string += ", ";
}
}
return string + "}";
}
public static void main (String[] args) {
Tabular tab1 = new Tabular(10);
for (int i = 0 ; i < 10 ; i++) {
tab1.set(i, i);
}
System.out.println("Max : " + tab1.max());
System.out.println(tab1);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment