Home > Back-end > The great god online solution method about assignments
The great god online solution method about assignments
Time:10-06
The specific requirements: Use method overloading: Enter the specific number of 1 type int, determine the number of parity Two parameters of type int, calculate the number of two and
Three type int number with the ternary operator, it is concluded that the maximum
Four type int, sorted
2 a float, and multiply
CodePudding user response:
Homework assignments are simple, yourself ha!
CodePudding user response:
Import the Java. Util. ArrayList; The import java.util.Com parator; Import the Java. Util. List;
/* * * @ description: * @ company: * * @ author: James gosling : * @ version 1.0.0 Date: * @ 2020-03-11 10:47:31 */ Public class CalculatorServiceImpl implements CalculatorService { @ Override Public Boolean calculate (int num) { Return num % 2==1; }
@ Override Public int calculate (int num1, int num2) { Return num1 + num2; }
@ Override Public int calculate (int num1, int num2, int num3) { Return (num1 & gt; Num2? Num1: num2) & gt; Num3? (num1 & gt; Num2? Num1: num2) : num3; }
@ Override Public List Calculate (int num1, int num2, int num3, int num4) { List NumList=new ArrayList<> (a); NumList. Add (num1); NumList. Add (num2); NumList. Add (num3); NumList. Add (num4); Paring numList. Sort (Comparator.com (e - & gt; E)); Return numList; }
Interface CalculatorService { /* * * determine the odd or even number * @ param num digital * @ return true=an odd number, false=even */ Boolean calculate (int num);
/* * Calculation of the two Numbers and * @ param num1 number 1 * @ param num2 number 2 * @ return the sum of two Numbers */ Int calculate (int num1, int num2);
/* * * by the ternary operator to calculate the maximum the value * @ param num1 number 1 * @ param num2 number 2 * @ param num3 number 3 * @ return Max */ Int calculate (int num1, int num2, int num3);
/* * * four numerical sorted * @ param num1 number 1 * @ param num2 number 2 * @ param num3 number 3 * @ param num4 number 4 * @ return sorted collection of */ List Calculate (int num1, int num2, int num3, int num4);