From ab5c3ee991147425ae0d06c47a553e0c89dae860 Mon Sep 17 00:00:00 2001 From: sco Date: Mon, 23 May 2022 23:11:51 +0200 Subject: [PATCH] uouo --- intro/bank/ContoCorrente.java | 31 ++++++++++++++++++++++ intro/bank/ContoCorrenteCurrency.java | 19 ++++++++++++++ intro/bank/Currency.java | 5 ++++ intro/bank/TestContoCorrente.java | 18 +++++++++++++ intro/engine/Diesel.java | 32 ++++++++++++++++++++++ intro/engine/Gasoline.java | 32 ++++++++++++++++++++++ intro/engine/Motore.java | 5 ++++ intro/engine/MotoreTest.java | 13 +++++++++ intro/engine/NaturalGas.java | 32 ++++++++++++++++++++++ intro/persona/ImpiegatiDemo.java | 38 +++++++++++++++++++++++++++ intro/persona/Impiegato.java | 20 ++++++++++++++ intro/persona/Persona.java | 30 +++++++++++++++++++++ intro/persona/Stagista.java | 30 +++++++++++++++++++++ 13 files changed, 305 insertions(+) create mode 100644 intro/bank/ContoCorrente.java create mode 100644 intro/bank/ContoCorrenteCurrency.java create mode 100644 intro/bank/Currency.java create mode 100644 intro/bank/TestContoCorrente.java create mode 100644 intro/engine/Diesel.java create mode 100644 intro/engine/Gasoline.java create mode 100644 intro/engine/Motore.java create mode 100644 intro/engine/MotoreTest.java create mode 100644 intro/engine/NaturalGas.java create mode 100644 intro/persona/ImpiegatiDemo.java create mode 100644 intro/persona/Impiegato.java create mode 100644 intro/persona/Persona.java create mode 100644 intro/persona/Stagista.java diff --git a/intro/bank/ContoCorrente.java b/intro/bank/ContoCorrente.java new file mode 100644 index 0000000..07776dc --- /dev/null +++ b/intro/bank/ContoCorrente.java @@ -0,0 +1,31 @@ +package intro.bank; + +public class ContoCorrente { + private int balance; + private String owner; + + public ContoCorrente(String owner) { + this.balance = 0; + this.owner = owner; + } + public ContoCorrente(String owner, Integer balance) { + this.balance = balance; + this.owner = owner; + } + public int getBalance() { + return balance; + } + + public void setBalance(int balance) { + this.balance = balance; + } + + public String getOwner() { + return owner; + } + + @Override + public String toString() { + return "ContoCorrente[Owner: "+this.owner+" Balance: "+this.balance+"]"; + } +} diff --git a/intro/bank/ContoCorrenteCurrency.java b/intro/bank/ContoCorrenteCurrency.java new file mode 100644 index 0000000..da5fde0 --- /dev/null +++ b/intro/bank/ContoCorrenteCurrency.java @@ -0,0 +1,19 @@ +package intro.bank; + +public class ContoCorrenteCurrency extends ContoCorrente { + private Currency currency; + + public ContoCorrenteCurrency(String owner, Currency currency) { + super(owner); + this.currency = currency; + } + public ContoCorrenteCurrency(String owner, Integer balance, Currency currency) { + super(owner, balance); + this.currency = currency; + } + + @Override + public String toString() { + return super.toString().substring(0,super.toString().length()-1)+" "+this.currency+"]"; + } +} diff --git a/intro/bank/Currency.java b/intro/bank/Currency.java new file mode 100644 index 0000000..0fb33f2 --- /dev/null +++ b/intro/bank/Currency.java @@ -0,0 +1,5 @@ +package intro.bank; + +public enum Currency { + EUR, USD, GBP +} diff --git a/intro/bank/TestContoCorrente.java b/intro/bank/TestContoCorrente.java new file mode 100644 index 0000000..9aa808a --- /dev/null +++ b/intro/bank/TestContoCorrente.java @@ -0,0 +1,18 @@ +package intro.bank; + +public class TestContoCorrente { + public static void main(String[] args) { + ContoCorrenteCurrency c1 = new ContoCorrenteCurrency("c1", 1000, Currency.USD); + ContoCorrenteCurrency c2 = new ContoCorrenteCurrency("c2", Currency.EUR); + ContoCorrenteCurrency c3 = new ContoCorrenteCurrency("c3",2000, Currency.GBP); + System.out.println(c1); + System.out.println(c2); + System.out.println(c3); + + c2.setBalance(c2.getBalance()+200); + c3.setBalance(c3.getBalance()-1200); + + System.out.println(c2); + System.out.println(c3); + } +} diff --git a/intro/engine/Diesel.java b/intro/engine/Diesel.java new file mode 100644 index 0000000..a0b83de --- /dev/null +++ b/intro/engine/Diesel.java @@ -0,0 +1,32 @@ +package intro.engine; + +public class Diesel implements Motore { + private int engineVolume; + private int strokes; + + public Diesel(int engineVolume, int strokes) { + this.engineVolume = engineVolume; + this.strokes = strokes; + } + + public int getEngineVolume() { + return engineVolume; + } + + public void setEngineVolume(int engineVolume) { + this.engineVolume = engineVolume; + } + + public int getStrokes() { + return strokes; + } + + public void setStrokes(int strokes) { + this.strokes = strokes; + } + + @Override + public int getPower() { + return (int) ((this.engineVolume / this.strokes) * 0.2); + } +} diff --git a/intro/engine/Gasoline.java b/intro/engine/Gasoline.java new file mode 100644 index 0000000..aaf244f --- /dev/null +++ b/intro/engine/Gasoline.java @@ -0,0 +1,32 @@ +package intro.engine; + +public class Gasoline implements Motore { + private int engineVolume; + private int strokes; + + public Gasoline(int engineVolume, int strokes) { + this.engineVolume = engineVolume; + this.strokes = strokes; + } + + public int getEngineVolume() { + return engineVolume; + } + + public void setEngineVolume(int engineVolume) { + this.engineVolume = engineVolume; + } + + public int getStrokes() { + return strokes; + } + + public void setStrokes(int strokes) { + this.strokes = strokes; + } + + @Override + public int getPower() { + return (int) ((this.engineVolume / this.strokes) * 0.1); + } +} diff --git a/intro/engine/Motore.java b/intro/engine/Motore.java new file mode 100644 index 0000000..9d69f62 --- /dev/null +++ b/intro/engine/Motore.java @@ -0,0 +1,5 @@ +package intro.engine; + +public interface Motore { + public int getPower(); +} diff --git a/intro/engine/MotoreTest.java b/intro/engine/MotoreTest.java new file mode 100644 index 0000000..163e468 --- /dev/null +++ b/intro/engine/MotoreTest.java @@ -0,0 +1,13 @@ +package intro.engine; + +public class MotoreTest { + public static void main(String[] args) { + Gasoline m1 = new Gasoline(1400, 4); + Diesel m2 = new Diesel(1900, 5); + NaturalGas m3 = new NaturalGas(1400, 4); + + System.out.println(m1.getPower()); + System.out.println(m2.getPower()); + System.out.println(m3.getPower()); + } +} diff --git a/intro/engine/NaturalGas.java b/intro/engine/NaturalGas.java new file mode 100644 index 0000000..626b850 --- /dev/null +++ b/intro/engine/NaturalGas.java @@ -0,0 +1,32 @@ +package intro.engine; + +public class NaturalGas implements Motore { + private int engineVolume; + private int strokes; + + public NaturalGas(int engineVolume, int strokes) { + this.engineVolume = engineVolume; + this.strokes = strokes; + } + + public int getEngineVolume() { + return engineVolume; + } + + public void setEngineVolume(int engineVolume) { + this.engineVolume = engineVolume; + } + + public int getStrokes() { + return strokes; + } + + public void setStrokes(int strokes) { + this.strokes = strokes; + } + + @Override + public int getPower() { + return (int) (((this.engineVolume*0.8) / this.strokes) * 0.25); + } +} diff --git a/intro/persona/ImpiegatiDemo.java b/intro/persona/ImpiegatiDemo.java new file mode 100644 index 0000000..56e958f --- /dev/null +++ b/intro/persona/ImpiegatiDemo.java @@ -0,0 +1,38 @@ +package intro.persona; + +import java.util.*; + +public class ImpiegatiDemo { + public static void main(String[] args) { + Impiegato i1 = new Impiegato("Dio cane", new Date(1990, Calendar.MARCH,8), 1200); + Impiegato i2 = new Impiegato("wewe ciruzz", new Date(1990, Calendar.MAY,10),2000); + Stagista s1 = new Stagista("pepp o stagist", new Date(1999, Calendar.DECEMBER, 15), 1000,0,15); + Stagista s2 = new Stagista("toni il fantino", new Date(1996, Calendar.NOVEMBER, 8), 1000,10,15); + Stagista s4 = new Stagista("gennarino tricketrack", new Date(1996, Calendar.APRIL, 18), 1000,5,15); + Stagista s3 = new Stagista("peppiniell junior", new Date(2000, Calendar.JULY,1),1000,1,16); + Stagista s5 = new Stagista("pascalin o femminiell", new Date(2000, Calendar.JANUARY,28),1000,2,16); + + List list = new ArrayList<>(); + + list.add(i1); + list.add(i2); + list.add(s1); + list.add(s2); + list.add(s3); + list.add(s4); + list.add(s5); + + Impiegato g = cercaGiovane(list); + System.out.println(g.getName()); + } + + public static Impiegato cercaGiovane(List list) { + Impiegato tmp = list.get(0); + for (Impiegato i: list) { + if (tmp.getDateOfBirth().before(i.getDateOfBirth())) { + tmp = i; + } + } + return tmp; + } +} diff --git a/intro/persona/Impiegato.java b/intro/persona/Impiegato.java new file mode 100644 index 0000000..9cd6ab3 --- /dev/null +++ b/intro/persona/Impiegato.java @@ -0,0 +1,20 @@ +package intro.persona; + +import java.util.Date; + +public class Impiegato extends Persona{ + private int salary; + + public Impiegato(String name, Date dateOfBirth, int salary) { + super(name, dateOfBirth); + this.salary = salary; + } + + public int getSalary() { + return salary; + } + + public void setSalary(int salary) { + this.salary = salary; + } +} diff --git a/intro/persona/Persona.java b/intro/persona/Persona.java new file mode 100644 index 0000000..46e5313 --- /dev/null +++ b/intro/persona/Persona.java @@ -0,0 +1,30 @@ +package intro.persona; + +import java.util.Date; + +public class Persona { + private String name; + + public Persona(String name, Date dateOfBirth) { + this.name = name; + this.dateOfBirth = dateOfBirth; + } + + private Date dateOfBirth; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Date getDateOfBirth() { + return dateOfBirth; + } + + public void setDateOfBirth(Date dateOfBirth) { + this.dateOfBirth = dateOfBirth; + } +} diff --git a/intro/persona/Stagista.java b/intro/persona/Stagista.java new file mode 100644 index 0000000..205a3f4 --- /dev/null +++ b/intro/persona/Stagista.java @@ -0,0 +1,30 @@ +package intro.persona; + +import java.util.Date; + +public class Stagista extends Impiegato { + private int numeroPresenze; + private int numeroIdentificativoStage; + + public Stagista(String name, Date dateOfBirth, int salary, int numeroPresenze, int numeroIdentificativoStage) { + super(name, dateOfBirth, salary); + this.numeroPresenze = numeroPresenze; + this.numeroIdentificativoStage = numeroIdentificativoStage; + } + + public int getNumeroPresenze() { + return numeroPresenze; + } + + public void setNumeroPresenze(int numeroPresenze) { + this.numeroPresenze = numeroPresenze; + } + + public int getNumeroIdentificativoStage() { + return numeroIdentificativoStage; + } + + public void setNumeroIdentificativoStage(int numeroIdentificativoStage) { + this.numeroIdentificativoStage = numeroIdentificativoStage; + } +}