/* * Intro to Programming CSE 1310 * University of Texas at Arlington */ package test2s19gas; import java.util.Scanner; public class Test2S19Gas { public static void main(String[] args) { Scanner input = new Scanner(System.in); double averageGas = 0; double day1 = 0, day2 = 0, day3 = 0, day4 = 0, day5 = 0; // gas prices System.out.println("This program asks for the last 5 days worth of "); System.out.println("gas prices and then averages them. "); System.out.println("\nPlease enter the prices as 5 decimal numbers on one line starting "); System.out.println("with today as Day 1 and going backwards to Day 5.\n"); for (int d = 1; d <= 5; d++) { switch (d) { case 1: { day1 = input.nextDouble(); System.out.print("\nValues entered: $"+day1+"\t"); break; } case 2: { day2 = input.nextDouble(); System.out.print("$"+day2+"\t"); break; } case 3: { day3 = input.nextDouble(); System.out.print("$"+day3+"\t"); break; } case 4: { day4 = input.nextDouble(); System.out.print("$"+day4+"\t"); break; } case 5: { day5 = input.nextDouble(); System.out.print("$"+day5+"\t"); break; } } } averageGas = (day1 + day2 + day3 + day4 + day5)/5; System.out.printf(" Avg: $%5.2f\n\n",averageGas); } }