WRITE A JAVA PROGRAM:
For this lab, you will create a 3 x 7 two dimensional array to store how many pounds of food three monkeys eats each day in a week. The 2D array is then passed to functions to find total, average and least amount of food consumption, etc. The program then need to display:
the average amount of food the three monkeys ate per day
the least amount of food eaten all week by any one monkey.
each monkey's consumption of food during the week
the average of food the 3 monkeys ate on Monday and Saturday.
The general structure of Lab9.java should be similar as follows:
import java.util.Scanner;
import java.text.DecimalFormat;
public class Lab9
{
public static void main(String[] args)
{
//declare necessary
constants and variables here
//......
//Create a 2D array to
hold the pounds of food consumed
//by each monkey on each
day of the week
//......
//Use nested for loop to
get data and fill in the 2D array
//......
//call the
findGroupTotal() method and compute
//the average amount of
food the 3 monkeys ate per day
//......
//call the findLeastAmtFood() method
and compute
//the least amount of food eaten all week by any one monkey
//......
//Find Monkey
#1 total consumption of food during the week
//......
//Find Monkey #2 total
consumption of food during the week
//......
//Find Monkey #3 total
consumption of food during the week
//......
//Find the average of
food the 3 monkeys eat on Monday
//......
//Find the average of
food the 3 monkeys eat on Saturday
//......
} //end main()
//This method takes a 2D array as input
parameter and returns
//the sum of all elements inside
public static double findGroupTotal(double[][]
a2DArray)
{
//......
}
//This method takes a 2D array as
input parameter and returns
//the smallest element inside
public static double findLeastAmtFood(double[][] a2DArray)
{
//......
}
} //end of class
1.2 Step 2: Declare necessary variables, constants and a 2D array inside the main()
For this section of the lab, you will need to declare two (2)
constants, both are integers, one for the number
of monkeys (3), another for the number of days (7). You also need
to declare a Scanner object that is used to read data from the
user, and also a DecimalFormat object which will be used to format
all double variables' output. Note: in this lab, all
output need to be formatted with 2 decimal
digits.
// For example, declare a constant that hold the number of
monkeys.
final int NUM_MONKEYS = 3;
// declare a constant that hold the number of days (7
days).
// ----
// declare a Scanner object which will be used to get user
input
// ----
// declare a DecimalFormat object which will be used to format
the output
// ----
// declare and create a 2D array called 'food' that holds the
pounds of food consumed
// by each monkey on each day of the week
// ----
As we learned in class, for example, to declare and create a two dimensional array, the syntax is as follows.
data_type[][] ArrayName = new data_type[NUM_OF_ROWS][NUM_OF_COLUMNS];
For Lab9, the data type is the pounds of food each monkey ate on a specific day; ArrayName as mentioned above, is food, the number of rows corresponds to number of the monkeys, and the number of columns corresponds to number of days in a week.
1.3 Step 3: Read in data from user and fill in the 2D array
Next, use the Scanner object created in the previous step to ask
the user to enter the pounds of food ate by each of the 3 monkeys
in each day of the week. i.e. we will need to fill in the
2D array 'food' we created in the previous step
row-by-row, and for each row, we need to fill in the data from left
to right. Remeber that we should always print a message indicating
what is to be input before requesting information from the user. To
do this task, we will need to write a nested
for loop, the
outer for loop iterates on each of the
monkeys, where the inner for loop
iterates on each of the day in one week.
for (/* loop logic - iterate on each of the 3 monkeys */)
{
System.out.print("\nEnter pounds of food eaten
by monkey #" + //---- + " on \n");
for (/*loop logic - iterate on each day of the
week */)
{
System.out.print( " on
day " + //---- + ": ");
//use Scanner object to
get user input and store it inside 2D array 'food'
food[monkey][day] =
scan.nextDouble();
}
}
//Codes in step #6 to step #8 continue......
1.4 Step 4: Design the findGroupTotal() method
Up to above step 3, codes should be put inside the main() method. In order to call findGroupTotal() method in main(), we need to design findGroupTotal() first. This method need to be put outside of the main(), but within the same class. The header of the method is as follows:
public static double findGroupTotal(double[][] a2DArray)
Basically this method takes a two dimensional array as input and returns the sum of all its elements inside. As we learned in class, in order to do this, we will need to write a nested for loop, the outer for loop iterates on each of the rows, where the inner for loop iterates on each of the columns of the 2D array. Very similar as we did in step #3. Note:
double total = 0.0;
for (/* loop logic - iterate on each of the row */)
{
for (/* loop logic - iterate on each of the
colunms */)
total +=
a2DArray[row][column];
}
return total;
1.5 Step 5: Design the findLeastAmtFood() method
Similar as we did in step #4, in order to call findLeastAmtFood() method in main(), we need to design findLeastAmtFood() method first. This method need to be put outside of the main(), but inside the Lab9.java class. The header of the method is as follows:
public static double findLeastAmtFood(double[][] a2DArray)
Basically this method takes a two dimensional array as input and returns the smallest elements inside. As we learned in class, in order to do this, we will need to write a nested for loop, the outer for loop iterates on each of the rows, where the inner for loop iterates on each of the columns of the 2D array. Very similar as we did in step #4, except that we need to declare and intialize a local variable leastAmt as follows:
double leastAmt = a2DArray[0][0];
for (/* loop logic - iterates on each of the rows */)
{
for (/* loop logic - iterate on each of the
columns */)
{
if
(a2DArray[row][column] < leastAmt)
//replace leastAmt with the two-D array element at (row,
column)
}
}
return leastAmt;
1.6 Step 6: Call findGroupTotal()and findLeastAmtFood() methods in main()
Continue on what we have left in step 4, now we need to call findGroupTotal() and findLeastAmtFood() methods on the two-dimensional array food. Since both method returns a double value, you might need to declare any necessary variables to hold the returned value, such as the following:
double groupTotal;
When we call a method with 2D array as input parameter, we just need to plug in the actual parameter's name, such as the following:
groupTotal = findGroupTotal(food); //find total on 2D array food
Next, you need to do simple computation to find the average amount of food ate per day by the entire family of monkeys, which equals to the groupTotal divided by number of days, then output the computation result according to the test cases.
Similarly, call findLeastAmtFood()method on two dimensional array food, declare any necessary local variables here and output the result as test cases show.
1.7 Step 7: Find each of the monkey's consumption of food during the week
Still inside the main() method, for 2D array food, we need to find the sum of each of the rows, this corresponds to each of the monkeys' consumption of food in the whole week. Use monkey #1 as an example, first we declare a local variable totalOne which will be used to hold monkey #1's total consumption,
double totalOne = 0.0;
Next, we write a for loop which iterates on each of the
days in a week (column of 2D array food) and sum the elements
one-by-one as follows:
for (int day = 0; day < NUM_DAYS; day++)
totalOne += food[0][day];
we then output the result on screen:
System.out.print("\nMonkey #1 eat total of " + fmt.format(totalOne) + " pounds of food in this week.\n");
//Follow above monkey #1's example, compute and output monkey #2 & #3's total consumption of food in one week
//----
1.8 Step 8: Find the average of food the 3 monkeys eat on Monday and Saturday
Continue on above step 7, we now need to find the total amount of food the 3 monkeys ate on Monday or Saturday, this corresponds to sum of all elements in column 0 and 5 of 2D array food respectively. Always keep in mind that index starts from 0!
Let's compute the average of food the three monkeys ate on Monday first, we declare a local variable totalMonday which will be used to hold the total consumption, on Monday
double totalMonday = 0.0;
Next, we need to write a for loop which iterates on each of the monkeys on Monday (row of 2D array food), note for Monday, the column index is 0,
for (int monkey = 0; monkey < 3; monkey ++)
totalMonday +=
food[monkey][0];
Last, we compute the average and output accordingly,
double averageMon = totalMonday / 3.0;
//Follow above Monday example, compute and output the average of food the three monkeys consumed on Saturday.
//----
In: Computer Science
Suppose two independent random samples of sizes n1 = 9 and n2 = 7 that have been taken from two normally distributed populations having variances σ12 and σ22 give sample variances of s12 = 94 and s22 = 13. (a) Test H0: σ12 = σ22 versus Ha: σ12 ≠ σ22 with σ = .05. What do you conclude? (Round your answers to 2 decimal places.) F = 7.231 F.025 = H0:σ12 = σ22 (b) Test H0: σ12 < σ22versus Ha: σ12 > σ22 with σ = .05. What do you conclude? (Round your answers to 2 decimal places.) F = 4.147 F.05 = H0: σ12 < σ22
In: Math
You have decided to open a restaurant in Huntington. The following table gives the payoffs based on two states of nature, favorable and unfavorable demand. You believe that the probability of a favorable market is 0.8. You can open any one of three different sizes of restaurant.
|
Open |
Favorable |
Unfavorable |
|
Large Restaurant |
50,000 |
-40,000 |
|
Medium Restaurant |
40,000 |
-10,000 |
|
Small Restaurant |
20,000 |
10,000 |
You have decided to do some marketing research (using the skills that you learned). If the marketing research is positive (probability = .7), then the probability of favorable demand goes to .95. If the marketing research is negative (shows weak demand) (probability of .3), then the probability of favorable demand goes to .40.
In: Statistics and Probability
Furniture Depot orders a certain brand of mattress from its supplier and sells the mattresses at its retail location. The store currently orders 40 mattresses whenever the inventory level drops to 20. The cost to hold 1 mattress in inventory for one day is $0.75. The cost cost to place an order with the supplier is $80, and inventory is 30 mattresses. The daily demand probabilities are shown in the following table:
Daily Demand Probability
2 0.08
3 0.14
4 0.20
5 0.26
6 0.22
7 0.10
Lead time is decrete uniformly distributed between two and five days (both inclusive). Simulate this inventory policy for a quarter (90 days) and calculate the total quarterly cost. Also calculate the percentage of stockouts for the quarter. Replicate these calculations N times each to calculate the average values for these measures.
In: Operations Management
Executives at Microsoft are interested to get into the drone delivery business. Since it would take them too much time to set up their own operation, they decide to acquire “Flyit” corporation. “Flyit” has been operating a drone delivery service for 4 years now, and they are the most successful operators in the market. Microsoft executives offer “Flyit” two purchase options. The first option is one $40 million lump sum payment. The second option is paying five annual payments of $10 million over the next five years.
i) If the annual interest rate is 7%, find the present value of both options? [Note: you are supposed to show every step of your calculation and interpret the result]
ii)Evaluate the net present values of both option and identify which option is more cost effective for Microsoft?
In: Finance
As part of a course project, a statistics student surveyed random samples of 50 student athletes and 50 student non-athletes at his university, with the goal of comparing the heights of the two groups. His summary statistics are displayed in the provided table.
|
n |
s |
||
|
Athletes |
50 |
68.96 |
4.25 |
|
Non-athletes |
50 |
67.28 |
3.46 |
a). Which data analysis method is more appropriate in this situation: paired data difference in means or difference in means with two separate groups? Explain briefly.
b). Construct a 99% confidence interval for the difference in
mean heights between student athletes and non-athletes at this
university. Use two decimal places in your margin of
error.
c). Test, at the 5% level, if student athletes at this university are significantly taller, on average, than student non-athletes. Include all of the details.
In: Statistics and Probability
Two firms, C and D, both produce coat hangers. The price of coat hangers is $1.20 each. Firm C has total fixed costs of $750,000 and variable costs of 30¢ per coat hanger. Firm D has total fixed costs of $400,000 and variable costs of 50¢ per coat hanger. The corporate tax rate is 40%. If the economy is strong, each firm will sell 2,000,000 coat hangers. If the economy enters a recession, each firm will sell 1,400,000 coat hangers.
If the economy is strong, the total revenue of firm C will be
$1,680,000.
$2,400,000.
$2,000,000.
$1,400,000.
In: Finance
| Age range (yr) | 20-29 | 30-39 | 40-49 | 50-59 | 60-69 | 70-79 | 80+ |
| Midpoint x | 24.5 | 34.5 | 44.5 | 54.5 | 64.5 | 74.5 | 84.5 |
| Percent of nurses | 5.4% | 9.8% | 19.8% | 29.2% | 25.5% | 8.7% | 1.6% |
What was the age distribution of nurses in Great Britain at the time of Florence Nightingale? Suppose we have the following information. Note: In 1851 there were 25,466 nurses in Great Britain.
(e) Compute the standard deviation σ for ages of nurses shown in the distribution. (Round your answer to two decimal places.)
In: Statistics and Probability
4. YQR has a market value of $125 million and 5 million shares outstanding. HKG has a market value of $40 million and 2 million shares outstanding. YQR thinks of taking over HKG with a premium of $10 million. The combined firm will be worth $185 million. If YQR offers 1.2 million shares of its stock in exchange for the 2 million shares of HKG, what will the stock price of YQR be after the acquisition? What exchange ratio between the two stocks would make the value of a stock offer equivalent to a cash offer of $50 million?
In: Finance
What was the age distribution of nurses in Great Britain at the time of Florence Nightingale? Suppose we have the following information. Note: In 1851 there were 25,466 nurses in Great Britain.
Compute the standard deviation σ for ages of nurses shown in the distribution. (Round your answer to two decimal places.)
| Age range (yr) | 20-29 | 30-39 | 40-49 | 50-59 | 60-69 | 70-79 | 80+ |
| Midpoint x | 24.5 | 34.5 | 44.5 | 54.5 | 64.5 | 74.5 | 84.5 |
| Percent of nurses | 5.9% | 9.9% | 19.1% | 29.3% | 25.2% | 8.9% | 1.7% |
In: Statistics and Probability