Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- import java.util.Comparator;
- import java.util.List;
- import java.util.Scanner;
- import java.util.stream.Collectors;
- class Triple<T extends Number>{
- private List<T> threeList;
- public Triple(T a, T b, T c) {
- threeList = Arrays.asList(a,b,c);
- }
- public double max(){
- return threeList.stream().max(Comparator.comparingDouble(Number::doubleValue)).orElseGet(null).doubleValue();
- }
- public double avarage(){
- return threeList.stream().mapToDouble(Number::doubleValue).average().orElseGet(null);
- }
- public void sort(){
- threeList = threeList.stream().sorted().collect(Collectors.toList());
- }
- @Override
- public String toString() {
- return String.format("%.2f %.2f %.2f",threeList.get(0).doubleValue(),threeList.get(1).doubleValue(),threeList.get(2).doubleValue());
- }
- }
- public class TripleTest {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int a = scanner.nextInt();
- int b = scanner.nextInt();
- int c = scanner.nextInt();
- Triple<Integer> tInt = new Triple<Integer>(a, b, c);
- System.out.printf("%.2f\n", tInt.max());
- System.out.printf("%.2f\n", tInt.avarage());
- tInt.sort();
- System.out.println(tInt);
- float fa = scanner.nextFloat();
- float fb = scanner.nextFloat();
- float fc = scanner.nextFloat();
- Triple<Float> tFloat = new Triple<Float>(fa, fb, fc);
- System.out.printf("%.2f\n", tFloat.max());
- System.out.printf("%.2f\n", tFloat.avarage());
- tFloat.sort();
- System.out.println(tFloat);
- double da = scanner.nextDouble();
- double db = scanner.nextDouble();
- double dc = scanner.nextDouble();
- Triple<Double> tDouble = new Triple<Double>(da, db, dc);
- System.out.printf("%.2f\n", tDouble.max());
- System.out.printf("%.2f\n", tDouble.avarage());
- tDouble.sort();
- System.out.println(tDouble);
- }
- }
- // vasiot kod ovde
- // class Triple
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement