-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a98e6bb
commit 074b268
Showing
11 changed files
with
198 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,4 +17,6 @@ public V get(K key) throws NotFoundException { | |
} | ||
throw new NotFoundException(); | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
||
} | ||
|
||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|