Question: JAVA// Follow directions below:) Write a program named StateSales that has the following data for the following states double] sales ={23000,14000,120000,43000,67000,86000,29800,59000,120000}; String[] state ={ AZ,CA,VA,SC,
Write a program named StateSales that has the following data for the following states double] sales ={23000,14000,120000,43000,67000,86000,29800,59000,120000}; String[] state ={ "AZ","CA","VA","SC", "RI","TX","NM", "WI","NC" }; (NOTE: For a real application, it would be better to have a blueprint of Sales and have two fields, amount and state...but we need practice with primitive and String arrays so we will approach it this way). Write methods and method calls that print the following: a) the average sales b) a list of states below the average sales c) the maximum sales amount b) the state(s) that has the maximum sales. There may be more than one. Make certain to use methods. Make certain you do the input validation. If I change one of the values in the top array to a negative and run my version of the program, it prints You have some bad data so I am ending your program! Sample output The average sales were $62,422.22 States below average: AZ: $23,000.00 CA: $14,000.00 SC: $43,000.00 NM:$29,800.00 WI: $59,000.00 The maximum sales amount was $120,000.00 The maximum sales occurred in the following state(s) : VA NC NOTE: Make certain most of the work goes into the methods. Here is my main method (without the validation added) public static void main(String[] args) \{ NumberFormat nf= NumberFormat.getCurrencylnstance(); double] sales ={23000,14000,120000,43000,67000,86000,29800,59000,120000}; String[] states = { "AZ", "CA","VA", "SC","RI", "TX", "NM", "WI","NC" }; double avg = salesAvg(sales); System.out.printin("The average sales were " +nf.format(avg)); belowAvg(sales, states); double high = highSales(sales); System.out.printin("The maximum sales amount was " +nf.format(high)); highState(sales, states)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
