ACME bakery has decided to take on a project to update their retail storefront based on a budget they have. They need your help to evaluate various bids against the project budget. These bids have been provided by exactly ten different contractors. In order to perform the evaluation, the bakery owner would like to avoid the lowest bid and the highest bid gathered. Create a modular solution to enable the bakery owner to first enter their budget for the storefront remodel project. Then, the solution should allow bakery owner to enter each bid, one at a time, until all bids have been entered. If the owner makes a mistake and input an invalid bid, she should be provided with an error message and a chance to enter the bid again. Once all bids have been entered, the average bid should be determined, not inclusive of the lowest or highest bid. Print a well-formatted report that lists all bids entered (inclusive of the lowest and highest bid), all bids factored into the average (not inclusive of the lowest and highest bid), the average bid (not inclusive of the lowest and highest bid), and a list of all bids (not inclusive of the lowest and highest bid) that are equal to or less than the project budget to show the bakery owner which bids she can afford based on her budget.

Respuesta :

Answer:

import java.util.Arrays;

import java.util.Scanner;

public class ProjectBakery {

  public static long projectBudget;

  public static void bidsFactoredIntoAvg(Integer[] bids) {

      int sum = 0;

      for (int i = 0; i < bids.length; i++) {

          sum += bids[i];

      }

      int avg = sum / bids.length;

      for (int i = 1; i < bids.length - 1; i++) {

          if (avg % bids[i] == 0) {

              System.out.println(bids[i]);

          }

      }

  }

  public static int avg(Integer[] bids) {

      int sum = 0;

      for (int i = 1; i < bids.length - 1; i++) {

          sum += bids[i];

      }

      return sum / (bids.length - 2);

  }

  public static void printAllBids(Integer[] bids) {

      for (int i = 0; i < bids.length - 1; i++) {

          System.out.print(bids[i] + ",");

      }

      System.out.println(bids[bids.length - 1]);

  }

  public static void printAffordableBids(Integer[] bids) {

      for (int i = 1; i < bids.length - 2; i++) {

          if (bids[i] <= projectBudget) {

              System.out.print(bids[i] + ",");

          }

      }

      System.out.print(bids[bids.length - 2]);

  }

  public static void main(String[] args) {

      Scanner in = new Scanner(System.in);

      projectBudget = in.nextLong();

      Integer[] arr = new Integer[10];

      for (int i = 0; i < 10; i++) {

          do {

              while (!in.hasNextInt()) {

                  System.out.println(in.next()

                          + " is not a valid bid(Number).");

              }

              arr[i] = in.nextInt();

          } while (arr[i] < 0);

      }

 

      in.close();

   

      Arrays.sort(arr);

      System.out.println("All bids entered");

      printAllBids(arr);

     

      System.out.println("All bids factored into the average");

      bidsFactoredIntoAvg(arr);

      System.out.println("The average bids");

      System.out.println(avg(arr));

      System.out.println("Affordable Bids");

      printAffordableBids(arr);

  }

}

ACCESS MORE