Ask Question
9 January, 00:37

Using the scenario below, answer the following questions:

You are preparing for the Boston Marathon. In order to prepare, you need to train for 10 weeks, running an increasing number of miles per week, starting at running at least 2 miles your first week up to 26 miles by week 10.

1.) Initialize the array with the appropriate number of values.

2.) What is the value in the array element when the index contains 2?

3.) What is your list length?

4.) Calculate the sum of the total miles you spent running over the 10 weeks. Calculate the average number of miles you ran.

5.) Write a search to determine whether 4 is on your list

+3
Answers (1)
  1. 9 January, 00:48
    0
    Here is code in java.

    import java. util.*;

    class Main

    {

    public static void main (String[] args) throws java. lang. Exception

    {

    try{

    boolean flag=false;

    int total_mile=0;

    double avg_mile;

    / / part 1, create and initialize array

    int inp[]={2,5,9,11,13,17,20,22,24,26};

    System. out. print ("miles ran per week: ");

    / / print the miles per week of train

    for (int x=0; x<10; x++)

    {

    System. out. print (inp[x]+" ");

    }

    System. out. println ();

    //part 2, print the value of index 2 in the list

    System. out. println ("value at index 2: "+inp[2]+" miles");

    //part 3, find length of array

    System. out. println ("list length: "+inp. length);

    / / part 4, calculate total mile and average

    for (int y=0; y<10; y++)

    {

    total_mile=total_mile+inp[y];

    }

    System. out. println ("total miles ran: "+total_mile+" miles");

    avg_mile=total_mile/10.0;

    System. out. println ("average no of miles ran = "+avg_mile+" miles");

    / / part 5, check 4 exist in the list or not

    for (int k=0; k<10; k++)

    {

    if (inp[k]==4)

    {

    flag=true;

    break;

    }

    }

    if (flag)

    System. out. println ("4 exist in the list.");

    else

    System. out. println ("4 doesn't exists in the list.");

    }catch (Exception ex) {

    return; }

    }

    }

    Explanation:

    Create and initialize array with list value equals to 2 and maximum value 26. Print the miles of each week. Then find the value of miles at index 2 in the list. Next find the length of the array and print it. Calculate total miles ran of 10 weeks. Then calculate the average miles by dividing the total with 10. In the array, check 4 exist or not.

    Output:

    miles ran per week: 2 5 9 11 13 17 20 22 24 26

    value at index 2: 9 miles

    list length: 10

    total miles ran: 149 miles

    average no of miles ran = 14.9 miles

    4 doesn't exists
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Using the scenario below, answer the following questions: You are preparing for the Boston Marathon. In order to prepare, you need to train ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers