I am trying to complete a program which takes in user input for 6 locations along with donation amounts for each. I then need to print out the site location with the largest cash donation. I figured out how to print out the actual dollar amount, but how do I code to see what the site with that amount is? Here is what I have:
import java.util.Scanner; public class Asg06 { static double [] cashDonations = new double[6]; static double [] lbsFood = new double[6]; static String [] siteName = new String[6]; static String bestSiteCash = " "; static String bestSiteFood = " "; static double totalCash = 0; static double totalFood = 0; static double maxFood = 0; static double maxCash = 0; public static void main(String[] args) { Scanner input = new Scanner(System.in); String anotherCourse = "yes"; do { getDonations(); processDonations(); displayDonations(); System.out.print("Enter yes if you want to run again: "); anotherCourse = input.next(); System.out.print("\n\n\n"); } while (anotherCourse.equalsIgnoreCase("yes")); } // end of main public static void getDonations() { Scanner input = new Scanner(System.in); //needed for input for (int i = 0; i < siteName.length; i++) { System.out.println("Enter site location name: "); siteName[i] = input.next(); input.nextLine(); System.out.println(""); do{ System.out.println("Enter cash donations for " + siteName[i] + " "); cashDonations[i] = input.nextDouble(); if(cashDonations[i] < 0) { System.out.println("ERROR---Please Enter Only Positive Numbers!!!"); }//end if System.out.println(""); }while(cashDonations[i] < 0);//end while do{ System.out.println("Enter lbs of food donations for " +siteName[i] + " "); lbsFood[i] = input.nextDouble(); if(lbsFood[i] < 0) { System.out.println("ERROR---Please Enter Only Positive Numbers!!!"); }//end if System.out.println(""); }while(lbsFood[i] < 0 );//end while }//end of for } //end of getDonations() public static void processDonations() { maxCash = cashDonations[0]; maxFood = lbsFood[0]; totalCash = 0; totalFood = 0; for(int i = 0; i < siteName.length; i++) { totalCash = totalCash + cashDonations[i]; totalFood = totalFood + lbsFood[i]; } for (int i = 0; i < cashDonations.length; i ++) { if (cashDonations[i] > maxCash) maxCash = cashDonations[i]; }//end of for loop for (int i = 0; i < lbsFood.length; i ++) { if (lbsFood[i] > maxFood) maxFood = lbsFood[i]; }//end of for loop }//end of processDonations() public static void displayDonations() { System.out.println("Holiday Donation Locations Report"); System.out.println("---------------------------------"); System.out.println(""); for(int i = 0; i < siteName.length; i++){ System.out.println("Site: " + siteName[i]); System.out.println("Individual Cash Donations " + cashDonations[i]); System.out.println("Individual Food Donations " + lbsFood[i]); System.out.print("\n\n"); }//end of for System.out.println(""); System.out.println("Holiday Donation Totals Report"); System.out.println("------------------------------"); System.out.println(""); System.out.printf("Total Cash Donations $%.2f\n", totalCash); System.out.printf("Total Food Donations %.2f lbs\n", totalFood); System.out.println("\n\n"); System.out.println("Holiday Donation Best Site Report"); System.out.println("---------------------------------"); System.out.println(""); System.out.println("Best Location For Cash Donation: " + bestSiteCash); System.out.printf("Max Cash Collected Was: $%.2f\n ", maxCash ); System.out.println(""); System.out.println("Best Location For Food Donation: " + bestSiteFood); System.out.printf("Max Food Collectd Was: %.2f lbs\n ", maxFood ); System.out.println(""); }//end of displayDonations() }// end of class
Thanks for your help!