TutorMe homepage
Subjects
PRICING
COURSES
SIGN IN
Start Free Trial
Brett M.
Teaching Assistant Fisher College of Business Ohio State University
Tutor Satisfaction Guarantee
Java Programming
TutorMe
Question:

The code below is an attempt print out the sum the odd numbers from 1 to some max. Point out any flaw(s) in the code, if any exist. (line numbers are on the right side for your reference) int i = 0; 1 int sum = 0; 2 while (max > i) { 3 int sum = sum + i; 4 i = i + 2; 5 } 6 System.out.println(sum); 7

Brett M.
Answer:

The code contains 2 errors. One is a syntax error and the other is a logical error. The first error is located inside the while loop on line 4. The int, signifying integer value, is not needed on this line for the variable sum is declared an integer on line 2. Variables cannot be declared and initialized after they are already declared. This will cause the code to create a new sum and try to use itself as the initial value, which is not possible and will error out. Correct code here is below: sum = sum + i; Second error is a logical one. The problem wants the summation of odd integers but running through the loop will output the sum of even variables because the initial 1 was set to 0. This means the first value is 0 and the statement on line 5 will make the new i = 2. Then it will be 4, 6 and so on. One must make sure they run through the loop to ensure the correct combination of initial counter variable and increment variable. i = i is the correct way to solve this problem Final correct code is listed below: int i = 1; 1 int sum = 0; 2 while (max > i) { 3 sum = sum + i; 4 i = i + 2; 5 } 6 System.out.println(sum); 7

Statistics
TutorMe
Question:

Jared works for Walmart and has been assigned to see if a recent sales investment has been successful in increasing the mean sales of jiff peanut butter per month. The past years mean sales of products was 578.8 million dollars with a population standard deviation of yearly sales to be 8 million dollars. The current years mean sales was 594 million dollars. With 95% confidence can you say that the initiative increased sales?

Brett M.
Answer:

To answer this problem, one must first identify what is being asked. The question wants to know if mean sales has increased or not. This wording points in the direction of a hypothesis test to see if the mean sales increased from the previous year based on this year’s mean sales. Next step is to identify the Hypothesis and type of test. The problem gives a population standard deviation listed as 8 million, last year’s mean sales as 578.8 million dollars, and this year’s mean sales as 594 million dollars. Since we know the population standard deviation, we are using the Normal distribution (Z Scores) to solve this. Note that if we were given no population standard deviation, we would need to utilize the T distribution with the appropriate amount of degrees of freedom. The question ask for an increase in sales meaning we are only concerned with if the sales increased over the previous amount and not if it decreased. This makes the test a one sided Z hypothesis test. The hypothesis are as shown below based on the values given in the problem. H_O: μ ≤ 578.8 H_A: μ > 578.8 The significance level of the test is determined by how confident we want to be. The problem states a 95% confidence, meaning the significance level is the remaining 5% we are not confident in. Sometimes the problem will state it as, we want a significance of only 5%, but it is good to know it both ways. From here you would calculate the z score for this year’s mean sales based on the population standard deviation using the equation below. z score=(x-μ)/(σ/√n) x = 594 (the mean we are testing) μ = 578.8 (the mean we are checking against as are null mean) σ = 8 (population standard deviation) n = 1 (sample size used to get the mean tested. In this problem it is 1 since it is 1 year) Calculation of z score z = (594-578.8)/(8/√1) z = 1.9 With the z score calculated, one would check for the one sided tail p value of a z score being higher than 1.9. This can be done with tail or cumulative probability tables, using a calculator with normal distribution calculation capabilities, or looking online at a z score calculator. The p value calculation is shown below P(z > 1.9) = 0.0287 Conclusion at 5% significance is yes. The mean sales of products at Walmart has increased from last year. This is because the hypothesis test showed a 2.87% chance of getting a sales at least as high as 594 million dollars given the null mean sales of 578.8 million dollars and our significance level was 5%. The p-value is lower than the level needed allowing us to reject the null hypothesis and accept the alternative that the mean sales have increased.

Algebra
TutorMe
Question:

If f(x) = 3x 3 − 7x + 5, then f(−1) =

Brett M.
Answer:

First step is to recognize that this equation is a function f in terms of x. This is denoted as f(x). The problem then wants you to solve for f(-1). All this means is that they want you to plug in -1 for all the x values in the equation. Equation with substitutions is shown below: 3(-1)^3 - 7(-1) Evaluate the answer based on order of operations. Remember the mnemonic for order of operations. Please Excuse My Dear Aunt Sally. Parenthesis, Exponents, Multiplication/Division (left to right) and Addition/Subtraction (left to right). Exponents first means (-1)^3 is first. Exponents are just multiplication to the number of times of the exponent. In full form this is -1 x -1 x -1. First 2 negatives cross of leaving 1 x -1 which equals -1. 3(-1) -7(-1) Next is multiplication. Take 3 x -1 and 7 x -1. This equals -3 and minus -7. Subtracting a negative is like adding a positive. Take the subtraction sign and turn it into an addition one and adding a negative to the 7. -3 + --7 The 2 negatives cross out, leaving only 7. This leaves -3 + 7 = 4 The final answer is denoted as this. f(-1) = 4

Send a message explaining your
needs and Brett will reply soon.
Contact Brett
Ready now? Request a lesson.
Start Session
FAQs
What is a lesson?
A lesson is virtual lesson space on our platform where you and a tutor can communicate. You'll have the option to communicate using video/audio as well as text chat. You can also upload documents, edit papers in real time and use our cutting-edge virtual whiteboard.
How do I begin a lesson?
If the tutor is currently online, you can click the "Start Session" button above. If they are offline, you can always send them a message to schedule a lesson.
Who are TutorMe tutors?
Many of our tutors are current college students or recent graduates of top-tier universities like MIT, Harvard and USC. TutorMe has thousands of top-quality tutors available to work with you.