lab1
This commit is contained in:
parent
d3ac74eb64
commit
bbf73e06a4
BIN
DataLabs/lab1/Box.class
Normal file
BIN
DataLabs/lab1/Box.class
Normal file
Binary file not shown.
17
DataLabs/lab1/Box.java
Normal file
17
DataLabs/lab1/Box.java
Normal file
@ -0,0 +1,17 @@
|
||||
public class Box<T> {
|
||||
|
||||
private T t;
|
||||
|
||||
public void set(T t){
|
||||
this.t = t;
|
||||
}
|
||||
|
||||
public T get(){
|
||||
return t;
|
||||
}
|
||||
|
||||
public String printContents(){
|
||||
return t.toString();
|
||||
}
|
||||
|
||||
}
|
BIN
DataLabs/lab1/Tuple.class
Normal file
BIN
DataLabs/lab1/Tuple.class
Normal file
Binary file not shown.
42
DataLabs/lab1/Tuple.java
Normal file
42
DataLabs/lab1/Tuple.java
Normal file
@ -0,0 +1,42 @@
|
||||
public class Tuple<T1, T2, T3> {
|
||||
|
||||
private T1 item1;
|
||||
private T2 item2;
|
||||
private T3 item3;
|
||||
|
||||
public Tuple(T1 item1, T2 item2, T3 item3){
|
||||
this.item1 = item1;
|
||||
this.item2 = item2;
|
||||
this.item3 = item3;
|
||||
}
|
||||
|
||||
public T1 getItem1(){
|
||||
return item1;
|
||||
}
|
||||
|
||||
public T2 getItem2(){
|
||||
return item2;
|
||||
}
|
||||
|
||||
public T3 getItem3(){
|
||||
return item3;
|
||||
}
|
||||
|
||||
|
||||
public void setItem1(T1 item1) {
|
||||
this.item1 = item1;
|
||||
}
|
||||
|
||||
public void setItem2(T2 item2) {
|
||||
this.item2 = item2;
|
||||
}
|
||||
|
||||
public void setItem3(T3 item3) {
|
||||
this.item3 = item3;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "item1" + item1 + "item2" + item2 + "item3" + item3;
|
||||
}
|
||||
|
||||
}
|
11
DataLabs/lab1/TupleDemo.java
Normal file
11
DataLabs/lab1/TupleDemo.java
Normal file
@ -0,0 +1,11 @@
|
||||
public class TupleDemo {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
|
||||
Tuple <String, Integer, String> personTuple = new Tuple("John Doe", 21, "CS student");
|
||||
Tuple <String, Double, Boolean> itemTuple = new Tuple("Tablet", 13123, 1);
|
||||
|
||||
System.out.println(personTuple.getItem1() + personTuple.getItem2() + personTuple.getItem3());
|
||||
}
|
||||
}
|
9
DataLabs/lab1/demoSwap.java
Normal file
9
DataLabs/lab1/demoSwap.java
Normal file
@ -0,0 +1,9 @@
|
||||
public class demoSwap{
|
||||
|
||||
public static void main(String[] main) {
|
||||
Integer[] intArray = {1, 2, 3, 4, 5};
|
||||
swap.swap(intArray, 1, 3);
|
||||
System.out.print("New array: ");
|
||||
swap.printArray(intArray);
|
||||
}
|
||||
}
|
BIN
DataLabs/lab1/swap.class
Normal file
BIN
DataLabs/lab1/swap.class
Normal file
Binary file not shown.
16
DataLabs/lab1/swap.java
Normal file
16
DataLabs/lab1/swap.java
Normal file
@ -0,0 +1,16 @@
|
||||
public class swap {
|
||||
|
||||
public static <T> void swap(T[] array, int i1, int i2) {
|
||||
|
||||
T temp = array[i1];
|
||||
array[i1] = array[i2];
|
||||
array[i2] = temp;
|
||||
}
|
||||
|
||||
public static <T> void printArray(T[] array) {
|
||||
for (T element: array) {
|
||||
System.out.print(element + " ");
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user