Skip to content

Commit

Permalink
Primo commit a.a.2019-20
Browse files Browse the repository at this point in the history
  • Loading branch information
alvisespano committed Feb 13, 2020
1 parent a98e6bb commit 074b268
Show file tree
Hide file tree
Showing 11 changed files with 198 additions and 1 deletion.
2 changes: 2 additions & 0 deletions 2019/TinyJDK/src/collections/MyListMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ public V get(K key) throws NotFoundException {
}
throw new NotFoundException();
}

}

1 change: 1 addition & 0 deletions 2019/TinyJDK/src/sort/GenericSort.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

public class GenericSort {


static <T> void sort(List<T> l, BiFunction<T, T, Integer> f) {
sort(l, new Comparator<T>() {
@Override
Expand Down
11 changes: 11 additions & 0 deletions 2020/2020.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
61 changes: 61 additions & 0 deletions 2020/src/it/unive/dais/po2/aa2019_20/myjdk/MyList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package it.unive.dais.po2.aa2019_20.myjdk;

import it.unive.dais.po2.aa2019_20.zoo.*;

public class MyList<T> {


private class Node {
public T data;
public Node next;
public Node(T data, Node next) {
this.data = data;
this.next = next;
}
}

private Node head;

public MyList() {
head = null;
}

public void add(T e) {
head = new Node(e, head);
}

public T get(int pos) throws OutOfBoundsException {
Node n = head;
for (; pos > 0; --pos)
if ((n = head.next) == null) throw new OutOfBoundsException();
return n.data;
}


public static class NotFoundException extends Exception {

}

public static class OutOfBoundsException extends Exception {

}

public void remove(int n) throws NotFoundException {
// TODO
}

static void main() {
MyList<Integer> l = new MyList<>();
l.add(7);
l.add(67);
l.add(23);
l.add(true);
Integer n = l.get(0);


MyList<? super Animal> l2 = new MyList<Animal>();
l2.add(new Animal());
l2.add(new Dog());
Animal a = l2.get(1);
}
}
20 changes: 20 additions & 0 deletions 2020/src/it/unive/dais/po2/aa2019_20/zoo/Animal.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package it.unive.dais.po2.aa2019_20.zoo;

public class Animal implements Creature {
protected int weight;
protected Animal partner;

public Animal(int weight, Animal p) {
this.weight = weight;
this.partner = p;
}

public void eat(Animal a) {
this.weight += a.weight;
}

// TODO: rendere abstract questo metodo
public Animal getPartner() {
return partner;
}
}
21 changes: 21 additions & 0 deletions 2020/src/it/unive/dais/po2/aa2019_20/zoo/Cat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package it.unive.dais.po2.aa2019_20.zoo;


public class Cat extends Animal {
private String color;

public Cat(int w, String c, Cat p) {
super(w, p);
this.color = c;
}

@Override
public void eat(Animal a) {
weight += a.weight / 3;
color = color + " fat";
}

public void meow() {
System.out.println("miao!");
}
}
5 changes: 5 additions & 0 deletions 2020/src/it/unive/dais/po2/aa2019_20/zoo/Creature.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package it.unive.dais.po2.aa2019_20.zoo;

public interface Creature {

}
27 changes: 27 additions & 0 deletions 2020/src/it/unive/dais/po2/aa2019_20/zoo/Dog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package it.unive.dais.po2.aa2019_20.zoo;

public class Dog extends Animal {
private String color; // TODO: fare una enum
private Dog newpartner; // TODO: metterlo nella superclass con generic A <: Animal

public Dog(int w, String c, Dog p) {
super(w, p);
this.newpartner = p;
this.color = c;
}


@Override
public void eat(Animal a) {
weight += a.weight / 2;
}

@Override
public Dog getPartner() {
return newpartner;
}

public void bark() {
System.out.println("bau!");
}
}
37 changes: 37 additions & 0 deletions 2020/src/it/unive/dais/po2/aa2019_20/zoo/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package it.unive.dais.po2.aa2019_20.zoo;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class Main {

public static void main(String[] args) {
Dog fido = new Dog(15, "bruno");
Dog baldo = new Dog(20, "bianco");
Animal jackie = new Dog(2, "nero");
Dog pluto = new Animal(50);
Animal selene = new Cat(4, "grigio");

// sumsumption NON valide
Dog fido2 = selene;
Cat selene2 = selene;

Cat tigre = new Cat(20);
Animal cane = new Dog(50, tigre);
Animal p = fido.getPartner();

selene.eat(fido);

Animal a = new Persian(6);
a.meow(); // NON COMPILA
a.eat(fido);

a.eat(a); // mangiare se stessi si può fare


}

}


12 changes: 12 additions & 0 deletions 2020/src/it/unive/dais/po2/aa2019_20/zoo/Persian.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package it.unive.dais.po2.aa2019_20.zoo;

public class Persian extends Cat {
public Persian(int w) {
super(w, "beige");
}

@Override
public void meow() {
System.out.println("maoo!");
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(ITALIAN)

Questo repository contiene sorgenti ed altro materiale per il corso di Programmazione ad Oggetti mod. 2, a.a. 2017-18, per il DAIS dell'Università Ca' Foscari di Venezia.
Questo repository contiene sorgenti ed altro materiale per il corso di Programmazione ad Oggetti mod. 2, dall'a.a. 2017-18 in poi, presso il DAIS dell'Università Ca' Foscari di Venezia.
Ogni sottocartella contiene progetti IntelliJ IDEA o altro inerente a diversi aspetti del corso.

0 comments on commit 074b268

Please sign in to comment.