Question

In: Computer Science

A bug collector collects bugs every day for one week (7 days). Write a program that...

A bug collector collects bugs every day for one week (7 days). Write a program that asks the user for the total number of bugs they collected for each day and stores each number in a list. Use a loop to calculate the total number of bugs and display the result.

Solutions

Expert Solution

Hi, you hadn't mention the programming language, however I write the code in Java.

Here is your program:


Code in Text:

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // List for storing bug count for each day.
        List<Integer> bugCount = new ArrayList<>();
        // Scanner for reading input from user.
        Scanner scanner = new Scanner(System.in);

        System.out.println("Please enter count of bug collected: ");
        //Loop through a week i.e. 7 days and ask for bug count by user.
        for (int i=0; i<7; i++){
            System.out.print("Enter for Day " + (i+1) + ": ");
            // Read the user input and assign it to count.
            int count = scanner.nextInt();
            // Add this value to list.
            bugCount.add(count);
        }


        int count = 0;
        // Now loop through list and add the value of each item in list
        // to count.
        for (int i=0; i<bugCount.size();i++){
            count += bugCount.get(i);
        }
        // Finally print the value.
        System.out.println("Total bug collected during this week: " + count);

    }
}

Output:


Related Solutions

A bug collector collects bugs every day for five days. Write a program that keeps a...
A bug collector collects bugs every day for five days. Write a program that keeps a running total of the number of bugs collected during the five days. The loop should ask for the number of bugs collected for each day, and when the loop is finished, the program should display the total number of bugs collected. need this in Python
Need a java code A bug collector collects bugs every day for 7 days. Write a...
Need a java code A bug collector collects bugs every day for 7 days. Write a program that keeps a running total of the number of bugs collected during the 7 days. The program should prompt the user to enter the number of bugs collected for each day. Finally, when the program is finished, the program should display the total number of bugs collected.
A bug collector collects bugs every day for seven days. Design a program that keeps a...
A bug collector collects bugs every day for seven days. Design a program that keeps a running total of the number of bugs collected during the seven days. The loop should ask for the number of bugs collected for each day, and when the loop is finished, the program should display the total number of bugs collected. Finally, compute and display the average number of bugs collected. You should have 2 functions defined: A main – control program flow A...
Write a C# Program (using loops) to read temperature of the 7 days of the week...
Write a C# Program (using loops) to read temperature of the 7 days of the week (one day at a time) and calculate the average temperature of the week and print it.
You work in a factory that runs 24 hr a day, 7 days a week. The...
You work in a factory that runs 24 hr a day, 7 days a week. The boss insists that all 10 of the machines in the factory get a good servicing before he goes on vacation. Each of these machines has a part replaced that has an MTTF(µ) of 10,000hrs. The boss will then take the next 2 months (60 days) off for his “well deserved” vacation. The purchasing department will not purchase any expensive items while the boss is...
You eat five days per week at the same restaurant, and every day you order a...
You eat five days per week at the same restaurant, and every day you order a sandwich and a drink. There are 26 sandwiches including 6 vegetarian options, and 15 drinks including 4 caffeine-free drinks. On Tuesdays, you like to eat healthy, so you always choose a vegetarian sandwich and a caffeine free drink on Tuesdays. The other days you can eat any sandwich and drink any drink - but you never repeat a sandwich or a drink in the...
You eat five days per week at the same restaurant, and every day you order a...
You eat five days per week at the same restaurant, and every day you order a sandwich and a drink. There are 26 sandwiches including 6 vegetarian options, and 15 drinks including 4 caffeine-free drinks. On Tuesdays, you like to eat healthy, so you always choose a vegetarian sandwich and a caffeine free drink on Tuesdays. The other days you can eat any sandwich and drink any drink - but you never repeat a sandwich or a drink in the...
You eat five days per week at the same restaurant, and every day you order a...
You eat five days per week at the same restaurant, and every day you order a sandwich and a drink. There are 20 sandwiches including 6 vegetarian options, and 14 drinks including 4 caffeine-free drinks. On Tuesdays, you like to eat healthy, so you always choose a vegetarian sandwich and a caffeine free drink on Tuesdays. The other days you can eat any sandwich and drink any drink - but you never repeat a sandwich or a drink in the...
PYTHON PROGRAM: Write a program that determines the day of the week for any given calendar...
PYTHON PROGRAM: Write a program that determines the day of the week for any given calendar date after January 1, 1900, which was a Monday. This program will need to account for leap years, which occur in every year that is divisible by 4, except for years that are divisible by 100 but are not divisible by 400. For example, 1900 was not a leap year, but 2000 was a leap year.
Store is open 7 days/week. orders units every other week. maintains safety stock of 120 units....
Store is open 7 days/week. orders units every other week. maintains safety stock of 120 units. weekly sales is 800 units. lead time is 3 days. current inventory is 350 units, how many units should it order?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT