Question

Can you help me to write a Java code for this:

Holiday Donation Drive ~ Write a program that will

The program must satisfy the following requirements:

The program should ask the user the following information

The site names for 6 locations (into an array)

The cash donation for 6 locations (into an array)

The food donations in pounds for 6 locations (into an array)

Is there another test they want to process, meaning do they want to run the program again?

Based on the input, the program will calculate the total cash donated for all 6 sites and the total pounds of food collected for all 6 sites. It will determine the highest cash donation, the highest pounds of food donated, and the name of each corresponding site location.

The program should then display a report of each individual site name with cash and food donations, the total cash and total food donated, the highest cash donation with the corresponding site location name, and the highest food donation with the corresponding site location name.

Calculations: The following calculations must happen in order to meet the system requirements:

In order to calculate the total cash donation and total food donation, use accumulation.

In order to determine the max cash donation and max food donation, use an if statement within a for loop.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Scanner;
    public class donations

{
        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();
                input.nextLine();
                System.out.print("\n\n\n");
            } while (anotherCourse.equalsIgnoreCase("yes"));

        }

        public static void getDonations() {
            Scanner input = new Scanner(System.in);        
            for (int i = 0; i < 6; i++) {
                System.out.println("Enter site " + (i + 1) + " name: ");
                siteName[i] = input.next();

                System.out.println("Enter cash donation(USD) for " + siteName[i]
                        + ": ");
                cashDonations[i] = input.nextDouble();          
                System.out.println("Enter food donation(lbs.) for " + siteName[i]
                        + ": ");
                lbsFood[i] = input.nextDouble();

            }

        }

        public static void processDonations()

{
            totalCash = 0;
            totalFood = 0;
            maxCash = cashDonations[0];
            maxFood = lbsFood[0];

            totalCash = cashDonations[1] + cashDonations[2] + cashDonations[3]
                    + cashDonations[4] + cashDonations[5] + cashDonations[6];
            totalFood = lbsFood[1] + lbsFood[1] + lbsFood[2] + lbsFood[3]
                    + lbsFood[4] + lbsFood[5] + lbsFood[6];

        }

        public static void displayDonations() {
            System.out.print("Total Cash Donations are " + totalCash);
            System.out.print("Total Food Donations are " + totalFood);
            System.out.print("Donation totals for " + siteName[1]);
            System.out.print("Total cash: " + cashDonations[1]);
            System.out.print("Food donations " +lbsFood[1]);
            System.out.println();
            System.out.print("Donation totals for " + siteName[2]);
            System.out.print("Total cash: " + cashDonations[2]);
            System.out.print("Food donations " +lbsFood[2]);
            System.out.println();
            System.out.print("Donation totals for " + siteName[3]);
            System.out.print("Total cash: " + cashDonations[3]);
            System.out.print("Food donations " +lbsFood[3]);
            System.out.println();
            System.out.print("Donation totals for " + siteName[4]);
            System.out.print("Total cash: " + cashDonations[4]);
            System.out.print("Food donations " +lbsFood[4]);
            System.out.println();
            System.out.print("Donation totals for " + siteName[5]);
            System.out.print("Total cash: " + cashDonations[5]);
            System.out.print("Food donations " +lbsFood[5]);
            System.out.println();
            System.out.print("Donation totals for " + siteName[6]);
            System.out.print("Total cash: " + cashDonations[6]);
            System.out.print("Food donations " +lbsFood[6]);
            System.out.println();

        }

    }

Add a comment
Know the answer?
Add Answer to:
Can you help me to write a Java code for this: The program must satisfy the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • please help with this. You must create a sales tracking program named SalesTracking.java. This program must...

    please help with this. You must create a sales tracking program named SalesTracking.java. This program must track monthly sales as well as compute average yearly sales, total sales for the year, and which month had the highest sales and which month had the lowest sales. The program should prompt the user for the sales for each month starting with January. After all the monthly sales have been entered, your program should have methods that do the following. getSales(): This method...

  • Hi this program must be completed using a Eclipes Compiler for Java only . This is...

    Hi this program must be completed using a Eclipes Compiler for Java only . This is and intro to java class , so only intro methods should be used for this assignment. Please include a copy of the input data and a sample of the out put data . Thanks a bunch Homework-Topic 9-Donations Write a complete program to do the following: The main program calls a method to read in (Erom an input file) a set of people's three-digit...

  • The name of the C++ file must be search.cpp Write a program that will read data...

    The name of the C++ file must be search.cpp Write a program that will read data from a file. The program will allow the user to specify the filename. Use a loop that will check if the file is opened correctly, otherwise display an error message and allow the user to re-enter a filename until successful. Read the values from the file and store into an integer array. The program should then prompt the user for an integer which will...

  • In Java. Write a GUI contact list application. The program should allow you to input names...

    In Java. Write a GUI contact list application. The program should allow you to input names and phone numbers. You should also be able to input a name and have it display the previously entered phone number. The GUI should look something like the following, although you are welcome to format it in any way that works. This should be a GUI application with a JFrame. The program should contain two arrays of Strings. One array will contain a list...

  • In Java Problem Description/Purpose:  Write a program that will compute and display the final score...

    In Java Problem Description/Purpose:  Write a program that will compute and display the final score of two teams in a baseball game. The number of innings in a baseball game is 9.    Your program should read the name of the teams. While the user does not enter the word done for the first team name, your program should read the second team name and then read the number of runs for each Inning for each team, calculate the...

  • In Java with comments. Write a program that computes the cost of flowers sold at a...

    In Java with comments. Write a program that computes the cost of flowers sold at a flower stand. Five kinds of flowers—petunia, pansy, rose, violet, and carnation— are stocked and cost, respectively, 50¢, 75¢, $1.50, 50¢, and 80¢ per flower. Create an array of strings that holds the names of these flowers. Create another array that holds the cost of each corresponding flower. Your program should read the name of a flower and the quantity desired by a customer. Locate...

  • Write you code in a class named HighScores, in file named HighScores.java. Write a program that...

    Write you code in a class named HighScores, in file named HighScores.java. Write a program that records high-score data for a fictitious game. The program will ask the user to enter five names, and five scores. It will store the data in memory, and print it back out sorted by score. The output from your program should look approximately like this: Enter the name for score #1: Suzy Enter the score for score #1: 600 Enter the name for score...

  • (2 bookmarks) In JAVA You have been asked to write a program that can manage candidates...

    (2 bookmarks) In JAVA You have been asked to write a program that can manage candidates for an upcoming election. This program needs to allow the user to enter candidates and then record votes as they come in and then calculate results and determine the winner. This program will have three classes: Candidate, Results and ElectionApp Candidate Class: This class records the information for each candidate that is running for office. Instance variables: first name last name office they are...

  • Write a C++ console application that allows your user to capture rainfall statistics. Your program should...

    Write a C++ console application that allows your user to capture rainfall statistics. Your program should contain an array of 12 doubles for the rainfall values as well as a parallel array containing the names of the months. Using each of the month names, prompt your user for the total rainfall for that month. The program should validate user input by guarding against rainfall values that are less than zero. After all 12 entries have been made, the program should...

  • [JAVA/chapter 7] Assignment: Write a program to process scores for a set of students. Arrays and...

    [JAVA/chapter 7] Assignment: Write a program to process scores for a set of students. Arrays and methods must be used for this program. Process: •Read the number of students in a class. Make sure that the user enters 1 or more students. •Create an array with the number of students entered by the user. •Then, read the name and the test score for each student. •Calculate the best or highest score. •Then, Calculate letter grades based on the following criteria:...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT