Prove domande capitolo 6

This commit is contained in:
Fabio Scotto di Santolo
2018-02-01 16:53:37 +01:00
parent f36f1ec8c2
commit 624ff09ad8
9 changed files with 170 additions and 0 deletions

View 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;
}
}
}

View 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));
}
}

View File

@@ -0,0 +1,10 @@
package it.oracle.associate.java8.test;
public class Drink {
public static void water() {}
public void get() {
Drink.water();
}
}

View 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
}
}

View 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);
}
}

View 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
}
}

View 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;
}
}

View 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;
}
}

View 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;
}