In: Computer Science
Submit a java file. Write a program where you input 4 numbers and the output generates the average of the 4 numbers. The output may not be negative and <= 100. If any value is negative or >100, it should be replaced by the value of 30. For all such values, you will replace them with a value of 10. The program should produce the following output:
Today's average amount is: $xx.xx.
import java.util.Scanner; public class AverageTips4 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("Enter 4 employee tips"); double d1,d2,d3,d4; d1 = scanner.nextDouble(); if(d1<0 || d1>100){ d1 = 30; } d2 = scanner.nextDouble(); if(d2<0 || d2>100){ d2 = 30; } d3 = scanner.nextDouble(); if(d3<0 || d3>100){ d3 = 30; } d4 = scanner.nextDouble(); if(d4<0 || d4>100){ d4 = 30; } double avg = (d1+d2+d3+d4)/4; System.out.printf("Today's average tip amount it: %.2f\n",avg); } }