This commit is contained in:
sco
2022-05-23 23:11:51 +02:00
parent 183736b4e6
commit ab5c3ee991
13 changed files with 305 additions and 0 deletions
+31
View File
@@ -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+"]";
}
}
+19
View File
@@ -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+"]";
}
}
+5
View File
@@ -0,0 +1,5 @@
package intro.bank;
public enum Currency {
EUR, USD, GBP
}
+18
View File
@@ -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);
}
}
+32
View File
@@ -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);
}
}
+32
View File
@@ -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);
}
}
+5
View File
@@ -0,0 +1,5 @@
package intro.engine;
public interface Motore {
public int getPower();
}
+13
View File
@@ -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());
}
}
+32
View File
@@ -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);
}
}
+38
View File
@@ -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<Impiegato> 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<Impiegato> list) {
Impiegato tmp = list.get(0);
for (Impiegato i: list) {
if (tmp.getDateOfBirth().before(i.getDateOfBirth())) {
tmp = i;
}
}
return tmp;
}
}
+20
View File
@@ -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;
}
}
+30
View File
@@ -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;
}
}
+30
View File
@@ -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;
}
}