Prove domande capitolo 6
This commit is contained in:
61
src/it/oracle/associate/java8/test/Calculations.java
Normal file
61
src/it/oracle/associate/java8/test/Calculations.java
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
package it.oracle.associate.java8.test;
|
||||||
|
|
||||||
|
public class Calculations {
|
||||||
|
|
||||||
|
private enum CardinalPoint {
|
||||||
|
NORTH, SOUTH, WEST, EST
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean findAverage(boolean sum) {
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Byte findAverage(byte sum) {
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Character findAverage(char sum) {
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Short findAverage(short sum) {
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer findAverage(int sum) {
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long findAverage(long sum) {
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Float findAverage(float sum) {
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double findAverage(double sum) {
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Calculations c = new Calculations();
|
||||||
|
System.out.println(c.findAverage((char) 36));
|
||||||
|
|
||||||
|
char ch = 0b0010_0100;
|
||||||
|
System.out.println(ch);
|
||||||
|
|
||||||
|
ch = 0x24;
|
||||||
|
System.out.println(ch);
|
||||||
|
|
||||||
|
byte b = 100;
|
||||||
|
switch (b) {
|
||||||
|
case 100:
|
||||||
|
break;
|
||||||
|
case 20:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
11
src/it/oracle/associate/java8/test/ChooseWisely.java
Normal file
11
src/it/oracle/associate/java8/test/ChooseWisely.java
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
package it.oracle.associate.java8.test;
|
||||||
|
|
||||||
|
public class ChooseWisely {
|
||||||
|
public ChooseWisely() { super(); }
|
||||||
|
public int choose(int choise) { return 5; }
|
||||||
|
public int choose(short choise) { return 2; }
|
||||||
|
public int choose(long choise) { return 11; }
|
||||||
|
public static void main(String[] path) {
|
||||||
|
System.out.println(new ChooseWisely().choose((byte) 2+1));
|
||||||
|
}
|
||||||
|
}
|
||||||
10
src/it/oracle/associate/java8/test/Drink.java
Normal file
10
src/it/oracle/associate/java8/test/Drink.java
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package it.oracle.associate.java8.test;
|
||||||
|
|
||||||
|
public class Drink {
|
||||||
|
|
||||||
|
public static void water() {}
|
||||||
|
|
||||||
|
public void get() {
|
||||||
|
Drink.water();
|
||||||
|
}
|
||||||
|
}
|
||||||
13
src/it/oracle/associate/java8/test/Football.java
Normal file
13
src/it/oracle/associate/java8/test/Football.java
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package it.oracle.associate.java8.test;
|
||||||
|
|
||||||
|
public class Football {
|
||||||
|
|
||||||
|
public static Long getScore(Long timeRemaining) {
|
||||||
|
return 2 * timeRemaining; // m1
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] refs) {
|
||||||
|
final int startTime = 4;
|
||||||
|
//System.out.println(getScore(startTime)); // m2
|
||||||
|
}
|
||||||
|
}
|
||||||
20
src/it/oracle/associate/java8/test/Phone.java
Normal file
20
src/it/oracle/associate/java8/test/Phone.java
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
package it.oracle.associate.java8.test;
|
||||||
|
|
||||||
|
public class Phone {
|
||||||
|
private int size;
|
||||||
|
|
||||||
|
public Phone(int size) {
|
||||||
|
this.size = size;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sendHome(Phone p, int newSize) {
|
||||||
|
p = new Phone(newSize);
|
||||||
|
p.size = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final void main(String... params) {
|
||||||
|
final Phone phone = new Phone(3);
|
||||||
|
sendHome(phone, 7);
|
||||||
|
System.out.println(phone.size);
|
||||||
|
}
|
||||||
|
}
|
||||||
13
src/it/oracle/associate/java8/test/Puppy.java
Normal file
13
src/it/oracle/associate/java8/test/Puppy.java
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package it.oracle.associate.java8.test;
|
||||||
|
|
||||||
|
public class Puppy {
|
||||||
|
public static int wag = 5;
|
||||||
|
|
||||||
|
public void Puppy(int wag) {
|
||||||
|
this.wag = wag;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] tail) {
|
||||||
|
//System.out.println(new Puppy(2).wag); // q3
|
||||||
|
}
|
||||||
|
}
|
||||||
17
src/it/oracle/associate/java8/test/RainForest.java
Normal file
17
src/it/oracle/associate/java8/test/RainForest.java
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package it.oracle.associate.java8.test;
|
||||||
|
|
||||||
|
public class RainForest extends Forest {
|
||||||
|
|
||||||
|
public RainForest(long treeCount) {
|
||||||
|
//this.treeCount = treeCount + 1;
|
||||||
|
super(treeCount + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Forest {
|
||||||
|
public long treeCount;
|
||||||
|
|
||||||
|
public Forest(long treeCount) {
|
||||||
|
this.treeCount = treeCount + 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
17
src/it/oracle/associate/java8/test/Tree.java
Normal file
17
src/it/oracle/associate/java8/test/Tree.java
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package it.oracle.associate.java8.test;
|
||||||
|
|
||||||
|
public class Tree {
|
||||||
|
public final static long numberOfTrees;
|
||||||
|
public final double height;
|
||||||
|
|
||||||
|
static {}
|
||||||
|
{
|
||||||
|
final int initHeight = 2;
|
||||||
|
height = initHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
static {
|
||||||
|
numberOfTrees = 100;
|
||||||
|
//height = 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
8
src/it/oracle/associate/java8/test/Week.java
Normal file
8
src/it/oracle/associate/java8/test/Week.java
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
package it.oracle.associate.java8.test;
|
||||||
|
|
||||||
|
public class Week {
|
||||||
|
//private static final String monday;
|
||||||
|
String tuesday;
|
||||||
|
//final static wednesday = 3;
|
||||||
|
final protected int thursday = 4;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user